From 64a36fd2ae78b1d2dae4fc661ed05ffeb05991f3 Mon Sep 17 00:00:00 2001 From: HateMe <14168138+HateMeLikeAPro@users.noreply.github.com> Date: Fri, 19 Apr 2024 17:26:54 +0200 Subject: [PATCH] Added InItemGroup Added the InItemGroup attribute filter back. --- .../logistics/filter/ItemAttribute.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/main/java/com/simibubi/create/content/logistics/filter/ItemAttribute.java b/src/main/java/com/simibubi/create/content/logistics/filter/ItemAttribute.java index 2a7f9aa4a..bdb1a442f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/filter/ItemAttribute.java +++ b/src/main/java/com/simibubi/create/content/logistics/filter/ItemAttribute.java @@ -40,6 +40,8 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.ComposterBlock; @@ -47,6 +49,7 @@ import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.minecraftforge.common.CreativeModeTabRegistry; import net.minecraftforge.fml.ModContainer; import net.minecraftforge.fml.ModList; import net.minecraftforge.forgespi.language.IModInfo; @@ -59,6 +62,7 @@ public interface ItemAttribute { static ItemAttribute standard = register(StandardTraits.DUMMY); static ItemAttribute inTag = register(new InTag(ItemTags.LOGS)); + static ItemAttribute inItemGroup = register(InItemGroup.EMPTY); static ItemAttribute addedBy = register(new AddedBy("dummy")); static ItemAttribute hasEnchant = register(EnchantAttribute.EMPTY); static ItemAttribute shulkerFillLevel = register(ShulkerFillLevelAttribute.EMPTY); @@ -273,6 +277,55 @@ public interface ItemAttribute { } + public static class InItemGroup implements ItemAttribute { + public static final InItemGroup EMPTY = new InItemGroup(null); + + private CreativeModeTab group; + + public InItemGroup(CreativeModeTab group) { + this.group = group; + } + + @Override + public boolean appliesTo(ItemStack stack) { + return group != null && group.contains(stack); + } + + @Override + public List listAttributesOf(ItemStack stack) { + return CreativeModeTabs.tabs().stream() + .filter(tab -> !tab.hasSearchBar() && tab.contains(stack)) + .map(tab -> (ItemAttribute)new InItemGroup(tab)) + .toList(); + } + + @Override + public String getTranslationKey() { + return "in_item_group"; + } + + @Override + public Object[] getTranslationParameters() { + return new Object[] { group == null ? "" : group.getDisplayName().getString() }; + } + + @Override + public void writeNBT(CompoundTag nbt) { + if (group != null) { + ResourceLocation groupId = CreativeModeTabRegistry.getName(group); + + if (groupId != null) { + nbt.putString("group", groupId.toString()); + } + } + } + + @Override + public ItemAttribute readNBT(CompoundTag nbt) { + return nbt.contains("group") ? new InItemGroup(CreativeModeTabRegistry.getTab(new ResourceLocation(nbt.getString("group")))) : EMPTY; + } + } + public static class AddedBy implements ItemAttribute { private String modId;