diff --git a/gradle.properties b/gradle.properties index 7e5e133a..d29e5c9a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.daemon=false mod_id=sophisticatedstorage mod_group_id=sophisticatedstorage -mod_version=1.2.0 +mod_version=1.2.1 sonar_project_key=sophisticatedstorage:SophisticatedStorage github_package_url=https://maven.pkg.github.com/P3pp3rF1y/SophisticatedStorage diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/DecorationTableBlockEntity.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/DecorationTableBlockEntity.java index ef9dcafa..20290edd 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/DecorationTableBlockEntity.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/block/DecorationTableBlockEntity.java @@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.DyeableLeatherItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; @@ -25,6 +26,7 @@ import javax.annotation.Nullable; import java.util.*; +import java.util.function.Predicate; import java.util.stream.Collectors; public class DecorationTableBlockEntity extends BlockEntity { @@ -41,10 +43,10 @@ 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<>(); + private static final Map, IItemDecorator> ITEM_DECORATORS = new LinkedHashMap<>(); - public static void registerItemDecorator(Class itemClass, IItemDecorator itemDecorator) { - ITEM_DECORATORS.put(itemClass, itemDecorator); + public static void registerItemDecorator(Predicate itemMatcher, IItemDecorator itemDecorator) { + ITEM_DECORATORS.put(itemMatcher, itemDecorator); } private final Map remainingParts = new HashMap<>(); @@ -102,7 +104,7 @@ protected void onContentsChanged(int slot) { @Override public boolean isItemValid(int slot, ItemStack stack) { - return ITEM_DECORATORS.keySet().stream().anyMatch(clazz -> clazz.isInstance(stack.getItem())); + return ITEM_DECORATORS.keySet().stream().anyMatch(predicate -> predicate.test(stack)); } }; @@ -123,7 +125,7 @@ private void updateResult() { } private static Optional getItemDecorator(ItemStack input) { - return ITEM_DECORATORS.entrySet().stream().filter(e -> e.getKey().isInstance(input.getItem())).findFirst().map(Map.Entry::getValue); + return ITEM_DECORATORS.entrySet().stream().filter(e -> e.getKey().test(input)).findFirst().map(Map.Entry::getValue); } private TintDecorationResult decorateItem(IItemDecorator itemDecorator, ItemStack input) { @@ -539,8 +541,8 @@ public TintDecorationResult decorateWithTints(ItemStack input, int mainColorToSe }; static { - ITEM_DECORATORS.put(StorageBlockItem.class, STORAGE_DECORATOR); - ITEM_DECORATORS.put(PaintbrushItem.class, new IItemDecorator() { + ITEM_DECORATORS.put(stack -> stack.getItem() instanceof StorageBlockItem, STORAGE_DECORATOR); + ITEM_DECORATORS.put(stack -> stack.getItem() instanceof PaintbrushItem, new IItemDecorator() { @Override public boolean consumesIngredientsOnCraft() { return false; @@ -599,5 +601,38 @@ public List getPreviewStackInputs(ItemStack input, boolean materialsI return List.of(new ItemStack(ModBlocks.LIMITED_BARREL_3_ITEM.get()), new ItemStack(ModBlocks.CHEST_ITEM.get()), new ItemStack(ModBlocks.SHULKER_BOX_ITEM.get())); } }); + ITEM_DECORATORS.put(stack -> stack.getItem() instanceof DyeableLeatherItem, new 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 TintDecorationResult decorateWithTints(ItemStack input, int mainColorToSet, int accentColorToSet) { + if (mainColorToSet == -1 || !(input.getItem() instanceof DyeableLeatherItem dyeableLeatherItem) || dyeableLeatherItem.getColor(input) == mainColorToSet) { + return TintDecorationResult.EMPTY; + } + int currentColor = dyeableLeatherItem.getColor(input); + ItemStack result = input.copyWithCount(1); + dyeableLeatherItem.setColor(result, mainColorToSet); + + return new TintDecorationResult(result, DecorationHelper.getDyePartsNeeded(mainColorToSet, -1, currentColor, -1, 24, 0)); + } + }); } } diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/sb/SBCompat.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/sb/SBCompat.java index 420c2dfb..cbf71a0d 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/sb/SBCompat.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/compat/sb/SBCompat.java @@ -14,7 +14,7 @@ public class SBCompat implements ICompat { @Override public void setup() { - DecorationTableBlockEntity.registerItemDecorator(BackpackItem.class, new DecorationTableBlockEntity.IItemDecorator() { + DecorationTableBlockEntity.registerItemDecorator(stack -> stack.getItem() instanceof BackpackItem, new DecorationTableBlockEntity.IItemDecorator() { @Override public boolean supportsMaterials(ItemStack input) { return false;