diff --git a/src/main/java/io/github/apace100/calio/data/SerializableData.java b/src/main/java/io/github/apace100/calio/data/SerializableData.java index 5818a1f..6ea6445 100644 --- a/src/main/java/io/github/apace100/calio/data/SerializableData.java +++ b/src/main/java/io/github/apace100/calio/data/SerializableData.java @@ -203,7 +203,7 @@ public boolean isPresent(String name) { return this.get(name) != null; } } - return true; + return data.containsKey(name); } public void ifPresent(String name, Consumer consumer) { diff --git a/src/main/java/io/github/apace100/calio/data/SerializableDataTypes.java b/src/main/java/io/github/apace100/calio/data/SerializableDataTypes.java index 1c7e76e..260e450 100644 --- a/src/main/java/io/github/apace100/calio/data/SerializableDataTypes.java +++ b/src/main/java/io/github/apace100/calio/data/SerializableDataTypes.java @@ -31,6 +31,8 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; +import net.minecraft.stats.Stat; +import net.minecraft.stats.StatType; import net.minecraft.tags.TagKey; import net.minecraft.util.GsonHelper; import net.minecraft.world.InteractionHand; @@ -54,6 +56,7 @@ import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; +import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.gameevent.GameEvent; @@ -578,5 +581,28 @@ public final class SerializableDataTypes { public static final SerializableDataType RAYCAST_FLUID_HANDLING = SerializableDataType.enumValue(ClipContext.Fluid.class); - public static final SerializableDataType EXPLOSION_DESTRUCTION_TYPE = SerializableDataType.enumValue(Explosion.BlockInteraction.class); + public static final SerializableDataType> STAT = SerializableDataType.compound(ClassUtil.castClass(Stat.class), + new SerializableData() + .add("type", SerializableDataType.registry(ClassUtil.castClass(StatType.class), ForgeRegistries.STAT_TYPES)) + .add("id", SerializableDataTypes.IDENTIFIER), + data -> { + StatType statType = data.get("type"); + Registry statRegistry = statType.getRegistry(); + ResourceLocation statId = data.get("id"); + if(statRegistry.containsKey(statId)) { + Object statObject = statRegistry.get(statId); + return statType.get(statObject); + } + throw new IllegalArgumentException("Desired stat \"" + statId + "\" does not exist in stat type "); + }, + (data, stat) -> { + SerializableData.Instance inst = data.new Instance(); + inst.set("type", stat.getType()); + Registry reg = stat.getType().getRegistry(); + ResourceLocation statId = reg.getKey(stat.getValue()); + inst.set("id", statId); + return inst; + }); + + public static final SerializableDataType> BIOME_TAG = SerializableDataType.tag(Registry.BIOME_REGISTRY); }