From a7e2d842afa41c52849946408774feac0094876f Mon Sep 17 00:00:00 2001 From: Colman Davenport Date: Sat, 17 Oct 2020 00:04:23 -0400 Subject: [PATCH 1/8] Specific Enchantment Attribute --- .../logistics/item/filter/ItemAttribute.java | 2 + .../filter/attribute/EnchantAttribute.java | 71 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/EnchantAttribute.java diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java index fe8dca539..a3283eb3e 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java @@ -9,6 +9,7 @@ import java.util.function.BiPredicate; import java.util.function.Predicate; import java.util.stream.Collectors; +import com.simibubi.create.content.logistics.item.filter.attribute.EnchantAttribute; import org.apache.commons.lang3.StringUtils; import com.google.common.base.Predicates; @@ -43,6 +44,7 @@ public interface ItemAttribute { static ItemAttribute standard = register(StandardTraits.DUMMY); static ItemAttribute inTag = register(new InTag(new ResourceLocation("dummy"))); static ItemAttribute inItemGroup = register(new InItemGroup(ItemGroup.MISC)); + static ItemAttribute hasEnchant = register(new EnchantAttribute("dummy")); static ItemAttribute addedBy = register(new AddedBy("dummy")); static ItemAttribute register(ItemAttribute attributeType) { diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/EnchantAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/EnchantAttribute.java new file mode 100644 index 000000000..a30548862 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/EnchantAttribute.java @@ -0,0 +1,71 @@ +package com.simibubi.create.content.logistics.item.filter.attribute; + +import com.simibubi.create.content.logistics.item.filter.ItemAttribute; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.TranslationTextComponent; +import net.minecraftforge.registries.ForgeRegistries; + +import java.util.ArrayList; +import java.util.List; + +public class EnchantAttribute implements ItemAttribute { + String enchantName; + + public EnchantAttribute(String enchantName) { + this.enchantName = enchantName; + } + + @Override + public boolean appliesTo(ItemStack itemStack) { + ListNBT enchants = extractEnchants(itemStack); + for (int i = 0; i < enchants.size(); i++) { + if(enchants.getCompound(i).getString("id").equals(this.enchantName)) + return true; + } + return false; + } + + @Override + public List listAttributesOf(ItemStack itemStack) { + ListNBT enchants = extractEnchants(itemStack); + List atts = new ArrayList<>(); + for (int i = 0; i < enchants.size(); i++) { + atts.add(new EnchantAttribute(enchants.getCompound(i).getString("id"))); + } + return atts; + } + + @Override + public String getTranslationKey() { + return "has_enchant"; + } + + @Override + public Object[] getTranslationParameters() { + String something = ""; + Enchantment enchant = ForgeRegistries.ENCHANTMENTS.getValue(ResourceLocation.tryCreate(enchantName)); + if(enchant != null) { + something = new TranslationTextComponent(enchant.getName()).getString(); + } + return new Object[] { something }; + } + + @Override + public void writeNBT(CompoundNBT nbt) { + nbt.putString("id", this.enchantName); + } + + @Override + public ItemAttribute readNBT(CompoundNBT nbt) { + return new EnchantAttribute(nbt.getString("id")); + } + + private ListNBT extractEnchants(ItemStack stack) { + CompoundNBT tag = stack.getTag() != null ? stack.getTag() : new CompoundNBT(); + return tag.contains("Enchantments") ? stack.getEnchantmentTagList() : tag.getList("StoredEnchantments", 10); + } +} From 6ff57ca65c85c9cce8875e31c19fe4a7532adb5d Mon Sep 17 00:00:00 2001 From: Colman Davenport Date: Sat, 17 Oct 2020 00:26:16 -0400 Subject: [PATCH 2/8] Fluid Container Attributes --- .../logistics/item/filter/ItemAttribute.java | 4 + .../attribute/FluidContentsAttribute.java | 83 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/FluidContentsAttribute.java diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java index a3283eb3e..3170f104e 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java @@ -10,6 +10,8 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import com.simibubi.create.content.logistics.item.filter.attribute.EnchantAttribute; +import com.simibubi.create.content.logistics.item.filter.attribute.FluidContentsAttribute; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import org.apache.commons.lang3.StringUtils; import com.google.common.base.Predicates; @@ -45,6 +47,7 @@ public interface ItemAttribute { static ItemAttribute inTag = register(new InTag(new ResourceLocation("dummy"))); static ItemAttribute inItemGroup = register(new InItemGroup(ItemGroup.MISC)); static ItemAttribute hasEnchant = register(new EnchantAttribute("dummy")); + static ItemAttribute hasFluid = register(new FluidContentsAttribute("dummy")); static ItemAttribute addedBy = register(new AddedBy("dummy")); static ItemAttribute register(ItemAttribute attributeType) { @@ -108,6 +111,7 @@ public interface ItemAttribute { DUMMY(s -> false), PLACEABLE(s -> s.getItem() instanceof BlockItem), CONSUMABLE(ItemStack::isFood), + FLUID_CONTAINER(s -> s.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY).isPresent()), ENCHANTED(ItemStack::isEnchanted), DAMAGED(ItemStack::isDamaged), BADLY_DAMAGED(s -> s.isDamaged() && s.getDamage() / s.getMaxDamage() > 3 / 4f), diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/FluidContentsAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/FluidContentsAttribute.java new file mode 100644 index 000000000..421282b9b --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/FluidContentsAttribute.java @@ -0,0 +1,83 @@ +package com.simibubi.create.content.logistics.item.filter.attribute; + +import com.simibubi.create.content.logistics.item.filter.ItemAttribute; +import net.minecraft.fluid.Fluid; +import net.minecraft.item.BucketItem; +import net.minecraft.item.GlassBottleItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.TranslationTextComponent; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; +import net.minecraftforge.fluids.capability.IFluidHandlerItem; +import net.minecraftforge.registries.ForgeRegistries; + +import java.util.ArrayList; +import java.util.List; + +public class FluidContentsAttribute implements ItemAttribute { + String fluidName; + + public FluidContentsAttribute(String fluidName) { + this.fluidName = fluidName; + } + + @Override + public boolean appliesTo(ItemStack itemStack) { + return extractFluidNames(itemStack).contains(fluidName); + } + + @Override + public List listAttributesOf(ItemStack itemStack) { + List names = extractFluidNames(itemStack); + + List atts = new ArrayList<>(); + for(String name : names) { + atts.add(new FluidContentsAttribute(name)); + } + return atts; + } + + @Override + public String getTranslationKey() { + return "has_fluid"; + } + + @Override + public Object[] getTranslationParameters() { + ResourceLocation fluidResource = new ResourceLocation(fluidName); + Fluid fluid = ForgeRegistries.FLUIDS.getValue(fluidResource); + String trans = ""; + if(fluid != null) + trans = new TranslationTextComponent(fluid.getAttributes().getTranslationKey()).getString(); + return new Object[] {trans}; + } + + @Override + public void writeNBT(CompoundNBT nbt) { + nbt.putString("fluidName", this.fluidName); + } + + @Override + public ItemAttribute readNBT(CompoundNBT nbt) { + return new FluidContentsAttribute(nbt.getString("fluidName")); + } + + private List extractFluidNames(ItemStack stack) { + List fluids = new ArrayList<>(); + + LazyOptional capability = + stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY); + + capability.ifPresent((cap) -> { + for(int i = 0; i < cap.getTanks(); i++) { + fluids.add(cap.getFluidInTank(i).getFluid().getRegistryName().toString()); + } + }); + + return fluids; + } +} From c1bb1e64c9b3611a3bd362c5aac9b8ad9e9a55ed Mon Sep 17 00:00:00 2001 From: Colman Davenport Date: Sat, 17 Oct 2020 00:58:49 -0400 Subject: [PATCH 3/8] Custom Name Attributes --- .../logistics/item/filter/ItemAttribute.java | 3 + .../filter/attribute/ItemNameAttribute.java | 71 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/ItemNameAttribute.java diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java index 3170f104e..8b2bd991c 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java @@ -11,6 +11,7 @@ import java.util.stream.Collectors; import com.simibubi.create.content.logistics.item.filter.attribute.EnchantAttribute; import com.simibubi.create.content.logistics.item.filter.attribute.FluidContentsAttribute; +import com.simibubi.create.content.logistics.item.filter.attribute.ItemNameAttribute; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import org.apache.commons.lang3.StringUtils; @@ -48,6 +49,7 @@ public interface ItemAttribute { static ItemAttribute inItemGroup = register(new InItemGroup(ItemGroup.MISC)); static ItemAttribute hasEnchant = register(new EnchantAttribute("dummy")); static ItemAttribute hasFluid = register(new FluidContentsAttribute("dummy")); + static ItemAttribute hasName = register(new ItemNameAttribute("dummy")); static ItemAttribute addedBy = register(new AddedBy("dummy")); static ItemAttribute register(ItemAttribute attributeType) { @@ -113,6 +115,7 @@ public interface ItemAttribute { CONSUMABLE(ItemStack::isFood), FLUID_CONTAINER(s -> s.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY).isPresent()), ENCHANTED(ItemStack::isEnchanted), + RENAMED(ItemStack::hasDisplayName), DAMAGED(ItemStack::isDamaged), BADLY_DAMAGED(s -> s.isDamaged() && s.getDamage() / s.getMaxDamage() > 3 / 4f), NOT_STACKABLE(Predicates.not(ItemStack::isStackable)), diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/ItemNameAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/ItemNameAttribute.java new file mode 100644 index 000000000..2f83e648a --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/ItemNameAttribute.java @@ -0,0 +1,71 @@ +package com.simibubi.create.content.logistics.item.filter.attribute; + +import com.google.gson.JsonParseException; +import com.simibubi.create.content.logistics.item.filter.ItemAttribute; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TranslationTextComponent; + +import java.util.ArrayList; +import java.util.List; + +public class ItemNameAttribute implements ItemAttribute { + String itemName; + + public ItemNameAttribute(String itemName) { + this.itemName = itemName; + } + + @Override + public boolean appliesTo(ItemStack itemStack) { + return extractCustomName(itemStack).equals(itemName); + } + + @Override + public List listAttributesOf(ItemStack itemStack) { + String name = extractCustomName(itemStack); + + List atts = new ArrayList<>(); + if(name.length() > 0) { + atts.add(new ItemNameAttribute(name)); + } + return atts; + } + + @Override + public String getTranslationKey() { + return "has_name"; + } + + @Override + public Object[] getTranslationParameters() { + return new Object[] { itemName }; + } + + @Override + public void writeNBT(CompoundNBT nbt) { + nbt.putString("name", this.itemName); + } + + @Override + public ItemAttribute readNBT(CompoundNBT nbt) { + return new ItemNameAttribute(nbt.getString("name")); + } + + private String extractCustomName(ItemStack stack) { + CompoundNBT compoundnbt = stack.getChildTag("display"); + if (compoundnbt != null && compoundnbt.contains("Name", 8)) { + try { + ITextComponent itextcomponent = ITextComponent.Serializer.fromJson(compoundnbt.getString("Name")); + if (itextcomponent != null) { + return itextcomponent.getString(); + } + } catch (JsonParseException ignored) { + } + } + return ""; + } +} From 562abdea3139bbf23f784e4c35a55970ecee54ef Mon Sep 17 00:00:00 2001 From: Colman Davenport Date: Sat, 17 Oct 2020 01:16:32 -0400 Subject: [PATCH 4/8] Written Book Attributes --- .../logistics/item/filter/ItemAttribute.java | 6 +- .../filter/attribute/BookAuthorAttribute.java | 63 ++++++++++++++++++ .../filter/attribute/BookCopyAttribute.java | 66 +++++++++++++++++++ 3 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/BookAuthorAttribute.java create mode 100644 src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/BookCopyAttribute.java diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java index 8b2bd991c..aee1da7d9 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java @@ -9,9 +9,7 @@ import java.util.function.BiPredicate; import java.util.function.Predicate; import java.util.stream.Collectors; -import com.simibubi.create.content.logistics.item.filter.attribute.EnchantAttribute; -import com.simibubi.create.content.logistics.item.filter.attribute.FluidContentsAttribute; -import com.simibubi.create.content.logistics.item.filter.attribute.ItemNameAttribute; +import com.simibubi.create.content.logistics.item.filter.attribute.*; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import org.apache.commons.lang3.StringUtils; @@ -50,6 +48,8 @@ public interface ItemAttribute { static ItemAttribute hasEnchant = register(new EnchantAttribute("dummy")); static ItemAttribute hasFluid = register(new FluidContentsAttribute("dummy")); static ItemAttribute hasName = register(new ItemNameAttribute("dummy")); + static ItemAttribute bookAuthor = register(new BookAuthorAttribute("dummy")); + static ItemAttribute bookCopy = register(new BookCopyAttribute(-1)); static ItemAttribute addedBy = register(new AddedBy("dummy")); static ItemAttribute register(ItemAttribute attributeType) { diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/BookAuthorAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/BookAuthorAttribute.java new file mode 100644 index 000000000..44c97ed28 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/BookAuthorAttribute.java @@ -0,0 +1,63 @@ +package com.simibubi.create.content.logistics.item.filter.attribute; + +import com.google.gson.JsonParseException; +import com.simibubi.create.content.logistics.item.filter.ItemAttribute; +import net.minecraft.item.ItemStack; +import net.minecraft.item.WrittenBookItem; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.text.ITextComponent; + +import java.util.ArrayList; +import java.util.List; + +public class BookAuthorAttribute implements ItemAttribute { + String author; + + public BookAuthorAttribute(String author) { + this.author = author; + } + + @Override + public boolean appliesTo(ItemStack itemStack) { + return extractAuthor(itemStack).equals(author); + } + + @Override + public List listAttributesOf(ItemStack itemStack) { + String name = extractAuthor(itemStack); + + List atts = new ArrayList<>(); + if(name.length() > 0) { + atts.add(new BookAuthorAttribute(name)); + } + return atts; + } + + @Override + public String getTranslationKey() { + return "book_author"; + } + + @Override + public Object[] getTranslationParameters() { + return new Object[] {author}; + } + + @Override + public void writeNBT(CompoundNBT nbt) { + nbt.putString("author", this.author); + } + + @Override + public ItemAttribute readNBT(CompoundNBT nbt) { + return new BookAuthorAttribute(nbt.getString("author")); + } + + private String extractAuthor(ItemStack stack) { + CompoundNBT nbt = stack.getTag(); + if (nbt != null && nbt.contains("author")) { + return nbt.getString("author"); + } + return ""; + } +} diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/BookCopyAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/BookCopyAttribute.java new file mode 100644 index 000000000..e379a3bdc --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/BookCopyAttribute.java @@ -0,0 +1,66 @@ +package com.simibubi.create.content.logistics.item.filter.attribute; + +import com.simibubi.create.content.logistics.item.filter.ItemAttribute; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.item.WrittenBookItem; +import net.minecraft.nbt.CompoundNBT; + +import java.util.ArrayList; +import java.util.List; + +public class BookCopyAttribute implements ItemAttribute { + int generation; + + public BookCopyAttribute(int generation) { + this.generation = generation; + } + + @Override + public boolean appliesTo(ItemStack itemStack) { + return extractGeneration(itemStack) == generation; + } + + @Override + public List listAttributesOf(ItemStack itemStack) { + int generation = extractGeneration(itemStack); + + List atts = new ArrayList<>(); + if(generation >= 0) { + atts.add(new BookCopyAttribute(generation)); + } + return atts; + } + + @Override + public String getTranslationKey() { + switch(generation){ + case 0: + return "book_copy_original"; + case 1: + return "book_copy_first"; + case 2: + return "book_copy_second"; + default: + return "book_copy_tattered"; + } + } + + @Override + public void writeNBT(CompoundNBT nbt) { + nbt.putInt("generation", this.generation); + } + + @Override + public ItemAttribute readNBT(CompoundNBT nbt) { + return new BookCopyAttribute(nbt.getInt("generation")); + } + + private int extractGeneration(ItemStack stack) { + CompoundNBT nbt = stack.getTag(); + if (nbt != null && stack.getItem() instanceof WrittenBookItem) { + return nbt.getInt("generation"); + } + return -1; + } +} From 822ca6dad69ea08da1ba8a13153caedb43935b30 Mon Sep 17 00:00:00 2001 From: Colman Davenport Date: Sat, 17 Oct 2020 01:17:25 -0400 Subject: [PATCH 5/8] Lang --- .../resources/assets/create/lang/en_us.json | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/generated/resources/assets/create/lang/en_us.json b/src/generated/resources/assets/create/lang/en_us.json index 622a30a18..1cae0dc94 100644 --- a/src/generated/resources/assets/create/lang/en_us.json +++ b/src/generated/resources/assets/create/lang/en_us.json @@ -840,6 +840,10 @@ "create.item_attributes.blastable.inverted": "is not smeltable in Blast Furnace", "create.item_attributes.enchanted": "is enchanted", "create.item_attributes.enchanted.inverted": "is unenchanted", + "create.item_attributes.renamed": "has a custom name", + "create.item_attributes.renamed.inverted": "does not have a custom name", + "create.item_attributes.fluid_container": "can hold fluid", + "create.item_attributes.fluid_container.inverted": "cannot hold fluid", "create.item_attributes.damaged": "is damaged", "create.item_attributes.damaged.inverted": "is not damaged", "create.item_attributes.badly_damaged": "is heavily damaged", @@ -856,6 +860,23 @@ "create.item_attributes.in_item_group.inverted": "is not in group '%1$s'", "create.item_attributes.added_by": "was added by %1$s", "create.item_attributes.added_by.inverted": "was not added by %1$s", + "create.item_attributes.has_enchant": "is enchanted with %1$s", + "create.item_attributes.has_enchant.inverted": "is not enchanted with %1$s", + "create.item_attributes.has_fluid": "contains %1$s", + "create.item_attributes.has_fluid.inverted": "does not contain %1$s", + "create.item_attributes.has_name": "has the custom name %1$s", + "create.item_attributes.has_name.inverted": "does not have the custom name %1$s", + "create.item_attributes.book_author": "was authored by %1$s", + "create.item_attributes.book_author.inverted": "was not authored by %1$s", + "create.item_attributes.book_copy_original": "is an original", + "create.item_attributes.book_copy_original.inverted": "is not an original", + "create.item_attributes.book_copy_first": "is a first-generation copy", + "create.item_attributes.book_copy_first.inverted": "is not a first-generation copy", + "create.item_attributes.book_copy_second": "is a second-generation copy", + "create.item_attributes.book_copy_second.inverted": "is not a second-generation copy", + "create.item_attributes.book_copy_tattered": "is a tattered mess", + "create.item_attributes.book_copy_tattered.inverted": "is not a tattered mess", + "create.gui.attribute_filter.no_selected_attributes": "No attributes selected", "create.gui.attribute_filter.selected_attributes": "Selected attributes:", From 6d51a6c7305723e690e45d9c9cca703d7e2f481b Mon Sep 17 00:00:00 2001 From: Colman Davenport Date: Sat, 17 Oct 2020 01:25:29 -0400 Subject: [PATCH 6/8] Astral Sorcery Attributes --- .../resources/assets/create/lang/en_us.json | 9 ++- .../logistics/item/filter/ItemAttribute.java | 8 ++ .../AstralSorceryAmuletAttribute.java | 81 +++++++++++++++++++ .../AstralSorceryAttunementAttribute.java | 76 +++++++++++++++++ .../AstralSorceryCrystalAttribute.java | 65 +++++++++++++++ .../AstralSorceryPerkGemAttribute.java | 65 +++++++++++++++ 6 files changed, 303 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryAmuletAttribute.java create mode 100644 src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryAttunementAttribute.java create mode 100644 src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryCrystalAttribute.java create mode 100644 src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryPerkGemAttribute.java diff --git a/src/generated/resources/assets/create/lang/en_us.json b/src/generated/resources/assets/create/lang/en_us.json index 1cae0dc94..4b9cb7861 100644 --- a/src/generated/resources/assets/create/lang/en_us.json +++ b/src/generated/resources/assets/create/lang/en_us.json @@ -876,7 +876,14 @@ "create.item_attributes.book_copy_second.inverted": "is not a second-generation copy", "create.item_attributes.book_copy_tattered": "is a tattered mess", "create.item_attributes.book_copy_tattered.inverted": "is not a tattered mess", - + "create.item_attributes.astralsorcery_crystal": "has crystal attribute %1$s", + "create.item_attributes.astralsorcery_crystal.inverted": "does not have crystal attribute %1$s", + "create.item_attributes.astralsorcery_constellation": "is attuned to %1$s", + "create.item_attributes.astralsorcery_constellation.inverted": "is not attuned to %1$s", + "create.item_attributes.astralsorcery_perk_gem": "has perk attribute %1$s", + "create.item_attributes.astralsorcery_perk_gem.inverted": "does not have perk attribute %1$s", + "create.item_attributes.astralsorcery_amulet": "improves %1$s", + "create.item_attributes.astralsorcery_amulet.inverted": "does not improve %1$s", "create.gui.attribute_filter.no_selected_attributes": "No attributes selected", "create.gui.attribute_filter.selected_attributes": "Selected attributes:", diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java index aee1da7d9..8c369cbc7 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java @@ -10,6 +10,10 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import com.simibubi.create.content.logistics.item.filter.attribute.*; +import com.simibubi.create.content.logistics.item.filter.attribute.astralsorcery.AstralSorceryAmuletAttribute; +import com.simibubi.create.content.logistics.item.filter.attribute.astralsorcery.AstralSorceryAttunementAttribute; +import com.simibubi.create.content.logistics.item.filter.attribute.astralsorcery.AstralSorceryCrystalAttribute; +import com.simibubi.create.content.logistics.item.filter.attribute.astralsorcery.AstralSorceryPerkGemAttribute; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import org.apache.commons.lang3.StringUtils; @@ -48,6 +52,10 @@ public interface ItemAttribute { static ItemAttribute hasEnchant = register(new EnchantAttribute("dummy")); static ItemAttribute hasFluid = register(new FluidContentsAttribute("dummy")); static ItemAttribute hasName = register(new ItemNameAttribute("dummy")); + static ItemAttribute astralAmulet = register(new AstralSorceryAmuletAttribute("dummy", -1)); + static ItemAttribute astralAttunement = register(new AstralSorceryAttunementAttribute("dummy")); + static ItemAttribute astralCrystal = register(new AstralSorceryCrystalAttribute("dummy")); + static ItemAttribute astralPerkGem = register(new AstralSorceryPerkGemAttribute("dummy")); static ItemAttribute bookAuthor = register(new BookAuthorAttribute("dummy")); static ItemAttribute bookCopy = register(new BookCopyAttribute(-1)); static ItemAttribute addedBy = register(new AddedBy("dummy")); diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryAmuletAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryAmuletAttribute.java new file mode 100644 index 000000000..f2e8ab062 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryAmuletAttribute.java @@ -0,0 +1,81 @@ +package com.simibubi.create.content.logistics.item.filter.attribute.astralsorcery; + +import com.simibubi.create.content.logistics.item.filter.ItemAttribute; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.INBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.TranslationTextComponent; +import net.minecraftforge.registries.ForgeRegistries; + +import java.util.ArrayList; +import java.util.List; + +public class AstralSorceryAmuletAttribute implements ItemAttribute { + String enchName; + int enchType; + + public AstralSorceryAmuletAttribute(String enchName, int enchType) { + this.enchName = enchName; + this.enchType = enchType; + } + + @Override + public boolean appliesTo(ItemStack itemStack) { + for (INBT trait : extractTraitList(itemStack)) { + if(((CompoundNBT) trait).getString("ench").equals(this.enchName) + && ((CompoundNBT)trait).getInt("type") == this.enchType) + return true; + } + return false; + } + + @Override + public List listAttributesOf(ItemStack itemStack) { + ListNBT traits = extractTraitList(itemStack); + List atts = new ArrayList<>(); + for (int i = 0; i < traits.size(); i++) { + atts.add(new AstralSorceryAmuletAttribute( + traits.getCompound(i).getString("ench"), + traits.getCompound(i).getInt("type"))); + } + return atts; + } + + @Override + public String getTranslationKey() { + return "astralsorcery_amulet"; + } + + @Override + public Object[] getTranslationParameters() { + ResourceLocation traitResource = new ResourceLocation(enchName); + String something = ""; + + Enchantment enchant = ForgeRegistries.ENCHANTMENTS.getValue(ResourceLocation.tryCreate(enchName)); + if(enchant != null) { + something = new TranslationTextComponent(enchant.getName()).getString(); + } + + if(enchType == 1) something = "existing " + something; + + return new Object[] { something }; + } + + @Override + public void writeNBT(CompoundNBT nbt) { + nbt.putString("enchName", this.enchName); + nbt.putInt("enchType", this.enchType); + } + + @Override + public ItemAttribute readNBT(CompoundNBT nbt) { + return new AstralSorceryAmuletAttribute(nbt.getString("enchName"), nbt.getInt("enchType")); + } + + private ListNBT extractTraitList(ItemStack stack) { + return stack.getTag() != null ? stack.getTag().getCompound("astralsorcery").getList("amuletEnchantments", 10) : new ListNBT(); + } +} diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryAttunementAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryAttunementAttribute.java new file mode 100644 index 000000000..3a621969a --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryAttunementAttribute.java @@ -0,0 +1,76 @@ +package com.simibubi.create.content.logistics.item.filter.attribute.astralsorcery; + +import com.simibubi.create.content.logistics.item.filter.ItemAttribute; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.TranslationTextComponent; + +import java.util.ArrayList; +import java.util.List; + +public class AstralSorceryAttunementAttribute implements ItemAttribute { + String constellationName; + + public AstralSorceryAttunementAttribute(String constellationName) { + this.constellationName = constellationName; + } + + @Override + public boolean appliesTo(ItemStack itemStack) { + CompoundNBT nbt = extractAstralNBT(itemStack); + String constellation = nbt.contains("constellation") ? nbt.getString("constellation") : nbt.getString("constellationName"); + + // Special handling for shifting stars + ResourceLocation itemResource = itemStack.getItem().getRegistryName(); + if(itemResource != null && itemResource.toString().contains("shifting_star_")) { + constellation = itemResource.toString().replace("shifting_star_", ""); + } + + return constellation.equals(constellationName); + } + + @Override + public List listAttributesOf(ItemStack itemStack) { + CompoundNBT nbt = extractAstralNBT(itemStack); + String constellation = nbt.contains("constellation") ? nbt.getString("constellation") : nbt.getString("constellationName"); + + // Special handling for shifting stars + ResourceLocation itemResource = itemStack.getItem().getRegistryName(); + if(itemResource != null && itemResource.toString().contains("shifting_star_")) { + constellation = itemResource.toString().replace("shifting_star_", ""); + } + + List atts = new ArrayList<>(); + if(constellation.length() > 0) { + atts.add(new AstralSorceryAttunementAttribute(constellation)); + } + return atts; + } + + @Override + public String getTranslationKey() { + return "astralsorcery_constellation"; + } + + @Override + public Object[] getTranslationParameters() { + ResourceLocation constResource = new ResourceLocation(constellationName); + String something = new TranslationTextComponent(String.format("%s.constellation.%s", constResource.getNamespace(), constResource.getPath())).getString(); + return new Object[] { something }; + } + + @Override + public void writeNBT(CompoundNBT nbt) { + nbt.putString("constellation", this.constellationName); + } + + @Override + public ItemAttribute readNBT(CompoundNBT nbt) { + return new AstralSorceryAttunementAttribute(nbt.getString("constellation")); + } + + private CompoundNBT extractAstralNBT(ItemStack stack) { + return stack.getTag() != null ? stack.getTag().getCompound("astralsorcery") : new CompoundNBT(); + } +} diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryCrystalAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryCrystalAttribute.java new file mode 100644 index 000000000..0500eea82 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryCrystalAttribute.java @@ -0,0 +1,65 @@ +package com.simibubi.create.content.logistics.item.filter.attribute.astralsorcery; + +import com.simibubi.create.content.logistics.item.filter.ItemAttribute; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.INBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.TranslationTextComponent; + +import java.util.ArrayList; +import java.util.List; + +public class AstralSorceryCrystalAttribute implements ItemAttribute { + String traitName; + + public AstralSorceryCrystalAttribute(String traitName) { + this.traitName = traitName; + } + + @Override + public boolean appliesTo(ItemStack itemStack) { + for (INBT trait : extractTraitList(itemStack)) { + if(((CompoundNBT) trait).getString("property").equals(this.traitName)) + return true; + } + return false; + } + + @Override + public List listAttributesOf(ItemStack itemStack) { + ListNBT traits = extractTraitList(itemStack); + List atts = new ArrayList<>(); + for (int i = 0; i < traits.size(); i++) { + atts.add(new AstralSorceryCrystalAttribute(traits.getCompound(i).getString("property"))); + } + return atts; + } + + @Override + public String getTranslationKey() { + return "astralsorcery_crystal"; + } + + @Override + public Object[] getTranslationParameters() { + ResourceLocation traitResource = new ResourceLocation(traitName); + String something = new TranslationTextComponent(String.format("crystal.property.%s.%s.name", traitResource.getNamespace(), traitResource.getPath())).getString(); + return new Object[] { something }; + } + + @Override + public void writeNBT(CompoundNBT nbt) { + nbt.putString("property", this.traitName); + } + + @Override + public ItemAttribute readNBT(CompoundNBT nbt) { + return new AstralSorceryCrystalAttribute(nbt.getString("property")); + } + + private ListNBT extractTraitList(ItemStack stack) { + return stack.getTag() != null ? stack.getTag().getCompound("astralsorcery").getCompound("crystalProperties").getList("attributes", 10) : new ListNBT(); + } +} diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryPerkGemAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryPerkGemAttribute.java new file mode 100644 index 000000000..ab4671c1f --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/astralsorcery/AstralSorceryPerkGemAttribute.java @@ -0,0 +1,65 @@ +package com.simibubi.create.content.logistics.item.filter.attribute.astralsorcery; + +import com.simibubi.create.content.logistics.item.filter.ItemAttribute; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.INBT; +import net.minecraft.nbt.ListNBT; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.TranslationTextComponent; + +import java.util.ArrayList; +import java.util.List; + +public class AstralSorceryPerkGemAttribute implements ItemAttribute { + String traitName; + + public AstralSorceryPerkGemAttribute(String traitName) { + this.traitName = traitName; + } + + @Override + public boolean appliesTo(ItemStack itemStack) { + for (INBT trait : extractTraitList(itemStack)) { + if(((CompoundNBT) trait).getString("type").equals(this.traitName)) + return true; + } + return false; + } + + @Override + public List listAttributesOf(ItemStack itemStack) { + ListNBT traits = extractTraitList(itemStack); + List atts = new ArrayList<>(); + for (int i = 0; i < traits.size(); i++) { + atts.add(new AstralSorceryPerkGemAttribute(traits.getCompound(i).getString("type"))); + } + return atts; + } + + @Override + public String getTranslationKey() { + return "astralsorcery_perk_gem"; + } + + @Override + public Object[] getTranslationParameters() { + ResourceLocation traitResource = new ResourceLocation(traitName); + String something = new TranslationTextComponent(String.format("perk.attribute.%s.%s.name", traitResource.getNamespace(), traitResource.getPath())).getString(); + return new Object[] { something }; + } + + @Override + public void writeNBT(CompoundNBT nbt) { + nbt.putString("type", this.traitName); + } + + @Override + public ItemAttribute readNBT(CompoundNBT nbt) { + return new AstralSorceryPerkGemAttribute(nbt.getString("type")); + } + + private ListNBT extractTraitList(ItemStack stack) { + return stack.getTag() != null ? stack.getTag().getCompound("astralsorcery").getList("attribute_modifiers", 10) : new ListNBT(); + } +} From 42ef3796a27879218a8031f8a5938c2fc6a24576 Mon Sep 17 00:00:00 2001 From: Colman Davenport Date: Sat, 17 Oct 2020 11:23:38 -0400 Subject: [PATCH 7/8] Refactor EnchantAttribute --- .../logistics/item/filter/ItemAttribute.java | 2 +- .../filter/attribute/EnchantAttribute.java | 51 ++++++++----------- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java index 8c369cbc7..de66e9d59 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java @@ -49,7 +49,7 @@ public interface ItemAttribute { static ItemAttribute standard = register(StandardTraits.DUMMY); static ItemAttribute inTag = register(new InTag(new ResourceLocation("dummy"))); static ItemAttribute inItemGroup = register(new InItemGroup(ItemGroup.MISC)); - static ItemAttribute hasEnchant = register(new EnchantAttribute("dummy")); + static ItemAttribute hasEnchant = register(EnchantAttribute.EMPTY); static ItemAttribute hasFluid = register(new FluidContentsAttribute("dummy")); static ItemAttribute hasName = register(new ItemNameAttribute("dummy")); static ItemAttribute astralAmulet = register(new AstralSorceryAmuletAttribute("dummy", -1)); diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/EnchantAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/EnchantAttribute.java index a30548862..26d4586f8 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/EnchantAttribute.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/EnchantAttribute.java @@ -2,41 +2,34 @@ package com.simibubi.create.content.logistics.item.filter.attribute; import com.simibubi.create.content.logistics.item.filter.ItemAttribute; import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.ListNBT; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.registries.ForgeRegistries; -import java.util.ArrayList; +import javax.annotation.Nullable; import java.util.List; +import java.util.stream.Collectors; public class EnchantAttribute implements ItemAttribute { - String enchantName; + public static final EnchantAttribute EMPTY = new EnchantAttribute(null); - public EnchantAttribute(String enchantName) { - this.enchantName = enchantName; + private final Enchantment enchantment; + + public EnchantAttribute(@Nullable Enchantment enchantment) { + this.enchantment = enchantment; } @Override public boolean appliesTo(ItemStack itemStack) { - ListNBT enchants = extractEnchants(itemStack); - for (int i = 0; i < enchants.size(); i++) { - if(enchants.getCompound(i).getString("id").equals(this.enchantName)) - return true; - } - return false; + return EnchantmentHelper.getEnchantments(itemStack).containsKey(enchantment); } @Override public List listAttributesOf(ItemStack itemStack) { - ListNBT enchants = extractEnchants(itemStack); - List atts = new ArrayList<>(); - for (int i = 0; i < enchants.size(); i++) { - atts.add(new EnchantAttribute(enchants.getCompound(i).getString("id"))); - } - return atts; + return EnchantmentHelper.getEnchantments(itemStack).keySet().stream().map(EnchantAttribute::new).collect(Collectors.toList()); } @Override @@ -46,26 +39,24 @@ public class EnchantAttribute implements ItemAttribute { @Override public Object[] getTranslationParameters() { - String something = ""; - Enchantment enchant = ForgeRegistries.ENCHANTMENTS.getValue(ResourceLocation.tryCreate(enchantName)); - if(enchant != null) { - something = new TranslationTextComponent(enchant.getName()).getString(); - } - return new Object[] { something }; + String parameter = ""; + if(enchantment != null) + parameter = new TranslationTextComponent(enchantment.getName()).getString(); + return new Object[] { parameter }; } @Override public void writeNBT(CompoundNBT nbt) { - nbt.putString("id", this.enchantName); + if (enchantment == null) + return; + ResourceLocation id = ForgeRegistries.ENCHANTMENTS.getKey(enchantment); + if (id == null) + return; + nbt.putString("id", id.toString()); } @Override public ItemAttribute readNBT(CompoundNBT nbt) { - return new EnchantAttribute(nbt.getString("id")); - } - - private ListNBT extractEnchants(ItemStack stack) { - CompoundNBT tag = stack.getTag() != null ? stack.getTag() : new CompoundNBT(); - return tag.contains("Enchantments") ? stack.getEnchantmentTagList() : tag.getList("StoredEnchantments", 10); + return nbt.contains("id") ? new EnchantAttribute(ForgeRegistries.ENCHANTMENTS.getValue(ResourceLocation.tryCreate(nbt.getString("id")))) : EMPTY; } } From 083a9c1140da263c2c7496a9c5db3b2b77b1b97c Mon Sep 17 00:00:00 2001 From: Colman Davenport Date: Sat, 17 Oct 2020 11:24:15 -0400 Subject: [PATCH 8/8] Refactor FluidContentsAttribute --- .../logistics/item/filter/ItemAttribute.java | 2 +- .../attribute/FluidContentsAttribute.java | 47 +++++++++---------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java index de66e9d59..a07a82ca2 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/ItemAttribute.java @@ -50,7 +50,7 @@ public interface ItemAttribute { static ItemAttribute inTag = register(new InTag(new ResourceLocation("dummy"))); static ItemAttribute inItemGroup = register(new InItemGroup(ItemGroup.MISC)); static ItemAttribute hasEnchant = register(EnchantAttribute.EMPTY); - static ItemAttribute hasFluid = register(new FluidContentsAttribute("dummy")); + static ItemAttribute hasFluid = register(FluidContentsAttribute.EMPTY); static ItemAttribute hasName = register(new ItemNameAttribute("dummy")); static ItemAttribute astralAmulet = register(new AstralSorceryAmuletAttribute("dummy", -1)); static ItemAttribute astralAttunement = register(new AstralSorceryAttunementAttribute("dummy")); diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/FluidContentsAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/FluidContentsAttribute.java index 421282b9b..94aa9ed1f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/FluidContentsAttribute.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/FluidContentsAttribute.java @@ -2,12 +2,8 @@ package com.simibubi.create.content.logistics.item.filter.attribute; import com.simibubi.create.content.logistics.item.filter.ItemAttribute; import net.minecraft.fluid.Fluid; -import net.minecraft.item.BucketItem; -import net.minecraft.item.GlassBottleItem; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.ListNBT; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.common.util.LazyOptional; @@ -15,30 +11,28 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandlerItem; import net.minecraftforge.registries.ForgeRegistries; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; public class FluidContentsAttribute implements ItemAttribute { - String fluidName; + public static final FluidContentsAttribute EMPTY = new FluidContentsAttribute(null); - public FluidContentsAttribute(String fluidName) { - this.fluidName = fluidName; + private final Fluid fluid; + + public FluidContentsAttribute(@Nullable Fluid fluid) { + this.fluid = fluid; } @Override public boolean appliesTo(ItemStack itemStack) { - return extractFluidNames(itemStack).contains(fluidName); + return extractFluids(itemStack).contains(fluid); } @Override public List listAttributesOf(ItemStack itemStack) { - List names = extractFluidNames(itemStack); - - List atts = new ArrayList<>(); - for(String name : names) { - atts.add(new FluidContentsAttribute(name)); - } - return atts; + return extractFluids(itemStack).stream().map(FluidContentsAttribute::new).collect(Collectors.toList()); } @Override @@ -48,33 +42,36 @@ public class FluidContentsAttribute implements ItemAttribute { @Override public Object[] getTranslationParameters() { - ResourceLocation fluidResource = new ResourceLocation(fluidName); - Fluid fluid = ForgeRegistries.FLUIDS.getValue(fluidResource); - String trans = ""; + String parameter = ""; if(fluid != null) - trans = new TranslationTextComponent(fluid.getAttributes().getTranslationKey()).getString(); - return new Object[] {trans}; + parameter = new TranslationTextComponent(fluid.getAttributes().getTranslationKey()).getString(); + return new Object[] { parameter }; } @Override public void writeNBT(CompoundNBT nbt) { - nbt.putString("fluidName", this.fluidName); + if (fluid == null) + return; + ResourceLocation id = ForgeRegistries.FLUIDS.getKey(fluid); + if (id == null) + return; + nbt.putString("id", id.toString()); } @Override public ItemAttribute readNBT(CompoundNBT nbt) { - return new FluidContentsAttribute(nbt.getString("fluidName")); + return nbt.contains("id") ? new FluidContentsAttribute(ForgeRegistries.FLUIDS.getValue(ResourceLocation.tryCreate(nbt.getString("id")))) : EMPTY; } - private List extractFluidNames(ItemStack stack) { - List fluids = new ArrayList<>(); + private List extractFluids(ItemStack stack) { + List fluids = new ArrayList<>(); LazyOptional capability = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY); capability.ifPresent((cap) -> { for(int i = 0; i < cap.getTanks(); i++) { - fluids.add(cap.getFluidInTank(i).getFluid().getRegistryName().toString()); + fluids.add(cap.getFluidInTank(i).getFluid()); } });