From 54c0acb75737e8f440b2dc1569d20abc7cd2da14 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 6 Aug 2023 18:29:33 +0100 Subject: [PATCH] Use an entity reference to remember the owner of a magic projectile, and store the level and corruption in the reference so we can remember it when the player is offline --- .../projectile/MagicProjectileEntity.java | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java b/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java index dc5c9401..4947fc80 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java @@ -7,7 +7,7 @@ import java.util.function.Function; import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.Affinity; -import com.minelittlepony.unicopia.Owned; +import com.minelittlepony.unicopia.WeaklyOwned; import com.minelittlepony.unicopia.ability.magic.Affine; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Levelled; @@ -53,7 +53,7 @@ import net.minecraft.world.World; * * Can also carry a spell if needed. */ -public class MagicProjectileEntity extends ThrownItemEntity implements Caster, Owned.Mutable { +public class MagicProjectileEntity extends ThrownItemEntity implements Caster, WeaklyOwned.Mutable { private static final TrackedData DAMAGE = DataTracker.registerData(MagicProjectileEntity.class, TrackedDataHandlerRegistry.FLOAT); private static final TrackedData GRAVITY = DataTracker.registerData(MagicProjectileEntity.class, TrackedDataHandlerRegistry.FLOAT); private static final TrackedData HYDROPHOBIC = DataTracker.registerData(MagicProjectileEntity.class, TrackedDataHandlerRegistry.BOOLEAN); @@ -66,6 +66,7 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Caster physics = new EntityPhysics<>(this, GRAVITY, false); private final EntityReference homingTarget = new EntityReference<>(); + private final EntityReference owner = new EntityReference<>(); public MagicProjectileEntity(EntityType type, World world) { super(type, world); @@ -107,10 +108,24 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Caster getMasterReference() { + return owner; } public void setHomingTarget(@Nullable Entity target) { @@ -119,12 +134,12 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Caster target.level()).orElse(Levelled.EMPTY); } @Override public LevelStore getCorruption() { - return Caster.of(getMaster()).map(Caster::getCorruption).orElse(Levelled.EMPTY); + return getMasterReference().getTarget().map(target -> target.corruption()).orElse(Levelled.EMPTY); } @Override @@ -169,7 +184,7 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Caster 90) { discard(); } @@ -238,6 +253,7 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Caster { compound.put("effect", Spell.writeNbt(effect)); });