mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fixed mana cost for cast spells not being passed on to the player
This commit is contained in:
parent
c188b9c7cb
commit
e386e040ea
4 changed files with 22 additions and 6 deletions
|
@ -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<E extends LivingEntity> extends Owned<E>, 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<Caster<?>> findAllSpellsInRange(double radius) {
|
||||
return findAllSpellsInRange(radius, null);
|
||||
|
|
|
@ -145,6 +145,11 @@ public class CastSpellEntity extends Entity implements Caster<LivingEntity> {
|
|||
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());
|
||||
|
|
|
@ -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<LivingEntity> {
|
|||
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) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue