Bugs in the filters 🐛

- Fix crash when using enchant attribute
- Fix gametest
- Add nullcheck before inserting attributes
This commit is contained in:
IThundxr 2025-01-04 22:52:29 -05:00
parent 669435e849
commit 3a9f7d591c
Failed to generate hash of commit
6 changed files with 15 additions and 9 deletions

View file

@ -137,7 +137,9 @@ public class AttributeFilterMenu extends AbstractFilterMenu {
.getList("MatchedAttributes", Tag.TAG_COMPOUND);
attributes.forEach(inbt -> {
CompoundTag compound = (CompoundTag) inbt;
selectedAttributes.add(Pair.of(ItemAttribute.loadStatic(compound), compound.getBoolean("Inverted")));
ItemAttribute attribute = ItemAttribute.loadStatic(compound);
if (attribute != null)
selectedAttributes.add(Pair.of(attribute, compound.getBoolean("Inverted")));
});
}

View file

@ -71,7 +71,7 @@ public class AllItemAttributeTypes {
BLASTABLE = singleton("blastable", (s, w) -> testRecipe(s, w, RecipeType.BLASTING)),
COMPOSTABLE = singleton("compostable", s -> ComposterBlock.COMPOSTABLES.containsKey(s.getItem())),
IN_TAG = register("in_tag", new InTagAttribute.Type()),
IN_TAG = register("in_tag", new InTagAttribute.Type()),
IN_ITEM_GROUP = register("in_item_group", new InItemGroupAttribute.Type()),
ADDED_BY = register("added_by", new AddedByAttribute.Type()),
HAS_ENCHANT = register("has_enchant", new EnchantAttribute.Type()),
@ -82,7 +82,7 @@ public class AllItemAttributeTypes {
BOOK_AUTHOR = register("book_author", new BookAuthorAttribute.Type()),
BOOK_COPY = register("book_copy", new BookCopyAttribute.Type()),
ASTRAL_AMULET = register("astral_amulet", new AstralSorceryAmuletAttribute.Type()),
ASTRAL_AMULET = register("astral_amulet", new AstralSorceryAmuletAttribute.Type()),
ASTRAL_ATTUNMENT = register("astral_attunment", new AstralSorceryAttunementAttribute.Type()),
ASTRAL_CRYSTAL = register("astral_crystal", new AstralSorceryCrystalAttribute.Type()),
ASTRAL_PERK_GEM = register("astral_perk_gem", new AstralSorceryPerkGemAttribute.Type());

View file

@ -39,9 +39,9 @@ public interface ItemAttribute {
}
ResourceLocation id = ResourceLocation.tryParse(nbt.getString("id"));
if (id == null) {
if (id == null)
return null;
}
ItemAttributeType type = AllRegistries.ITEM_ATTRIBUTE_TYPES.get().getValue(id);
if (type == null) {
return null;

View file

@ -3,6 +3,7 @@ package com.simibubi.create.content.logistics.item.filter.attribute.attributes;
import java.util.ArrayList;
import java.util.List;
import net.createmod.catnip.utility.NBTHelper;
import net.createmod.catnip.utility.lang.Components;
import org.jetbrains.annotations.NotNull;
@ -57,13 +58,13 @@ public class EnchantAttribute implements ItemAttribute {
ResourceLocation id = ForgeRegistries.ENCHANTMENTS.getKey(enchantment);
if (id == null)
return;
nbt.putString("id", id.toString());
NBTHelper.writeResourceLocation(nbt, "enchantId", id);
}
@Override
public void load(CompoundTag nbt) {
if (nbt.contains("id")) {
enchantment = ForgeRegistries.ENCHANTMENTS.getValue(ResourceLocation.tryParse(nbt.getString("id")));
if (nbt.contains("enchantId")) {
enchantment = ForgeRegistries.ENCHANTMENTS.getValue(NBTHelper.readResourceLocation(nbt, "enchantId"));
}
}

View file

@ -8,8 +8,10 @@ import org.jetbrains.annotations.ApiStatus;
import com.simibubi.create.content.logistics.item.filter.attribute.AllItemAttributeTypes;
import com.simibubi.create.content.logistics.item.filter.attribute.ItemAttribute;
import com.simibubi.create.content.logistics.item.filter.attribute.ItemAttributeType;
import com.simibubi.create.content.logistics.item.filter.attribute.attributes.EnchantAttribute;
import com.simibubi.create.content.logistics.item.filter.attribute.attributes.InTagAttribute;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
@ -27,7 +29,8 @@ public class AllItemAttributeLegacyDeserializers {
);
createLegacyDeserializer("in_item_group", AllItemAttributeTypes.IN_ITEM_GROUP);
createLegacyDeserializer("added_by", AllItemAttributeTypes.ADDED_BY);
createLegacyDeserializer("has_enchant", AllItemAttributeTypes.HAS_ENCHANT);
createLegacyDeserializer("has_enchant", tag ->
new EnchantAttribute(BuiltInRegistries.ENCHANTMENT.get(ResourceLocation.tryParse(tag.getString("id")))));
createLegacyDeserializer("shulker_fill_level", AllItemAttributeTypes.SHULKER_FILL_LEVEL);
createLegacyDeserializer("has_color", AllItemAttributeTypes.HAS_COLOR);
createLegacyDeserializer("has_fluid", AllItemAttributeTypes.HAS_FLUID);