mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 23:47:38 +01:00
Astral Sorcery Attributes
This commit is contained in:
parent
822ca6dad6
commit
6d51a6c730
6 changed files with 303 additions and 1 deletions
|
@ -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:",
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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<ItemAttribute> listAttributesOf(ItemStack itemStack) {
|
||||
ListNBT traits = extractTraitList(itemStack);
|
||||
List<ItemAttribute> 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();
|
||||
}
|
||||
}
|
|
@ -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<ItemAttribute> 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<ItemAttribute> 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();
|
||||
}
|
||||
}
|
|
@ -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<ItemAttribute> listAttributesOf(ItemStack itemStack) {
|
||||
ListNBT traits = extractTraitList(itemStack);
|
||||
List<ItemAttribute> 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();
|
||||
}
|
||||
}
|
|
@ -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<ItemAttribute> listAttributesOf(ItemStack itemStack) {
|
||||
ListNBT traits = extractTraitList(itemStack);
|
||||
List<ItemAttribute> 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();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue