From e386e040eaa1e8df38b3b45c7b108e449d4d84a4 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 6 Mar 2021 12:26:54 +0200 Subject: [PATCH] Fixed mana cost for cast spells not being passed on to the player --- .../minelittlepony/unicopia/ability/magic/Caster.java | 9 ++++----- .../minelittlepony/unicopia/entity/CastSpellEntity.java | 5 +++++ .../com/minelittlepony/unicopia/entity/Creature.java | 7 +++++++ .../unicopia/projectile/MagicProjectileEntity.java | 7 ++++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java index 23f91c12..a136fd5b 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java @@ -15,7 +15,6 @@ import com.minelittlepony.unicopia.util.VecHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.damage.DamageSource; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -63,10 +62,10 @@ public interface Caster extends Owned, Levelled, Affi return getEntity().getBlockPos(); } - default boolean subtractEnergyCost(double amount) { - getMaster().damage(DamageSource.MAGIC, (int)amount/2); - return getMaster().getHealth() > 0; - } + /** + * Removes the desired amount of mana or health from this caster in exchange for a spell's benefits. + */ + boolean subtractEnergyCost(double amount); default Stream> findAllSpellsInRange(double radius) { return findAllSpellsInRange(radius, null); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java index 244d2c97..4db5d4b5 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java @@ -145,6 +145,11 @@ public class CastSpellEntity extends Entity implements Caster { return Caster.of(getMaster()).map(Caster::getSpellSlot).orElse(SpellContainer.EMPTY); } + @Override + public boolean subtractEnergyCost(double amount) { + return Caster.of(getMaster()).filter(c -> c.subtractEnergyCost(amount)).isPresent(); + } + @Override protected void writeCustomDataToTag(CompoundTag tag) { tag.put("owner", owner.toNBT()); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Creature.java b/src/main/java/com/minelittlepony/unicopia/entity/Creature.java index 74b4f569..c664cb33 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Creature.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Creature.java @@ -15,6 +15,7 @@ import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.ai.goal.GoalSelector; import net.minecraft.entity.attribute.DefaultAttributeContainer; import net.minecraft.entity.attribute.EntityAttributes; +import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; @@ -78,6 +79,12 @@ public class Creature extends Living { return LEVELS; } + @Override + public boolean subtractEnergyCost(double amount) { + getMaster().damage(DamageSource.MAGIC, (int)amount/2); + return getMaster().getHealth() > 0; + } + @Override public Affinity getAffinity() { if (getMaster() instanceof Affine) { diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java b/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java index 74e22a46..9b46ddd1 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java @@ -84,7 +84,7 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Magical, case BAD: return Items.MAGMA_CREAM; default: return Items.AIR; } - } + } @Override public Entity getEntity() { @@ -121,6 +121,11 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Magical, return effectDelegate; } + @Override + public boolean subtractEnergyCost(double amount) { + return Caster.of(getMaster()).filter(c -> c.subtractEnergyCost(amount)).isPresent(); + } + public void setThrowDamage(float damage) { getDataTracker().set(DAMAGE, Math.max(0, damage)); }