mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-03-04 06:44:40 +01:00
Conflicting thoughts
- Fix certain attributes overriding the type id
This commit is contained in:
parent
7e0d504897
commit
a592e22df3
6 changed files with 27 additions and 17 deletions
|
@ -25,7 +25,7 @@ public interface ItemAttribute {
|
|||
if (id == null)
|
||||
throw new IllegalArgumentException("Cannot get " + attribute.getType() + "as it does not exist in AllRegistries.ITEM_ATTRIBUTE_TYPES");
|
||||
|
||||
nbt.putString("id", id.toString());
|
||||
nbt.putString("attributeId", id.toString());
|
||||
attribute.save(nbt);
|
||||
return nbt;
|
||||
}
|
||||
|
|
|
@ -48,12 +48,12 @@ public class AddedByAttribute implements ItemAttribute {
|
|||
|
||||
@Override
|
||||
public void save(CompoundTag nbt) {
|
||||
nbt.putString("id", modId);
|
||||
nbt.putString("modId", modId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag nbt) {
|
||||
modId = nbt.getString("id");
|
||||
modId = nbt.getString("modId");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -85,13 +85,13 @@ public class ColorAttribute implements ItemAttribute {
|
|||
|
||||
@Override
|
||||
public void save(CompoundTag nbt) {
|
||||
nbt.putInt("id", color.getId());
|
||||
nbt.putInt("color", color.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag nbt) {
|
||||
if (nbt.contains("id")) {
|
||||
color = DyeColor.byId(nbt.getInt("id"));
|
||||
if (nbt.contains("color")) {
|
||||
color = DyeColor.byId(nbt.getInt("color"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -72,13 +72,13 @@ public class FluidContentsAttribute implements ItemAttribute {
|
|||
ResourceLocation id = ForgeRegistries.FLUIDS.getKey(fluid);
|
||||
if (id == null)
|
||||
return;
|
||||
nbt.putString("id", id.toString());
|
||||
nbt.putString("fluidId", id.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag nbt) {
|
||||
if (nbt.contains("id")) {
|
||||
fluid = ForgeRegistries.FLUIDS.getValue(ResourceLocation.tryParse(nbt.getString("id")));
|
||||
if (nbt.contains("fluidId")) {
|
||||
fluid = ForgeRegistries.FLUIDS.getValue(ResourceLocation.tryParse(nbt.getString("fluidId")));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,17 +55,17 @@ public class ShulkerFillLevelAttribute implements ItemAttribute {
|
|||
@Override
|
||||
public void save(CompoundTag nbt) {
|
||||
if (levels != null)
|
||||
nbt.putString("id", levels.key);
|
||||
nbt.putString("level", levels.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag nbt) {
|
||||
if (nbt.contains("id")) {
|
||||
levels = ShulkerLevels.fromKey(nbt.getString("id"));
|
||||
if (nbt.contains("level")) {
|
||||
levels = ShulkerLevels.fromKey(nbt.getString("level"));
|
||||
}
|
||||
}
|
||||
|
||||
enum ShulkerLevels {
|
||||
public enum ShulkerLevels {
|
||||
EMPTY("empty", amount -> amount == 0),
|
||||
PARTIAL("partial", amount -> amount > 0 && amount < Integer.MAX_VALUE),
|
||||
FULL("full", amount -> amount == Integer.MAX_VALUE);
|
||||
|
|
|
@ -8,13 +8,19 @@ 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.AddedByAttribute;
|
||||
import com.simibubi.create.content.logistics.item.filter.attribute.attributes.ColorAttribute;
|
||||
import com.simibubi.create.content.logistics.item.filter.attribute.attributes.EnchantAttribute;
|
||||
import com.simibubi.create.content.logistics.item.filter.attribute.attributes.FluidContentsAttribute;
|
||||
import com.simibubi.create.content.logistics.item.filter.attribute.attributes.InTagAttribute;
|
||||
import com.simibubi.create.content.logistics.item.filter.attribute.attributes.ShulkerFillLevelAttribute;
|
||||
import com.simibubi.create.content.logistics.item.filter.attribute.attributes.ShulkerFillLevelAttribute.ShulkerLevels;
|
||||
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class AllItemAttributeLegacyDeserializers {
|
||||
|
@ -28,12 +34,16 @@ public class AllItemAttributeLegacyDeserializers {
|
|||
)))
|
||||
);
|
||||
createLegacyDeserializer("in_item_group", AllItemAttributeTypes.IN_ITEM_GROUP);
|
||||
createLegacyDeserializer("added_by", AllItemAttributeTypes.ADDED_BY);
|
||||
createLegacyDeserializer("added_by", tag ->
|
||||
new AddedByAttribute(tag.getString("id")));
|
||||
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);
|
||||
createLegacyDeserializer("shulker_fill_level", tag ->
|
||||
new ShulkerFillLevelAttribute(ShulkerLevels.fromKey(tag.getString("id"))));
|
||||
createLegacyDeserializer("has_color", tag ->
|
||||
new ColorAttribute(DyeColor.byId(tag.getInt("id"))));
|
||||
createLegacyDeserializer("has_fluid", tag ->
|
||||
new FluidContentsAttribute(BuiltInRegistries.FLUID.get(ResourceLocation.tryParse(tag.getString("id")))));
|
||||
createLegacyDeserializer("has_name", AllItemAttributeTypes.HAS_NAME);
|
||||
createLegacyDeserializer("book_author", AllItemAttributeTypes.BOOK_AUTHOR);
|
||||
createLegacyDeserializer("book_copy", AllItemAttributeTypes.BOOK_COPY);
|
||||
|
|
Loading…
Add table
Reference in a new issue