From 1eccc2e435e8c64da1877b87ec88b47c993fa1d3 Mon Sep 17 00:00:00 2001 From: P3pp3rF1y Date: Fri, 10 Jan 2025 23:22:35 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Added=20support=20to=20allo?= =?UTF-8?q?w=20using=20paintbrush=20on=20things=20other=20than=20just=20st?= =?UTF-8?q?orage=20blocks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 4 +- .../block/BarrelBlockEntity.java | 9 +- .../block/IMaterialHolder.java | 13 ++ .../block/ShulkerBoxBlock.java | 3 +- .../block/StorageWrapper.java | 10 - .../block/WoodStorageBlockBase.java | 3 +- .../client/render/ChestItemRenderer.java | 3 +- .../client/render/ShulkerBoxItemRenderer.java | 3 +- .../item/PaintbrushItem.java | 185 ++++++++++-------- .../item/StackStorageWrapper.java | 29 +++ .../item/StorageTierUpgradeItem.java | 3 +- 11 files changed, 161 insertions(+), 104 deletions(-) create mode 100644 src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/IMaterialHolder.java diff --git a/gradle.properties b/gradle.properties index 6694f9b2..50c9593a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ loader_version_range=[4,) mod_id=sophisticatedstorage mod_name=Sophisticated Storage mod_license=GNU General Public License v3.0 -mod_version=1.1.2 +mod_version=1.1.3 mod_group_id=sophisticatedstorage mod_authors=P3pp3rF1y, Ridanisaurus mod_description=Fancy and functional storage containers. @@ -35,7 +35,7 @@ jade_cf_file_id=5109393 chipped_cf_file_id=5506938 resourcefullib_cf_file_id=5483169 athena_cf_file_id=5431579 -sc_version=[1.21.1-1.1.0,1.22) +sc_version=[1.21.1-1.2.0,1.22) sb_version=[1.21,1.22) #publish diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/BarrelBlockEntity.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/BarrelBlockEntity.java index a8df529a..aaf4c311 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/BarrelBlockEntity.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/BarrelBlockEntity.java @@ -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 materials = new EnumMap<>(BarrelMaterial.class); @@ -117,12 +117,19 @@ public void loadSynchronizedData(CompoundTag tag, HolderLookup.Provider registri materials = NBTHelper.getMap(tag, MATERIALS_TAG, BarrelMaterial::fromName, (bm, t) -> Optional.of(ResourceLocation.parse(t.getAsString()))).orElse(Map.of()); } + @Override public void setMaterials(Map materials) { this.materials = materials; setChanged(); } + @Override public Map getMaterials() { return materials; } + + @Override + public boolean canHoldMaterials() { + return true; + } } diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/IMaterialHolder.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/IMaterialHolder.java new file mode 100644 index 00000000..8146f1c4 --- /dev/null +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/IMaterialHolder.java @@ -0,0 +1,13 @@ +package net.p3pp3rf1y.sophisticatedstorage.block; + +import net.minecraft.resources.ResourceLocation; + +import java.util.Map; + +public interface IMaterialHolder { + void setMaterials(Map materials); + + Map getMaterials(); + + boolean canHoldMaterials(); +} diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/ShulkerBoxBlock.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/ShulkerBoxBlock.java index bacd1f50..4d6ec578 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/ShulkerBoxBlock.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/ShulkerBoxBlock.java @@ -146,8 +146,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.getNumberOfInventorySlots(level.registryAccess(), stack) - inventoryHandler.getSlots(), diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/StorageWrapper.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/StorageWrapper.java index e5681e3c..a361a687 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/StorageWrapper.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/StorageWrapper.java @@ -320,11 +320,6 @@ public boolean hasMainColor() { return mainColor != -1; } - public void setMainColor(int mainColor) { - this.mainColor = mainColor; - save(); - } - @Override public int getAccentColor() { return accentColor; @@ -334,11 +329,6 @@ public boolean hasAccentColor() { return accentColor != -1; } - public void setAccentColor(int accentColor) { - this.accentColor = accentColor; - save(); - } - @Override public Optional getOpenTabId() { return openTabId >= 0 ? Optional.of(openTabId) : Optional.empty(); diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/WoodStorageBlockBase.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/WoodStorageBlockBase.java index 4ff3fa94..bc4516b4 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/WoodStorageBlockBase.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/WoodStorageBlockBase.java @@ -187,8 +187,7 @@ private void setNewSize(ItemStack stack, WoodStorageBlockEntity be) { protected void setRenderBlockRenderProperties(ItemStack stack, WoodStorageBlockEntity be) { WoodStorageBlockItem.getWoodType(stack).ifPresent(be::setWoodType); - StorageBlockItem.getMainColorFromComponentHolder(stack).ifPresent(be.getStorageWrapper()::setMainColor); - StorageBlockItem.getAccentColorFromComponentHolder(stack).ifPresent(be.getStorageWrapper()::setAccentColor); + be.getStorageWrapper().setColors(StorageBlockItem.getMainColorFromComponentHolder(stack).orElse(-1), StorageBlockItem.getAccentColorFromComponentHolder(stack).orElse(-1)); } @Override diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/ChestItemRenderer.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/ChestItemRenderer.java index 83688011..d4317ca0 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/ChestItemRenderer.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/ChestItemRenderer.java @@ -82,8 +82,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 = WoodStorageBlockItem.getWoodType(stack); if (woodType.isPresent() || !(chestBlockEntity.getStorageWrapper().hasAccentColor() && chestBlockEntity.getStorageWrapper().hasMainColor())) { diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/ShulkerBoxItemRenderer.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/ShulkerBoxItemRenderer.java index 48dea6d2..13b8a94f 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/ShulkerBoxItemRenderer.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/render/ShulkerBoxItemRenderer.java @@ -51,8 +51,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(); diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/PaintbrushItem.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/PaintbrushItem.java index a842989b..3c329a08 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/PaintbrushItem.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/PaintbrushItem.java @@ -13,6 +13,7 @@ import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; import net.minecraft.tags.TagKey; import net.minecraft.util.ExtraCodecs; @@ -26,13 +27,11 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.common.Tags; import net.neoforged.neoforge.items.IItemHandler; import net.p3pp3rf1y.sophisticatedcore.init.ModCoreDataComponents; -import net.p3pp3rf1y.sophisticatedcore.util.ColorHelper; -import net.p3pp3rf1y.sophisticatedcore.util.InventoryHelper; -import net.p3pp3rf1y.sophisticatedcore.util.ItemBase; -import net.p3pp3rf1y.sophisticatedcore.util.WorldHelper; +import net.p3pp3rf1y.sophisticatedcore.util.*; import net.p3pp3rf1y.sophisticatedstorage.block.*; import net.p3pp3rf1y.sophisticatedstorage.client.gui.StorageTranslationHelper; import net.p3pp3rf1y.sophisticatedstorage.init.ModDataComponents; @@ -76,8 +75,8 @@ public static Optional getItemRequirements(ItemStack paintbrus private static Optional getMaterialItemRequirements(ItemStack paintbrush, Player player, BlockEntity be, Map materialsToApply) { Map allPartsNeeded = new HashMap<>(); - if (be instanceof StorageBlockEntity storageBe) { - allPartsNeeded = getStorageMaterialPartsNeeded(materialsToApply, storageBe); + if (be instanceof IMaterialHolder materialHolder) { + allPartsNeeded = getMaterialHolderPartsNeeded(materialsToApply, materialHolder); } else if (be instanceof ControllerBlockEntity controllerBe) { for (BlockPos storagePosition : controllerBe.getStoragePositions()) { addStorageMaterialPartsNeeded(materialsToApply, controllerBe, storagePosition, allPartsNeeded); @@ -87,6 +86,10 @@ private static Optional getMaterialItemRequirements(ItemStack if (allPartsNeeded.isEmpty()) { return Optional.empty(); } + return getItemRequirements(paintbrush, player, allPartsNeeded); + } + + public static Optional getItemRequirements(ItemStack paintbrush, Player player, Map allPartsNeeded) { Map remainingParts = getRemainingParts(paintbrush); DecorationHelper.ConsumptionResult result = DecorationHelper.consumeMaterialPartsNeeded(allPartsNeeded, remainingParts, InventoryHelper.getItemHandlersFromPlayerIncludingContainers(player), true); @@ -112,8 +115,8 @@ private static Optional getMaterialItemRequirements(ItemStack } private static void addStorageMaterialPartsNeeded(Map materialsToApply, ControllerBlockEntity controllerBe, BlockPos storagePosition, Map allPartsNeeded) { - WorldHelper.getBlockEntity(controllerBe.getLevel(), storagePosition, StorageBlockEntity.class).ifPresent(storageBe -> { - Map storagePartsNeeded = getStorageMaterialPartsNeeded(materialsToApply, storageBe); + WorldHelper.getBlockEntity(controllerBe.getLevel(), storagePosition, IMaterialHolder.class).ifPresent(materialHolder -> { + Map storagePartsNeeded = getMaterialHolderPartsNeeded(materialsToApply, materialHolder); storagePartsNeeded.forEach((part, count) -> allPartsNeeded.merge(part, count, Integer::sum)); }); } @@ -124,7 +127,7 @@ private static Optional getDyeItemRequirements(ItemStack paint Map, Integer> allPartsNeeded = new HashMap<>(); if (be instanceof StorageBlockEntity storageBe) { - allPartsNeeded = getStorageDyePartsNeeded(mainColorToSet, accentColorToSet, storageBe); + allPartsNeeded = getStorageDyePartsNeeded(mainColorToSet, accentColorToSet, storageBe.getStorageWrapper()); } else if (be instanceof ControllerBlockEntity controllerBe) { for (BlockPos storagePosition : controllerBe.getStoragePositions()) { addStorageDyePartsNeeded(mainColorToSet, accentColorToSet, controllerBe, storagePosition, allPartsNeeded); @@ -134,6 +137,10 @@ private static Optional getDyeItemRequirements(ItemStack paint if (allPartsNeeded.isEmpty()) { return Optional.empty(); } + return getDyeItemRequirements(paintbrush, player, allPartsNeeded); + } + + public static @NotNull Optional getDyeItemRequirements(ItemStack paintbrush, Player player, Map, Integer> allPartsNeeded) { Map remainingParts = getRemainingParts(paintbrush); DecorationHelper.ConsumptionResult result = DecorationHelper.consumeDyePartsNeeded(allPartsNeeded, InventoryHelper.getItemHandlersFromPlayerIncludingContainers(player), remainingParts, true); @@ -142,14 +149,13 @@ private static Optional getDyeItemRequirements(ItemStack paint private static void addStorageDyePartsNeeded(int mainColorToSet, int accentColorToSet, ControllerBlockEntity controllerBe, BlockPos storagePosition, Map, Integer> allPartsNeeded) { WorldHelper.getBlockEntity(controllerBe.getLevel(), storagePosition, StorageBlockEntity.class).ifPresent(storageBe -> { - Map, Integer> storagePartsNeeded = getStorageDyePartsNeeded(mainColorToSet, accentColorToSet, storageBe); + Map, Integer> storagePartsNeeded = getStorageDyePartsNeeded(mainColorToSet, accentColorToSet, storageBe.getStorageWrapper()); storagePartsNeeded.forEach((part, count) -> allPartsNeeded.merge(part, count, Integer::sum)); }); } - private static Map, Integer> getStorageDyePartsNeeded(int mainColorToSet, int accentColorToSet, StorageBlockEntity storageBe) { - StorageWrapper storageWrapper = storageBe.getStorageWrapper(); - return DecorationHelper.getDyePartsNeeded(mainColorToSet, accentColorToSet, storageWrapper.getMainColor(), storageWrapper.getAccentColor()); + public static Map, Integer> getStorageDyePartsNeeded(int mainColorToSet, int accentColorToSet, ITintable tintable) { + return DecorationHelper.getDyePartsNeeded(mainColorToSet, accentColorToSet, tintable.getMainColor(), tintable.getAccentColor()); } @@ -186,13 +192,10 @@ private static Map, Integer> getStorageDyePartsNeeded(int mainColor return Optional.of(new ItemRequirements(itemsPresent, itemsMissing)); } - private static Map getStorageMaterialPartsNeeded(Map materialsToApply, StorageBlockEntity storageBe) { - if (storageBe instanceof BarrelBlockEntity barrelBe) { - Map originalMaterials = new HashMap<>(barrelBe.getMaterials()); - BarrelBlockItem.uncompactMaterials(originalMaterials); - return DecorationHelper.getMaterialPartsNeeded(originalMaterials, materialsToApply); - } - return Collections.emptyMap(); + public static Map getMaterialHolderPartsNeeded(Map materialsToApply, IMaterialHolder materialHolder) { + Map originalMaterials = new HashMap<>(materialHolder.getMaterials()); + BarrelBlockItem.uncompactMaterials(originalMaterials); + return DecorationHelper.getMaterialPartsNeeded(originalMaterials, materialsToApply); } @Override @@ -232,96 +235,116 @@ private static void paintStorage(@Nullable Player player, ItemStack paintbrush, if (player == null) { return; } - List itemHandlers = InventoryHelper.getItemHandlersFromPlayerIncludingContainers(player); - Map remainingParts = new HashMap<>(getRemainingParts(paintbrush)); + ITintable tintable = storageBe.getStorageWrapper(); + IMaterialHolder materialHolder = storageBe instanceof IMaterialHolder ? (IMaterialHolder) storageBe : null; + + if (storageBe instanceof ChestBlockEntity chestBe) { + tintable = chestBe.getMainStorageWrapper(); + storageBe = chestBe.getMainChestBlockEntity(); + } + + BlockState state = storageBe.getBlockState(); + Direction effectOffsetDirection = state.getBlock() instanceof StorageBlockBase storageBlock ? storageBlock.getFacing(state) : Direction.UP; + if (paint(player, paintbrush, soundVolume, materialHolder, tintable, Vec3.atCenterOf(storageBe.getBlockPos()), effectOffsetDirection, state.getSoundType(player.level(), storageBe.getBlockPos(), null).getPlaceSound())) { + WorldHelper.notifyBlockUpdate(storageBe); + } + } + + public static boolean paint(@NotNull Player player, ItemStack paintbrush, @Nullable IMaterialHolder materialHolder, ITintable tintable, Vec3 successEffectPos, Direction effectOffsetDirection, SoundEvent placeSound) { + return paint(player, paintbrush, 1f, materialHolder, tintable, successEffectPos, effectOffsetDirection, placeSound); + } + + public static boolean paint(@NotNull Player player, ItemStack paintbrush, float soundVolume, @Nullable IMaterialHolder materialHolder, ITintable tintable, Vec3 successEffectPos, Direction effectOffsetDirection, SoundEvent placeSound) { if (hasBarrelMaterials(paintbrush)) { - if (!(storageBe instanceof BarrelBlockEntity barrelBe)) { - return; + if (materialHolder == null || !materialHolder.canHoldMaterials()) { + return false; } - Map originalMaterials = new HashMap<>(barrelBe.getMaterials()); - Map materialsToApply = new HashMap<>(getBarrelMaterials(paintbrush)); - if (originalMaterials.equals(materialsToApply)) { - return; + if (applyMaterials(player, paintbrush, materialHolder, tintable)) { + playSoundAndParticles(player.level(), successEffectPos, soundVolume, placeSound, effectOffsetDirection); + return true; + } + } else { + if (setColors(player, paintbrush, tintable, materialHolder)) { + playSoundAndParticles(player.level(), successEffectPos, soundVolume, placeSound, effectOffsetDirection); + return true; } + } + return false; + } - BarrelBlockItem.uncompactMaterials(originalMaterials); + public static boolean setColors(Player player, ItemStack paintbrush, ITintable tintable, @Nullable IMaterialHolder materialHolder) { + Map remainingParts = new HashMap<>(getRemainingParts(paintbrush)); + List itemHandlers = InventoryHelper.getItemHandlersFromPlayerIncludingContainers(player); + int mainColorToSet = getMainColor(paintbrush); + int accentColorToSet = getAccentColor(paintbrush); - if (!DecorationHelper.consumeMaterials(remainingParts, itemHandlers, originalMaterials, materialsToApply, true)) { - return; - } + int originalMainColor = tintable.getMainColor(); + int originalAccentColor = tintable.getAccentColor(); - DecorationHelper.consumeMaterials(remainingParts, itemHandlers, originalMaterials, materialsToApply, false); - setRemainingParts(paintbrush, remainingParts); + if (originalMainColor == mainColorToSet && originalAccentColor == accentColorToSet) { + return false; + } - barrelBe.getStorageWrapper().setMainColor(-1); - barrelBe.getStorageWrapper().setAccentColor(-1); - BarrelBlockItem.compactMaterials(materialsToApply); - barrelBe.setMaterials(materialsToApply); + if (!DecorationHelper.consumeDyes(mainColorToSet, accentColorToSet, remainingParts, itemHandlers, originalMainColor, originalAccentColor, true)) { + return false; + } - playSoundAndParticles(player.level(), storageBe.getBlockPos(), storageBe, soundVolume); + tintable.setColors(mainColorToSet, accentColorToSet); - WorldHelper.notifyBlockUpdate(storageBe); - } else { - StorageWrapper storageWrapper = storageBe.getStorageWrapper(); - int mainColorToSet = getMainColor(paintbrush); - int accentColorToSet = getAccentColor(paintbrush); - if (storageBe instanceof ChestBlockEntity chestBe) { - storageWrapper = chestBe.getMainStorageWrapper(); - storageBe = chestBe.getMainChestBlockEntity(); - } + if (materialHolder != null) { + materialHolder.setMaterials(Collections.emptyMap()); + } - int originalMainColor = storageWrapper.getMainColor(); - int originalAccentColor = storageWrapper.getAccentColor(); + DecorationHelper.consumeDyes(mainColorToSet, accentColorToSet, remainingParts, itemHandlers, originalMainColor, originalAccentColor, false); + setRemainingParts(paintbrush, remainingParts); + return true; + } - if (originalMainColor == mainColorToSet && originalAccentColor == accentColorToSet) { - return; - } + private static boolean applyMaterials(Player player, ItemStack paintbrush, IMaterialHolder materialHolder, ITintable tintable) { + List itemHandlers = InventoryHelper.getItemHandlersFromPlayerIncludingContainers(player); + Map remainingParts = new HashMap<>(getRemainingParts(paintbrush)); - if (!DecorationHelper.consumeDyes(mainColorToSet, accentColorToSet, remainingParts, itemHandlers, originalMainColor, originalAccentColor, true)) { - return; - } + Map originalMaterials = new HashMap<>(materialHolder.getMaterials()); + Map materialsToApply = new HashMap<>(getBarrelMaterials(paintbrush)); + if (originalMaterials.equals(materialsToApply)) { + return false; + } - if (hasMainColor(paintbrush)) { - storageWrapper.setMainColor(mainColorToSet); - } - if (hasAccentColor(paintbrush)) { - storageWrapper.setAccentColor(accentColorToSet); - } + BarrelBlockItem.uncompactMaterials(originalMaterials); - if (storageBe instanceof BarrelBlockEntity barrelBe) { - barrelBe.setMaterials(Collections.emptyMap()); - } + if (!DecorationHelper.consumeMaterials(remainingParts, itemHandlers, originalMaterials, materialsToApply, true)) { + return false; + } - DecorationHelper.consumeDyes(mainColorToSet, accentColorToSet, remainingParts, itemHandlers, originalMainColor, originalAccentColor, false); - setRemainingParts(paintbrush, remainingParts); + DecorationHelper.consumeMaterials(remainingParts, itemHandlers, originalMaterials, materialsToApply, false); + setRemainingParts(paintbrush, remainingParts); - playSoundAndParticles(player.level(), storageBe.getBlockPos(), storageBe, soundVolume); + tintable.setColors(-1, -1); - WorldHelper.notifyBlockUpdate(storageBe); - } + BarrelBlockItem.compactMaterials(materialsToApply); + materialHolder.setMaterials(materialsToApply); + return true; } - private static void playSoundAndParticles(Level level, BlockPos pos, StorageBlockEntity storageBe, float soundVolume) { - BlockState state = storageBe.getBlockState(); - level.playSound(null, pos, state.getSoundType(level, pos, null).getPlaceSound(), SoundSource.BLOCKS, soundVolume, 1); + private static void playSoundAndParticles(Level level, Vec3 pos, float soundVolume, SoundEvent placeSound, Direction effectOffsetDirection) { + level.playSound(null, pos.x(), pos.y(), pos.z(), placeSound, SoundSource.BLOCKS, soundVolume, 1); - if (state.getBlock() instanceof StorageBlockBase storageBlock && level instanceof ServerLevel serverLevel) { - Direction facing = storageBlock.getFacing(state); - double x = pos.getX() + 0.5D + facing.getStepX() * 0.6D; - double y = pos.getY() + 0.5D + facing.getStepY() * 0.6D; - double z = pos.getZ() + 0.5D + facing.getStepZ() * 0.6D; + if (level instanceof ServerLevel serverLevel) { + double x = pos.x() + 0.5D + effectOffsetDirection.getStepX() * 0.6D; + double y = pos.y() + 0.5D + effectOffsetDirection.getStepY() * 0.6D; + double z = pos.z() + 0.5D + effectOffsetDirection.getStepZ() * 0.6D; double xOffset; double yOffset; double zOffset; - if (facing.getAxis().isVertical()) { + if (effectOffsetDirection.getAxis().isVertical()) { xOffset = 0.4D; yOffset = 0.1D; zOffset = 0.4D; } else { - xOffset = 0.1D + facing.getStepZ() * 0.3D; + xOffset = 0.1D + effectOffsetDirection.getStepZ() * 0.3D; yOffset = 0.4D; - zOffset = 0.1D + facing.getStepX() * 0.3D; + zOffset = 0.1D + effectOffsetDirection.getStepX() * 0.3D; } serverLevel.sendParticles(ParticleTypes.HAPPY_VILLAGER, x, y, z, 4, xOffset, yOffset, zOffset, 1f); diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/StackStorageWrapper.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/StackStorageWrapper.java index 377fde2d..cffd34ca 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/StackStorageWrapper.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/StackStorageWrapper.java @@ -127,4 +127,33 @@ public String getStorageType() { public Component getDisplayName() { return Component.empty(); //because this is only used when determining upgrade errors in gui which storage stacks can't have open } + + @Override + public void setColors(int mainColor, int accentColor) { + storageStack.set(ModCoreDataComponents.MAIN_COLOR, mainColor); + storageStack.set(ModCoreDataComponents.ACCENT_COLOR, accentColor); + save(); + } + + @Override + public int getMainColor() { + return storageStack.getOrDefault(ModCoreDataComponents.MAIN_COLOR, -1); + } + + + @Override + public boolean hasMainColor() { + return storageStack.has(ModCoreDataComponents.MAIN_COLOR); + } + + @Override + public int getAccentColor() { + return storageStack.getOrDefault(ModCoreDataComponents.ACCENT_COLOR, -1); + } + + @Override + public boolean hasAccentColor() { + return storageStack.has(ModCoreDataComponents.ACCENT_COLOR); + } + } diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/StorageTierUpgradeItem.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/StorageTierUpgradeItem.java index c5225493..8758f45a 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/StorageTierUpgradeItem.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/item/StorageTierUpgradeItem.java @@ -310,8 +310,7 @@ private void setStorageItemsNameAndWoodType(StorageBlockEntity newBe, @Nullable } if (color != -1) { - storageWrapper.setMainColor(color); - storageWrapper.setAccentColor(color); + storageWrapper.setColors(color, color); } } }