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