Fixed mana cost for cast spells not being passed on to the player

This commit is contained in:
Sollace 2021-03-06 12:26:54 +02:00
parent c188b9c7cb
commit e386e040ea
4 changed files with 22 additions and 6 deletions

View file

@ -15,7 +15,6 @@ import com.minelittlepony.unicopia.util.VecHelper;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -63,10 +62,10 @@ public interface Caster<E extends LivingEntity> extends Owned<E>, Levelled, Affi
return getEntity().getBlockPos(); return getEntity().getBlockPos();
} }
default boolean subtractEnergyCost(double amount) { /**
getMaster().damage(DamageSource.MAGIC, (int)amount/2); * Removes the desired amount of mana or health from this caster in exchange for a spell's benefits.
return getMaster().getHealth() > 0; */
} boolean subtractEnergyCost(double amount);
default Stream<Caster<?>> findAllSpellsInRange(double radius) { default Stream<Caster<?>> findAllSpellsInRange(double radius) {
return findAllSpellsInRange(radius, null); return findAllSpellsInRange(radius, null);

View file

@ -145,6 +145,11 @@ public class CastSpellEntity extends Entity implements Caster<LivingEntity> {
return Caster.of(getMaster()).map(Caster::getSpellSlot).orElse(SpellContainer.EMPTY); 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 @Override
protected void writeCustomDataToTag(CompoundTag tag) { protected void writeCustomDataToTag(CompoundTag tag) {
tag.put("owner", owner.toNBT()); tag.put("owner", owner.toNBT());

View file

@ -15,6 +15,7 @@ import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.ai.goal.GoalSelector; import net.minecraft.entity.ai.goal.GoalSelector;
import net.minecraft.entity.attribute.DefaultAttributeContainer; import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.data.TrackedDataHandlerRegistry;
@ -78,6 +79,12 @@ public class Creature extends Living<LivingEntity> {
return LEVELS; return LEVELS;
} }
@Override
public boolean subtractEnergyCost(double amount) {
getMaster().damage(DamageSource.MAGIC, (int)amount/2);
return getMaster().getHealth() > 0;
}
@Override @Override
public Affinity getAffinity() { public Affinity getAffinity() {
if (getMaster() instanceof Affine) { if (getMaster() instanceof Affine) {

View file

@ -121,6 +121,11 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Magical,
return effectDelegate; return effectDelegate;
} }
@Override
public boolean subtractEnergyCost(double amount) {
return Caster.of(getMaster()).filter(c -> c.subtractEnergyCost(amount)).isPresent();
}
public void setThrowDamage(float damage) { public void setThrowDamage(float damage) {
getDataTracker().set(DAMAGE, Math.max(0, damage)); getDataTracker().set(DAMAGE, Math.max(0, damage));
} }