Fixed serialization of delegate spell types

This commit is contained in:
Sollace 2021-11-22 00:48:22 +02:00
parent 7d830a3474
commit 9bb2818c2c
3 changed files with 18 additions and 4 deletions

View file

@ -38,9 +38,8 @@ public class CompoundSpell extends AbstractDelegatingSpell {
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound) {
super.toNBT(compound); super.toNBT(compound);
NbtList spells = new NbtList(); NbtList spells = new NbtList();
this.spells.forEach(spell -> { this.spells.stream().map(SpellType::toNBT).forEach(spells::add);
spells.add(spell.toNBT()); compound.put("spells", spells);
});
} }
@Override @Override

View file

@ -100,17 +100,19 @@ public class PlaceableSpell extends AbstractDelegatingSpell {
compound.putString("dimension", dimension.toString()); compound.putString("dimension", dimension.toString());
} }
compound.put("castEntity", castEntity.toNBT()); compound.put("castEntity", castEntity.toNBT());
compound.put("spell", SpellType.toNBT(spell));
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound) {
super.toNBT(); super.fromNBT(compound);
if (compound.contains("dimension")) { if (compound.contains("dimension")) {
dimension = new Identifier(compound.getString("dimension")); dimension = new Identifier(compound.getString("dimension"));
} }
if (compound.contains("castEntity")) { if (compound.contains("castEntity")) {
castEntity.fromNBT(compound.getCompound("castEntity")); castEntity.fromNBT(compound.getCompound("castEntity"));
} }
spell = SpellType.fromNBT(compound.getCompound("spell"));
} }
@Override @Override

View file

@ -12,6 +12,7 @@ import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity; import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -62,6 +63,18 @@ public class ThrowableSpell extends AbstractDelegatingSpell {
return Optional.empty(); return Optional.empty();
} }
@Override
public void toNBT(NbtCompound compound) {
super.toNBT(compound);
compound.put("spell", SpellType.toNBT(spell));
}
@Override
public void fromNBT(NbtCompound compound) {
super.fromNBT(compound);
spell = SpellType.fromNBT(compound.getCompound("spell"));
}
@Override @Override
public ThrowableSpell toThrowable() { public ThrowableSpell toThrowable() {
return this; return this;