Skip to content

Commit

Permalink
feat: ✨ Added support to allow using paintbrush on things other than …
Browse files Browse the repository at this point in the history
…just storage blocks
  • Loading branch information
P3pp3rF1y committed Jan 11, 2025
1 parent 11b92ac commit d75400e
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 103 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.daemon=false

mod_id=sophisticatedstorage
mod_group_id=sophisticatedstorage
mod_version=1.1.2
mod_version=1.1.3
sonar_project_key=sophisticatedstorage:SophisticatedStorage
github_package_url=https://maven.pkg.github.com/P3pp3rF1y/SophisticatedStorage

Expand All @@ -30,6 +30,6 @@ jade_cf_file_id=4614153
chipped_cf_file_id=5077656
resourcefullib_cf_file_id=5070629
athena_cf_file_id=4764357
sc_version=[1.20.1-1.1.0,1.20.4)
sc_version=[1.20.1-1.1.2,1.20.4)
sb_version=[1.20.1-3.22.0,1.20.4)
parchment_version=2023.09.03-1.20.1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Map;
import java.util.Optional;

public class BarrelBlockEntity extends WoodStorageBlockEntity {
public class BarrelBlockEntity extends WoodStorageBlockEntity implements IMaterialHolder {
private static final String MATERIALS_TAG = "materials";
public static final String STORAGE_TYPE = "barrel";
private Map<BarrelMaterial, ResourceLocation> materials = new EnumMap<>(BarrelMaterial.class);
Expand Down Expand Up @@ -117,12 +117,19 @@ public void loadSynchronizedData(CompoundTag tag) {
materials = NBTHelper.getMap(tag, MATERIALS_TAG, BarrelMaterial::fromName, (bm, t) -> Optional.of(new ResourceLocation(t.getAsString()))).orElse(Map.of());
}

@Override
public void setMaterials(Map<BarrelMaterial, ResourceLocation> materials) {
this.materials = materials;
setChanged();
}

@Override
public Map<BarrelMaterial, ResourceLocation> getMaterials() {
return materials;
}

@Override
public boolean canHoldMaterials() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.p3pp3rf1y.sophisticatedstorage.block;

import net.minecraft.resources.ResourceLocation;

import java.util.Map;

public interface IMaterialHolder {
void setMaterials(Map<BarrelMaterial, ResourceLocation> materials);

Map<BarrelMaterial, ResourceLocation> getMaterials();

boolean canHoldMaterials();
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable L
}
if (stack.getItem() instanceof ShulkerBoxItem shulkerBoxItem) {
StorageWrapper storageWrapper = be.getStorageWrapper();
storageWrapper.setMainColor(shulkerBoxItem.getMainColor(stack).orElse(-1));
storageWrapper.setAccentColor(shulkerBoxItem.getAccentColor(stack).orElse(-1));
storageWrapper.setColors(shulkerBoxItem.getMainColor(stack).orElse(-1), shulkerBoxItem.getAccentColor(stack).orElse(-1));
InventoryHandler inventoryHandler = storageWrapper.getInventoryHandler();
UpgradeHandler upgradeHandler = storageWrapper.getUpgradeHandler();
storageWrapper.changeSize(shulkerBoxItem.getNumberOfInventorySlotsOrDefault(stack) - inventoryHandler.getSlots(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,6 @@ public boolean hasMainColor() {
return mainColor > -1;
}

public void setMainColor(int mainColor) {
this.mainColor = mainColor;
save();
}

@Override
public int getAccentColor() {
return accentColor;
Expand All @@ -333,11 +328,6 @@ public boolean hasAccentColor() {
return accentColor > -1;
}

public void setAccentColor(int accentColor) {
this.accentColor = accentColor;
save();
}

@Override
public Optional<Integer> getOpenTabId() {
return openTabId >= 0 ? Optional.of(openTabId) : Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ private void setNewSize(ItemStack stack, WoodStorageBlockEntity be) {

protected void setRenderBlockRenderProperties(ItemStack stack, WoodStorageBlockEntity be) {
WoodStorageBlockItem.getWoodType(stack).ifPresent(be::setWoodType);
StorageBlockItem.getMainColorFromStack(stack).ifPresent(be.getStorageWrapper()::setMainColor);
StorageBlockItem.getAccentColorFromStack(stack).ifPresent(be.getStorageWrapper()::setAccentColor);
be.getStorageWrapper().setColors(StorageBlockItem.getMainColorFromStack(stack).orElse(-1), StorageBlockItem.getAccentColorFromStack(stack).orElse(-1));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public void renderByItem(ItemStack stack, ItemDisplayContext transformType, Pose

private void renderBlockEntity(ItemStack stack, PoseStack poseStack, MultiBufferSource buffer, int packedLight, int packedOverlay, ChestBlockEntity chestBlockEntity) {
if (stack.getItem() instanceof ITintableBlockItem tintableBlockItem) {
chestBlockEntity.getStorageWrapper().setMainColor(tintableBlockItem.getMainColor(stack).orElse(-1));
chestBlockEntity.getStorageWrapper().setAccentColor(tintableBlockItem.getAccentColor(stack).orElse(-1));
chestBlockEntity.getStorageWrapper().setColors(tintableBlockItem.getMainColor(stack).orElse(-1), tintableBlockItem.getAccentColor(stack).orElse(-1));
}
Optional<WoodType> woodType = WoodStorageBlockItem.getWoodType(stack);
if (woodType.isPresent() || !(chestBlockEntity.getStorageWrapper().hasAccentColor() && chestBlockEntity.getStorageWrapper().hasMainColor())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public void renderByItem(ItemStack stack, ItemDisplayContext transformType, Pose

ShulkerBoxBlockEntity shulkerBoxBlockEntity = shulkerBoxBlockEntities.getUnchecked(blockItem);
if (stack.getItem() instanceof ITintableBlockItem tintableBlockItem) {
shulkerBoxBlockEntity.getStorageWrapper().setMainColor(tintableBlockItem.getMainColor(stack).orElse(-1));
shulkerBoxBlockEntity.getStorageWrapper().setAccentColor(tintableBlockItem.getAccentColor(stack).orElse(-1));
shulkerBoxBlockEntity.getStorageWrapper().setColors(tintableBlockItem.getMainColor(stack).orElse(-1), tintableBlockItem.getAccentColor(stack).orElse(-1));
}
if (StorageBlockItem.showsTier(stack) != shulkerBoxBlockEntity.shouldShowTier()) {
shulkerBoxBlockEntity.toggleTierVisiblity();
Expand Down
Loading

0 comments on commit d75400e

Please sign in to comment.