From 122e274ff71e2586b3246b89a0ccc23897f0afb0 Mon Sep 17 00:00:00 2001 From: P3pp3rF1y Date: Tue, 14 Jan 2025 15:54:29 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Added=20support=20for=20col?= =?UTF-8?q?oring=20backpacks=20in=20Decoration=20Table=20and=20in=20the=20?= =?UTF-8?q?process=20made=20decoration=20table=20code=20more=20flexible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../block/DecorationTableBlockEntity.java | 336 ++++++++++++------ .../client/gui/DecorationTableScreen.java | 23 +- .../common/gui/DecorationTableMenu.java | 5 +- .../compat/jade/package-info.java | 8 + .../compat/quark/package-info.java | 8 + .../compat/sb/SBCompat.java | 61 ++++ .../compat/sb/package-info.java | 8 + .../sophisticatedstorage/init/ModCompat.java | 3 + .../util/DecorationHelper.java | 8 +- 10 files changed, 328 insertions(+), 134 deletions(-) create mode 100644 src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/jade/package-info.java create mode 100644 src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/quark/package-info.java create mode 100644 src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/sb/SBCompat.java create mode 100644 src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/sb/package-info.java diff --git a/gradle.properties b/gradle.properties index c7388a27b..3e24bbb65 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.5 +mod_version=1.2.0 mod_group_id=sophisticatedstorage mod_authors=P3pp3rF1y, Ridanisaurus mod_description=Fancy and functional storage containers. diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/DecorationTableBlockEntity.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/DecorationTableBlockEntity.java index b473f62bc..765c62be1 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/DecorationTableBlockEntity.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/DecorationTableBlockEntity.java @@ -7,6 +7,7 @@ import net.minecraft.nbt.Tag; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -41,6 +42,12 @@ public class DecorationTableBlockEntity extends BlockEntity { public static final Set STORAGES_WIHOUT_TOP_INNER_TRIM = Set.of(ModBlocks.BARREL_ITEM.get(), ModBlocks.COPPER_BARREL_ITEM.get(), ModBlocks.IRON_BARREL_ITEM.get(), ModBlocks.GOLD_BARREL_ITEM.get(), ModBlocks.DIAMOND_BARREL_ITEM.get(), ModBlocks.NETHERITE_BARREL_ITEM.get(), ModBlocks.LIMITED_BARREL_1_ITEM.get(), ModBlocks.LIMITED_COPPER_BARREL_1_ITEM.get(), ModBlocks.LIMITED_IRON_BARREL_1_ITEM.get(), ModBlocks.LIMITED_GOLD_BARREL_1_ITEM.get(), ModBlocks.LIMITED_DIAMOND_BARREL_1_ITEM.get(), ModBlocks.LIMITED_NETHERITE_BARREL_1_ITEM.get()); + private static final Map, IItemDecorator> ITEM_DECORATORS = new LinkedHashMap<>(); + + public static void registerItemDecorator(Class itemClass, IItemDecorator itemDecorator) { + ITEM_DECORATORS.put(itemClass, itemDecorator); + } + private final Map remainingParts = new HashMap<>(); private final ItemStackHandler decorativeBlocks = new ItemStackHandler(7) { @@ -96,7 +103,7 @@ protected void onContentsChanged(int slot) { @Override public boolean isItemValid(int slot, ItemStack stack) { - return stack.getItem() instanceof StorageBlockItem || stack.getItem() instanceof PaintbrushItem; + return ITEM_DECORATORS.keySet().stream().anyMatch(clazz -> clazz.isInstance(stack.getItem())); } }; @@ -104,107 +111,54 @@ private void updateResult() { missingDyes.clear(); result = ItemStack.EMPTY; - ItemStack storage = storageBlock.getStackInSlot(0); - if (storage.isEmpty()) { + ItemStack input = storageBlock.getStackInSlot(0); + if (input.isEmpty()) { return; } - if (storage.getItem() instanceof PaintbrushItem) { - updatePaintbrushResult(storage); - return; - } - - DecorationResult decorationResult = decorateStack(storage); - result = decorationResult.result(); - missingDyes.addAll(decorationResult.missingDyes()); - } - - public boolean hasMaterials() { - return !InventoryHelper.isEmpty(decorativeBlocks); + getItemDecorator(input).ifPresent(itemDecorator -> { + TintDecorationResult decorationResult = decorateItem(itemDecorator, input); + result = decorationResult.result(); + missingDyes.addAll(calculateMissingDyes(decorationResult.requiredDyeParts())); + }); } - public record DecorationResult(ItemStack result, Set missingDyes) { - public static final DecorationResult EMPTY = new DecorationResult(ItemStack.EMPTY, Collections.emptySet()); + private static Optional getItemDecorator(ItemStack input) { + return ITEM_DECORATORS.entrySet().stream().filter(e -> e.getKey().isInstance(input.getItem())).findFirst().map(Map.Entry::getValue); } - public DecorationResult decorateStack(ItemStack storage) { - ItemStack result; - if ((InventoryHelper.isEmpty(decorativeBlocks) || !(storage.getItem() instanceof BarrelBlockItem) || isTintedStorage(storage)) && (colorsTransparentOrSameAs(storage) || !BarrelBlockItem.getMaterials(storage).isEmpty())) { - return DecorationResult.EMPTY; - } - if (!(storage.getItem() instanceof BarrelBlockItem) || InventoryHelper.isEmpty(decorativeBlocks) || isTintedStorage(storage)) { - result = storage.copy(); - result.setCount(1); - if (result.getItem() instanceof BlockItem blockItem && blockItem instanceof ITintableBlockItem tintableBlockItem) { - if (mainColor != -1) { - tintableBlockItem.setMainColor(result, mainColor); - } - if (accentColor != -1) { - tintableBlockItem.setAccentColor(result, accentColor); - } + private TintDecorationResult decorateItem(IItemDecorator itemDecorator, ItemStack input) { + if (itemDecorator.supportsMaterials(input)) { + Map materialsToApply = getMaterialsToApply(itemDecorator.supportsTopInnerTrim(input)); + if (!materialsToApply.isEmpty()) { + return new TintDecorationResult(itemDecorator.decorateWithMaterials(input, materialsToApply), Collections.emptyMap()); } - Set missingDyes = calculateMissingDyes(storage); - return new DecorationResult(result, missingDyes); } - - if (InventoryHelper.isEmpty(decorativeBlocks)) { - return DecorationResult.EMPTY; + if (itemDecorator.supportsTints(input)) { + return itemDecorator.decorateWithTints(input, mainColor, accentColor); } - - Map materials = new EnumMap<>(BarrelMaterial.class); - materials.putAll(BarrelBlockItem.getMaterials(storage)); - BarrelBlockItem.uncompactMaterials(materials); - - setMaterialsFromDecorativeBlocks(materials, !STORAGES_WIHOUT_TOP_INNER_TRIM.contains(storage.getItem())); - BarrelBlockItem.compactMaterials(materials); - - if (allMaterialsMatch(materials, BarrelBlockItem.getMaterials(storage))) { - return DecorationResult.EMPTY; - } - - result = storage.copy(); - result.setCount(1); - - BarrelBlockItem.removeCoveredTints(result, materials); - BarrelBlockItem.setMaterials(result, materials); - - return new DecorationResult(result, Collections.emptySet()); + return TintDecorationResult.EMPTY; } - private void updatePaintbrushResult(ItemStack paintbrush) { - if (!InventoryHelper.isEmpty(decorativeBlocks)) { - Map materials = new EnumMap<>(BarrelMaterial.class); - setMaterialsFromDecorativeBlocks(materials, true); - BarrelBlockItem.compactMaterials(materials); - - if (allMaterialsMatch(materials, BarrelBlockItem.getMaterials(paintbrush))) { - return; - } - - result = paintbrush.copy(); - result.setCount(1); - PaintbrushItem.setBarrelMaterials(result, materials); - } else { - if ((mainColor == -1 && accentColor == -1) || (mainColor == PaintbrushItem.getMainColor(paintbrush) && accentColor == PaintbrushItem.getAccentColor(paintbrush))) { - return; - } - - result = paintbrush.copy(); - result.setCount(1); - if (mainColor != -1) { - PaintbrushItem.setMainColor(result, mainColor); - } - if (accentColor != -1) { - PaintbrushItem.setAccentColor(result, accentColor); - } - } + public boolean hasMaterials() { + return !InventoryHelper.isEmpty(decorativeBlocks); } - private boolean isTintedStorage(ItemStack storage) { - return StorageBlockItem.getMainColorFromComponentHolder(storage).isPresent() || StorageBlockItem.getAccentColorFromComponentHolder(storage).isPresent(); + public List getDecoratedPreviewStacks() { + ItemStack input = storageBlock.getStackInSlot(0); + return getItemDecorator(input).map(itemDecorator -> { + List previewStacks = new ArrayList<>(); + itemDecorator.getPreviewStackInputs(input, hasMaterials()).forEach(stack -> { + TintDecorationResult decorationResult = decorateItem(itemDecorator, stack); + if (!decorationResult.result().isEmpty()) { + previewStacks.add(decorationResult.result()); + } + }); + return previewStacks; + }).orElse(Collections.emptyList()); } - private boolean allMaterialsMatch(Map newMaterials, Map currentMaterials) { + public static boolean allMaterialsMatch(Map newMaterials, Map currentMaterials) { if (newMaterials.size() != currentMaterials.size()) { return false; } @@ -218,16 +172,14 @@ private boolean allMaterialsMatch(Map newMater return true; } - private Set calculateMissingDyes(ItemStack storage) { + private Set calculateMissingDyes(Map, Integer> requiredDyeParts) { Set missingDyes = new HashSet<>(); if (!dyes.getStackInSlot(RED_DYE_SLOT).isEmpty() && !dyes.getStackInSlot(GREEN_DYE_SLOT).isEmpty() && !dyes.getStackInSlot(BLUE_DYE_SLOT).isEmpty()) { return missingDyes; } Map partsNeeded = - DecorationHelper.getDyePartsNeeded(mainColor, accentColor, - StorageBlockItem.getMainColorFromComponentHolder(storage).orElse(-1), StorageBlockItem.getAccentColorFromComponentHolder(storage).orElse(-1)) - .entrySet().stream().map(entry -> Map.entry(entry.getKey().location(), entry.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + requiredDyeParts.entrySet().stream().map(entry -> Map.entry(entry.getKey().location(), entry.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); for (Map.Entry entry : partsNeeded.entrySet()) { if (entry.getKey().equals(Tags.Items.DYES_RED.location()) && dyes.getStackInSlot(RED_DYE_SLOT).isEmpty()) { @@ -241,12 +193,12 @@ private Set calculateMissingDyes(ItemStack storage) { return missingDyes; } - public Set getMissingDyes() { - return missingDyes; + private static Map, Integer> calculateRequiredDyes(int mainColorToSet, int accentColorToSet, int currentMainColor, int currentAccentColor) { + return DecorationHelper.getDyePartsNeeded(mainColorToSet, accentColorToSet, currentMainColor, currentAccentColor); } - private boolean colorsTransparentOrSameAs(ItemStack storage) { - return (mainColor == -1 || mainColor == StorageBlockItem.getMainColorFromComponentHolder(storage).orElse(-1)) && (accentColor == -1 || accentColor == StorageBlockItem.getAccentColorFromComponentHolder(storage).orElse(-1)); + public Set getMissingDyes() { + return missingDyes; } private void setMaterialsFromDecorativeBlocks(Map materials, boolean supportsInnerTrim) { @@ -422,19 +374,25 @@ private void saveData(CompoundTag tag, HolderLookup.Provider registries) { } public void consumeIngredientsOnCraft() { - if (getStorageBlock().getStackInSlot(0).getItem() instanceof PaintbrushItem) { - return; //paintbrush consumes ingredients by itself on application to storage block - } - ItemStack storageStack = storageBlock.getStackInSlot(0); - if (InventoryHelper.isEmpty(decorativeBlocks)) { - DecorationHelper.consumeDyes(mainColor, accentColor, this.remainingParts, List.of(dyes), StorageBlockItem.getMainColorFromComponentHolder(storageStack).orElse(-1), StorageBlockItem.getAccentColorFromComponentHolder(storageStack).orElse(-1), false); - } else { - Map originalMaterials = BarrelBlockItem.getUncompactedMaterials(storageStack); - DecorationHelper.consumeMaterials(this.remainingParts, List.of(decorativeBlocks), originalMaterials, getMaterialsToApply(storageStack), false); - } + ItemStack input = storageBlock.getStackInSlot(0); + + getItemDecorator(input).ifPresent(itemDecorator -> { + if (!itemDecorator.consumesIngredientsOnCraft()) { + return; + } + + boolean emptyDecorativeBlocks = InventoryHelper.isEmpty(decorativeBlocks); + if ((emptyDecorativeBlocks || !itemDecorator.supportsMaterials(input)) && itemDecorator.supportsTints(input)) { + DecorationHelper.consumeDyes(mainColor, accentColor, this.remainingParts, List.of(dyes), StorageBlockItem.getMainColorFromComponentHolder(input).orElse(-1), StorageBlockItem.getAccentColorFromComponentHolder(input).orElse(-1), false); + } else if (!emptyDecorativeBlocks && itemDecorator.supportsMaterials(input)) { + Map originalMaterials = BarrelBlockItem.getUncompactedMaterials(input); + DecorationHelper.consumeMaterials(this.remainingParts, List.of(decorativeBlocks), originalMaterials, getMaterialsToApply(!STORAGES_WIHOUT_TOP_INNER_TRIM.contains(input.getItem())), false); + } + + setChanged(); + WorldHelper.notifyBlockUpdate(this); + }); - setChanged(); - WorldHelper.notifyBlockUpdate(this); } public Map getPartsNeeded() { @@ -444,15 +402,15 @@ public Map getPartsNeeded() { DecorationHelper.getDyePartsNeeded(mainColor, accentColor, StorageBlockItem.getMainColorFromComponentHolder(storageStack).orElse(-1), StorageBlockItem.getAccentColorFromComponentHolder(storageStack).orElse(-1)) .forEach((tag, parts) -> partsNeeded.put(tag.location(), parts)); } else { - partsNeeded.putAll(DecorationHelper.getMaterialPartsNeeded(BarrelBlockItem.getUncompactedMaterials(storageStack), getMaterialsToApply(storageStack))); + partsNeeded.putAll(DecorationHelper.getMaterialPartsNeeded(BarrelBlockItem.getUncompactedMaterials(storageStack), getMaterialsToApply(!STORAGES_WIHOUT_TOP_INNER_TRIM.contains(storageStack.getItem())))); } return partsNeeded; } - private Map getMaterialsToApply(ItemStack storageStack) { + private Map getMaterialsToApply(boolean supportsInnerTrim) { Map materialsToApply = new EnumMap<>(BarrelMaterial.class); - setMaterialsFromDecorativeBlocks(materialsToApply, !STORAGES_WIHOUT_TOP_INNER_TRIM.contains(storageStack.getItem())); + setMaterialsFromDecorativeBlocks(materialsToApply, supportsInnerTrim); return materialsToApply; } @@ -483,4 +441,164 @@ public void dropContents() { InventoryHelper.dropItems(dyes, level, worldPosition); InventoryHelper.dropItems(storageBlock, level, worldPosition); } + + public record TintDecorationResult(ItemStack result, Map, Integer> requiredDyeParts) { + public static final TintDecorationResult EMPTY = new TintDecorationResult(ItemStack.EMPTY, Collections.emptyMap()); + } + + public interface IItemDecorator { + default boolean consumesIngredientsOnCraft() { + return true; + } + + boolean supportsMaterials(ItemStack input); + + boolean supportsTints(ItemStack input); + + boolean supportsTopInnerTrim(ItemStack input); + + ItemStack decorateWithMaterials(ItemStack input, Map materialsToApply); + + TintDecorationResult decorateWithTints(ItemStack input, int mainColorToSet, int accentColorToSet); + + default List getPreviewStackInputs(ItemStack input, boolean materialsInCraftingSlots) { + return List.of(input); + } + } + + private static boolean isTintedStorage(ItemStack storage) { + return StorageBlockItem.getMainColorFromComponentHolder(storage).isPresent() || StorageBlockItem.getAccentColorFromComponentHolder(storage).isPresent(); + } + + private static boolean colorsTransparentOrSameAs(ItemStack storage, int mainColorToSet, int accentColorToSet) { + return (mainColorToSet == -1 || mainColorToSet == StorageBlockItem.getMainColorFromComponentHolder(storage).orElse(-1)) && (accentColorToSet == -1 || accentColorToSet == StorageBlockItem.getAccentColorFromComponentHolder(storage).orElse(-1)); + } + + public static final IItemDecorator STORAGE_DECORATOR = new IItemDecorator() { + @Override + public boolean supportsMaterials(ItemStack input) { + return input.getItem() instanceof BarrelBlockItem && !isTintedStorage(input); + } + + @Override + public boolean supportsTints(ItemStack input) { + return !(input.getItem() instanceof BarrelBlockItem) || BarrelBlockItem.getMaterials(input).isEmpty(); + } + + @Override + public boolean supportsTopInnerTrim(ItemStack input) { + return !STORAGES_WIHOUT_TOP_INNER_TRIM.contains(input.getItem()); + } + + @Override + public ItemStack decorateWithMaterials(ItemStack input, Map materialsToApply) { + if (materialsToApply.isEmpty()) { + return ItemStack.EMPTY; + } + + Map materials = new EnumMap<>(BarrelMaterial.class); + materials.putAll(BarrelBlockItem.getMaterials(input)); + BarrelBlockItem.uncompactMaterials(materials); + + materials.putAll(materialsToApply); + + BarrelBlockItem.compactMaterials(materials); + + if (allMaterialsMatch(materials, BarrelBlockItem.getMaterials(input))) { + return ItemStack.EMPTY; + } + + ItemStack result = input.copyWithCount(1); + + BarrelBlockItem.removeCoveredTints(result, materials); + BarrelBlockItem.setMaterials(result, materials); + + return result; + } + + @Override + public TintDecorationResult decorateWithTints(ItemStack input, int mainColorToSet, int accentColorToSet) { + if (colorsTransparentOrSameAs(input, mainColorToSet, accentColorToSet)) { + return TintDecorationResult.EMPTY; + } + + ItemStack result = input.copyWithCount(1); + + if (result.getItem() instanceof BlockItem blockItem && blockItem instanceof ITintableBlockItem tintableBlockItem) { + if (mainColorToSet != -1) { + tintableBlockItem.setMainColor(result, mainColorToSet); + } + if (accentColorToSet != -1) { + tintableBlockItem.setAccentColor(result, accentColorToSet); + } + } + + return new TintDecorationResult(result, calculateRequiredDyes(mainColorToSet, accentColorToSet, StorageBlockItem.getMainColorFromComponentHolder(input).orElse(-1), StorageBlockItem.getAccentColorFromComponentHolder(input).orElse(-1))); + + } + }; + + static { + ITEM_DECORATORS.put(StorageBlockItem.class, STORAGE_DECORATOR); + ITEM_DECORATORS.put(PaintbrushItem.class, new IItemDecorator() { + @Override + public boolean consumesIngredientsOnCraft() { + return false; + } + + @Override + public boolean supportsMaterials(ItemStack input) { + return true; + } + + @Override + public boolean supportsTints(ItemStack input) { + return true; + } + + @Override + public boolean supportsTopInnerTrim(ItemStack input) { + return true; + } + + @Override + public ItemStack decorateWithMaterials(ItemStack input, Map materialsToApply) { + BarrelBlockItem.compactMaterials(materialsToApply); + + if (allMaterialsMatch(materialsToApply, BarrelBlockItem.getMaterials(input))) { + return ItemStack.EMPTY; + } + + ItemStack result = input.copyWithCount(1); + PaintbrushItem.setBarrelMaterials(result, materialsToApply); + return result; + } + + @Override + public TintDecorationResult decorateWithTints(ItemStack input, int mainColorToSet, int accentColorToSet) { + if ((mainColorToSet == -1 && accentColorToSet == -1) || (mainColorToSet == PaintbrushItem.getMainColor(input) && accentColorToSet == PaintbrushItem.getAccentColor(input))) { + return TintDecorationResult.EMPTY; + } + + ItemStack result = input.copyWithCount(1); + if (mainColorToSet != -1) { + PaintbrushItem.setMainColor(result, mainColorToSet); + } + if (accentColorToSet != -1) { + PaintbrushItem.setAccentColor(result, accentColorToSet); + } + return new TintDecorationResult(result, Collections.emptyMap()); + + } + + @Override + public List getPreviewStackInputs(ItemStack input, boolean materialsInCraftingSlots) { + if (materialsInCraftingSlots) { + return List.of(new ItemStack(ModBlocks.LIMITED_BARREL_3_ITEM.get())); + } + + return List.of(new ItemStack(ModBlocks.LIMITED_BARREL_3_ITEM.get()), new ItemStack(ModBlocks.CHEST_ITEM.get()), new ItemStack(ModBlocks.SHULKER_BOX_ITEM.get())); + } + }); + } } diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/gui/DecorationTableScreen.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/gui/DecorationTableScreen.java index 2c98b22a0..e190f82a8 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/gui/DecorationTableScreen.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/client/gui/DecorationTableScreen.java @@ -36,9 +36,7 @@ import net.p3pp3rf1y.sophisticatedstorage.SophisticatedStorage; import net.p3pp3rf1y.sophisticatedstorage.block.DecorationTableBlockEntity; import net.p3pp3rf1y.sophisticatedstorage.common.gui.DecorationTableMenu; -import net.p3pp3rf1y.sophisticatedstorage.init.ModBlocks; import net.p3pp3rf1y.sophisticatedstorage.init.ModItems; -import net.p3pp3rf1y.sophisticatedstorage.item.StorageBlockItem; import net.p3pp3rf1y.sophisticatedstorage.util.DecorationHelper; import javax.annotation.Nullable; @@ -100,22 +98,7 @@ public DecorationTableScreen(DecorationTableMenu menu, Inventory playerInventory private void updatePreviewStacks() { if (blockPreview != null) { - ItemStack storageStack = getMenu().getStorageSlot().getItem(); - - if (storageStack.getItem() instanceof StorageBlockItem) { - blockPreview.setPreviewStacks(List.of(getMenu().getResultSlot().getItem())); - } else if (storageStack.getItem() == ModItems.PAINTBRUSH.get() && !getMenu().getResultSlot().getItem().isEmpty()) { - ItemStack barrelPreviewStack = getMenu().decorateStack(new ItemStack(ModBlocks.LIMITED_BARREL_3_ITEM.get())); - if (getMenu().hasMaterials()) { - blockPreview.setPreviewStacks(List.of(barrelPreviewStack)); - } else { - ItemStack chestPreviewStack = getMenu().decorateStack(new ItemStack(ModBlocks.CHEST_ITEM.get())); - ItemStack shulkerPreviewStack = getMenu().decorateStack(new ItemStack(ModBlocks.SHULKER_BOX_ITEM.get())); - blockPreview.setPreviewStacks(List.of(barrelPreviewStack, chestPreviewStack, shulkerPreviewStack)); - } - } else { - blockPreview.setPreviewStacks(Collections.emptyList()); - } + blockPreview.setPreviewStacks(getMenu().getDecoratedPreviewStacks()); } } @@ -163,10 +146,10 @@ private void addDyeElements() { Slot topTrimSlot = menu.getSlot(DecorationTableBlockEntity.TOP_TRIM_SLOT); Slot sideTrimSlot = menu.getSlot(DecorationTableBlockEntity.SIDE_TRIM_SLOT); - ColorButton mainColorButton = new ColorButton(new Position(leftPos + greenDyeSlot.x - 1, topPos + topTrimSlot.y), new Dimension(18, 18), menu::getMainColor, + ColorButton mainColorButton = new ColorButton(new Position(leftPos + greenDyeSlot.x - 1, topPos + topTrimSlot.y - 1), new Dimension(18, 18), menu::getMainColor, button -> openColorPicker(menu.getMainColor(), menu::setMainColor), Component.translatable(StorageTranslationHelper.INSTANCE.translButton("pick_color"))); addRenderableWidget(mainColorButton); - ColorButton accentColorButton = new ColorButton(new Position(leftPos + greenDyeSlot.x - 1, topPos + sideTrimSlot.y), new Dimension(18, 18), menu::getAccentColor, + ColorButton accentColorButton = new ColorButton(new Position(leftPos + greenDyeSlot.x - 1, topPos + sideTrimSlot.y - 1), new Dimension(18, 18), menu::getAccentColor, button -> openColorPicker(menu.getAccentColor(), menu::setAccentColor), Component.translatable(StorageTranslationHelper.INSTANCE.translButton("pick_color"))); addRenderableWidget(accentColorButton); diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/common/gui/DecorationTableMenu.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/common/gui/DecorationTableMenu.java index f7597be76..0dcb2e08b 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/common/gui/DecorationTableMenu.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/common/gui/DecorationTableMenu.java @@ -22,6 +22,7 @@ import net.p3pp3rf1y.sophisticatedstorage.init.ModBlocks; import javax.annotation.Nullable; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Consumer; @@ -66,8 +67,8 @@ public Slot getStorageSlot() { return storageSlot; } - public ItemStack decorateStack(ItemStack stack) { - return blockEntity.decorateStack(stack).result(); + public List getDecoratedPreviewStacks() { + return blockEntity.getDecoratedPreviewStacks(); } private void addStorageSlots() { diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/jade/package-info.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/jade/package-info.java new file mode 100644 index 000000000..82f0bc906 --- /dev/null +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/jade/package-info.java @@ -0,0 +1,8 @@ +// Auto generated package-info by MCP + +@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault +package net.p3pp3rf1y.sophisticatedstorage.compat.jade; + +import net.minecraft.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/quark/package-info.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/quark/package-info.java new file mode 100644 index 000000000..d812d5550 --- /dev/null +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/quark/package-info.java @@ -0,0 +1,8 @@ +// Auto generated package-info by MCP + +@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault +package net.p3pp3rf1y.sophisticatedstorage.compat.quark; + +import net.minecraft.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/sb/SBCompat.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/sb/SBCompat.java new file mode 100644 index 000000000..a03fc19bf --- /dev/null +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/sb/SBCompat.java @@ -0,0 +1,61 @@ +package net.p3pp3rf1y.sophisticatedstorage.compat.sb; + +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.p3pp3rf1y.sophisticatedbackpacks.backpack.BackpackItem; +import net.p3pp3rf1y.sophisticatedbackpacks.backpack.wrapper.BackpackWrapper; +import net.p3pp3rf1y.sophisticatedbackpacks.backpack.wrapper.IBackpackWrapper; +import net.p3pp3rf1y.sophisticatedcore.compat.ICompat; +import net.p3pp3rf1y.sophisticatedstorage.block.BarrelMaterial; +import net.p3pp3rf1y.sophisticatedstorage.block.DecorationTableBlockEntity; +import net.p3pp3rf1y.sophisticatedstorage.util.DecorationHelper; + +import java.util.Map; + +public class SBCompat implements ICompat { + @Override + public void setup() { + DecorationTableBlockEntity.registerItemDecorator(BackpackItem.class, new DecorationTableBlockEntity.IItemDecorator() { + @Override + public boolean supportsMaterials(ItemStack input) { + return false; + } + + @Override + public boolean supportsTints(ItemStack input) { + return true; + } + + @Override + public boolean supportsTopInnerTrim(ItemStack input) { + return false; + } + + @Override + public ItemStack decorateWithMaterials(ItemStack input, Map materialsToApply) { + return ItemStack.EMPTY; + } + + @Override + public DecorationTableBlockEntity.TintDecorationResult decorateWithTints(ItemStack input, int mainColorToSet, int accentColorToSet) { + if (colorsTransparentOrSameAs(input, mainColorToSet, accentColorToSet)) { + return DecorationTableBlockEntity.TintDecorationResult.EMPTY; + } + + ItemStack result = input.copyWithCount(1); + + IBackpackWrapper backpackWrapper = BackpackWrapper.fromStack(result); + int originalMainColor = backpackWrapper.getMainColor(); + int originalAccentColor = backpackWrapper.getAccentColor(); + + backpackWrapper.setColors(mainColorToSet, accentColorToSet); + return new DecorationTableBlockEntity.TintDecorationResult(result, DecorationHelper.getDyePartsNeeded(mainColorToSet, accentColorToSet, originalMainColor, originalAccentColor, 20, 4)); + } + + private boolean colorsTransparentOrSameAs(ItemStack backpack, int mainColorToSet, int accentColorToSet) { + IBackpackWrapper backpackWrapper = BackpackWrapper.fromStack(backpack); + return (mainColorToSet == -1 || mainColorToSet == backpackWrapper.getMainColor()) && (accentColorToSet == -1 || accentColorToSet == backpackWrapper.getAccentColor()); + } + }); + } +} diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/sb/package-info.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/sb/package-info.java new file mode 100644 index 000000000..e19ac9723 --- /dev/null +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/sb/package-info.java @@ -0,0 +1,8 @@ +// Auto generated package-info by MCP + +@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault +package net.p3pp3rf1y.sophisticatedstorage.compat.sb; + +import net.minecraft.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/init/ModCompat.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/init/ModCompat.java index 1b0f948e4..418aa8ce6 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/init/ModCompat.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/init/ModCompat.java @@ -5,13 +5,16 @@ import net.p3pp3rf1y.sophisticatedcore.compat.CompatRegistry; import net.p3pp3rf1y.sophisticatedstorage.compat.chipped.ChippedCompat; import net.p3pp3rf1y.sophisticatedstorage.compat.quark.QuarkCompat; +import net.p3pp3rf1y.sophisticatedstorage.compat.sb.SBCompat; public class ModCompat { + private static final String SB_MOD_ID = "sophisticatedbackpacks"; private ModCompat() { } public static void register() { CompatRegistry.registerCompat(new CompatInfo(CompatModIds.QUARK, null), () -> modBus -> new QuarkCompat()); CompatRegistry.registerCompat(new CompatInfo(CompatModIds.CHIPPED, null), () -> modBus -> new ChippedCompat()); + CompatRegistry.registerCompat(new CompatInfo(SB_MOD_ID, null), () -> modBus -> new SBCompat()); } } diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/util/DecorationHelper.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/util/DecorationHelper.java index e2245b577..d6d3b2a88 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/util/DecorationHelper.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/util/DecorationHelper.java @@ -52,13 +52,17 @@ public static boolean consumeDyes(int mainColorBeingSet, int accentColorBeingSet } public static Map, Integer> getDyePartsNeeded(int mainColorBeingSet, int accentColorBeingSet, int storageMainColor, int storageAccentColor) { + return getDyePartsNeeded(mainColorBeingSet, accentColorBeingSet, storageMainColor, storageAccentColor, MAIN_COLOR_PARTS, ACCENT_COLOR_PARTS); + } + + public static Map, Integer> getDyePartsNeeded(int mainColorBeingSet, int accentColorBeingSet, int storageMainColor, int storageAccentColor, int mainColorParts, int accentColorParts) { Map, Integer> partsNeeded = new HashMap<>(); if (mainColorBeingSet != -1 && mainColorBeingSet != storageMainColor) { - int[] rgbPartsNeeded = calculateRGBPartsNeeded(mainColorBeingSet, MAIN_COLOR_PARTS); + int[] rgbPartsNeeded = calculateRGBPartsNeeded(mainColorBeingSet, mainColorParts); addPartsNeededIfAny(rgbPartsNeeded, partsNeeded); } if (accentColorBeingSet != -1 && accentColorBeingSet != storageAccentColor) { - int[] rgbPartsNeeded = calculateRGBPartsNeeded(accentColorBeingSet, ACCENT_COLOR_PARTS); + int[] rgbPartsNeeded = calculateRGBPartsNeeded(accentColorBeingSet, accentColorParts); addPartsNeededIfAny(rgbPartsNeeded, partsNeeded); } return partsNeeded;