Smooth out consumption of food levels/fix food consumption being roudned UP

This commit is contained in:
Sollace 2021-01-30 18:32:04 +02:00
parent f885198085
commit 186d7cdbee

View file

@ -92,6 +92,8 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
private int ticksHanging;
private float magicExhaustion = 0;
@Nullable
private Race clientPreferredRace;
@ -255,6 +257,8 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
}
}
magicExhaustion = burnFood(magicExhaustion);
powers.tick();
return false;
@ -384,21 +388,29 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
mana.getMana().set(0);
foodSubtract -= currentMana / foodManaRatio;
int lostLevels = (int)Math.ceil(foodSubtract);
int food = entity.getHungerManager().getFoodLevel() - lostLevels;
if (food < 0) {
entity.getHungerManager().add(-entity.getHungerManager().getFoodLevel(), 0);
entity.damage(MagicalDamageSource.EXHAUSTION, -food/2);
} else {
entity.getHungerManager().add(-lostLevels, 0);
}
magicExhaustion += foodSubtract;
}
}
return entity.getHealth() > 0;
}
private float burnFood(float foodSubtract) {
int lostLevels = (int)Math.floor(foodSubtract);
if (lostLevels > 0) {
int food = entity.getHungerManager().getFoodLevel() - lostLevels;
if (food < 0) {
entity.getHungerManager().add(-entity.getHungerManager().getFoodLevel(), 0);
entity.damage(MagicalDamageSource.EXHAUSTION, -food/2);
} else {
entity.getHungerManager().add(-lostLevels, 0);
}
}
return foodSubtract - lostLevels;
}
public Optional<Text> trySleep(BlockPos pos) {
return findAllSpellsInRange(10)
.filter(p -> p instanceof Pony && ((Pony)p).isEnemy(this))
@ -416,6 +428,8 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
public void toNBT(CompoundTag compound) {
compound.putString("playerSpecies", getSpecies().name());
compound.putFloat("magicExhaustion", magicExhaustion);
compound.put("powers", powers.toNBT());
compound.put("gravity", gravity.toNBT());
@ -434,6 +448,8 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
powers.fromNBT(compound.getCompound("powers"));
gravity.fromNBT(compound.getCompound("gravity"));
magicExhaustion = compound.getFloat("magicExhaustion");
if (compound.contains("effect")) {
effectDelegate.set(SpellRegistry.instance().createEffectFromNBT(compound.getCompound("effect")));
}