Skip to content

Commit

Permalink
All: Update to 1.19.2 and fix the multiple power.
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinMindcraft committed Aug 17, 2022
1 parent 0883946 commit 7604dce
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,38 +181,7 @@ public final class SerializableDataTypes {

public static final SerializableDataType<Enchantment> ENCHANTMENT = SerializableDataType.registry(Enchantment.class, ForgeRegistries.ENCHANTMENTS);

public static final SerializableDataType<DamageSource> 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<DamageSource> DAMAGE_SOURCE = new SerializableDataType<>(DamageSource.class, CalioCodecHelper.DAMAGE_SOURCE_CODEC);

public static final SerializableDataType<Attribute> ATTRIBUTE = SerializableDataType.registry(Attribute.class, ForgeRegistries.ATTRIBUTES);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -291,6 +292,27 @@ public static boolean isDataContext(DynamicOps<?> ops) {
return ops instanceof JsonOps && !ops.compressMaps();
}

public static final Codec<DamageSource> 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<T> implements JsonSerializer<T>, JsonDeserializer<T> {

private final Codec<T> codec;
Expand Down

0 comments on commit 7604dce

Please sign in to comment.