Fixed food levels going out of sync between the client and the server

This commit is contained in:
Sollace 2021-01-29 19:22:43 +02:00
parent 8f654177ec
commit f885198085

View file

@ -373,7 +373,7 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
@Override @Override
public boolean subtractEnergyCost(double foodSubtract) { public boolean subtractEnergyCost(double foodSubtract) {
if (!entity.isCreative()) { if (!entity.isCreative() && !entity.world.isClient) {
float currentMana = mana.getMana().get(); float currentMana = mana.getMana().get();
float foodManaRatio = 10; float foodManaRatio = 10;
@ -384,13 +384,14 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
mana.getMana().set(0); mana.getMana().set(0);
foodSubtract -= currentMana / foodManaRatio; foodSubtract -= currentMana / foodManaRatio;
int food = (int)(entity.getHungerManager().getFoodLevel() - foodSubtract); int lostLevels = (int)Math.ceil(foodSubtract);
int food = entity.getHungerManager().getFoodLevel() - lostLevels;
if (food < 0) { if (food < 0) {
entity.getHungerManager().add(-entity.getHungerManager().getFoodLevel(), 0); entity.getHungerManager().add(-entity.getHungerManager().getFoodLevel(), 0);
entity.damage(MagicalDamageSource.EXHAUSTION, -food/2); entity.damage(MagicalDamageSource.EXHAUSTION, -food/2);
} else { } else {
entity.getHungerManager().add((int)-foodSubtract, 0); entity.getHungerManager().add(-lostLevels, 0);
} }
} }
} }