From 7604dceae2782033440dc86c14810108f7d9a396 Mon Sep 17 00:00:00 2001 From: EdwinMindcraft Date: Wed, 17 Aug 2022 15:00:05 +0200 Subject: [PATCH] All: Update to 1.19.2 and fix the `multiple` power. --- .../calio/data/SerializableDataTypes.java | 33 +------------------ .../calio/api/network/CalioCodecHelper.java | 22 +++++++++++++ 2 files changed, 23 insertions(+), 32 deletions(-) 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 3b6c0fe..1c7e76e 100644 --- a/src/main/java/io/github/apace100/calio/data/SerializableDataTypes.java +++ b/src/main/java/io/github/apace100/calio/data/SerializableDataTypes.java @@ -181,38 +181,7 @@ public final class SerializableDataTypes { public static final SerializableDataType ENCHANTMENT = SerializableDataType.registry(Enchantment.class, ForgeRegistries.ENCHANTMENTS); - public static final SerializableDataType DAMAGE_SOURCE = SerializableDataType.compound(DamageSource.class, new SerializableData() - .add("name", STRING) - .add("bypasses_armor", BOOLEAN, false) - .add("fire", BOOLEAN, false) - .add("unblockable", BOOLEAN, false) - .add("magic", BOOLEAN, false) - .add("out_of_world", BOOLEAN, false) - .add("projectile", BOOLEAN, false) - .add("explosive", BOOLEAN, false), - (data) -> { - DamageSource damageSource = new DamageSource(data.getString("name")); - if (data.getBoolean("bypasses_armor")) damageSource.bypassArmor(); - if (data.getBoolean("fire")) damageSource.setIsFire(); - if (data.getBoolean("unblockable")) damageSource.bypassMagic(); - if (data.getBoolean("magic")) damageSource.setMagic(); - if (data.getBoolean("out_of_world")) damageSource.bypassInvul(); - if (data.getBoolean("projectile")) damageSource.setProjectile(); - if (data.getBoolean("explosive")) damageSource.setExplosion(); - return damageSource; - }, - (data, ds) -> { - SerializableData.Instance inst = data.new Instance(); - inst.set("name", ds.getMsgId()); - inst.set("fire", ds.isFire()); - inst.set("unblockable", ds.isBypassMagic()); - inst.set("bypasses_armor", ds.isBypassArmor()); - inst.set("out_of_world", ds.isBypassInvul()); - inst.set("magic", ds.isMagic()); - inst.set("projectile", ds.isProjectile()); - inst.set("explosive", ds.isExplosion()); - return inst; - }); + public static final SerializableDataType DAMAGE_SOURCE = new SerializableDataType<>(DamageSource.class, CalioCodecHelper.DAMAGE_SOURCE_CODEC); public static final SerializableDataType ATTRIBUTE = SerializableDataType.registry(Attribute.class, ForgeRegistries.ATTRIBUTES); diff --git a/src/main/java/io/github/edwinmindcraft/calio/api/network/CalioCodecHelper.java b/src/main/java/io/github/edwinmindcraft/calio/api/network/CalioCodecHelper.java index cfbf6e9..534a794 100644 --- a/src/main/java/io/github/edwinmindcraft/calio/api/network/CalioCodecHelper.java +++ b/src/main/java/io/github/edwinmindcraft/calio/api/network/CalioCodecHelper.java @@ -19,6 +19,7 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; +import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.phys.Vec3; import net.minecraftforge.registries.IForgeRegistry; import org.apache.commons.lang3.Validate; @@ -291,6 +292,27 @@ public static boolean isDataContext(DynamicOps ops) { return ops instanceof JsonOps && !ops.compressMaps(); } + public static final Codec DAMAGE_SOURCE_CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.STRING.fieldOf("name").forGetter(DamageSource::getMsgId), + optionalField(BOOL, "bypasses_armor", false).forGetter(DamageSource::isBypassArmor), + optionalField(BOOL, "fire", false).forGetter(DamageSource::isFire), + optionalField(BOOL, "unblockable", false).forGetter(DamageSource::isBypassMagic), + optionalField(BOOL, "magic", false).forGetter(DamageSource::isMagic), + optionalField(BOOL, "out_of_world", false).forGetter(DamageSource::isBypassInvul), + optionalField(BOOL, "projectile", false).forGetter(DamageSource::isProjectile), + optionalField(BOOL, "explosive", false).forGetter(DamageSource::isExplosion) + ).apply(instance, (name, bypassArmor, fire, bypassMagic, magic, bypassInvul, projectile, explosion) -> { + DamageSource ds = new DamageSource(name); + if (bypassArmor) ds.bypassArmor(); + if (fire) ds.setIsFire(); + if (bypassMagic) ds.bypassMagic(); + if (magic) ds.setMagic(); + if (bypassInvul) ds.bypassInvul(); + if (projectile) ds.setProjectile(); + if (explosion) ds.setExplosion(); + return ds; + })); + public static class CodecJsonAdapter implements JsonSerializer, JsonDeserializer { private final Codec codec;