From 6d51a6c7305723e690e45d9c9cca703d7e2f481b Mon Sep 17 00:00:00 2001 From: Colman Davenport Date: Sat, 17 Oct 2020 01:25:29 -0400 Subject: [PATCH] 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(); + } +}