mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 23:27:59 +01:00
Rewrite mana/food/health consumption to be more forgiving
This commit is contained in:
parent
22be8e35df
commit
5680e60464
2 changed files with 84 additions and 29 deletions
|
@ -0,0 +1,82 @@
|
|||
package com.minelittlepony.unicopia.entity.player;
|
||||
|
||||
import com.minelittlepony.unicopia.util.MagicalDamageSource;
|
||||
|
||||
import net.minecraft.entity.player.HungerManager;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
public interface ManaConsumptionUtil {
|
||||
float FOOD_PER_MANA = 0.1F;
|
||||
float HEARTS_PER_FOOD = 0.5F;
|
||||
float SATURATION_PER_FOOD = 0.8F;
|
||||
|
||||
static float consumeMana(MagicReserves.Bar mana, double foodSubtract) {
|
||||
|
||||
if (foodSubtract <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
float availableMana = mana.get();
|
||||
float consumedMana = (float)foodSubtract / FOOD_PER_MANA;
|
||||
|
||||
if (consumedMana <= availableMana) {
|
||||
mana.set(availableMana - consumedMana);
|
||||
return 0;
|
||||
}
|
||||
|
||||
mana.set(0);
|
||||
return (float)foodSubtract - (availableMana * FOOD_PER_MANA);
|
||||
}
|
||||
|
||||
static float burnFood(PlayerEntity entity, float foodSubtract) {
|
||||
HungerManager hunger = entity.getHungerManager();
|
||||
|
||||
if (foodSubtract <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
float availableSaturation = hunger.getSaturationLevel();
|
||||
|
||||
if (availableSaturation > 0 && foodSubtract > 0) {
|
||||
float consumedSaturation = Math.min(foodSubtract * SATURATION_PER_FOOD, availableSaturation);
|
||||
foodSubtract = addExhaustion(hunger, foodSubtract);
|
||||
if (consumedSaturation > 0) {
|
||||
foodSubtract -= (consumedSaturation / SATURATION_PER_FOOD);
|
||||
hunger.setSaturationLevel(availableSaturation - consumedSaturation);
|
||||
}
|
||||
}
|
||||
|
||||
int availableFood = hunger.getFoodLevel();
|
||||
if (availableFood > 0 && foodSubtract > 0) {
|
||||
int consumedFood = Math.min((int)Math.floor(foodSubtract), availableFood);
|
||||
foodSubtract = addExhaustion(hunger, foodSubtract);
|
||||
if (consumedFood > 0) {
|
||||
foodSubtract -= consumedFood;
|
||||
hunger.add(-consumedFood, 0.3F);
|
||||
}
|
||||
}
|
||||
|
||||
float availableHearts = entity.getHealth();
|
||||
if (foodSubtract > 0) {
|
||||
float consumedHearts = Math.max(0.001F, Math.min(availableHearts - 1, foodSubtract * HEARTS_PER_FOOD));
|
||||
foodSubtract = addExhaustion(hunger, foodSubtract);
|
||||
foodSubtract -= (consumedHearts / HEARTS_PER_FOOD);
|
||||
entity.damage(MagicalDamageSource.EXHAUSTION, consumedHearts);
|
||||
}
|
||||
|
||||
return Math.max(0, foodSubtract);
|
||||
}
|
||||
|
||||
static float addExhaustion(HungerManager hunger, float foodSubtract) {
|
||||
hunger.addExhaustion(0.1F);
|
||||
return Math.max(0, foodSubtract - 0.1F);
|
||||
}
|
||||
|
||||
interface FloatSupplier {
|
||||
float get();
|
||||
}
|
||||
|
||||
interface FloatConsumer {
|
||||
void accept(float f);
|
||||
}
|
||||
}
|
|
@ -330,7 +330,7 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
|
|||
}
|
||||
}
|
||||
|
||||
magicExhaustion = burnFood(magicExhaustion);
|
||||
magicExhaustion = ManaConsumptionUtil.burnFood(entity, magicExhaustion);
|
||||
|
||||
powers.tick();
|
||||
|
||||
|
@ -502,37 +502,10 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
|
|||
|
||||
protected void directTakeEnergy(double foodSubtract) {
|
||||
if (!entity.isCreative() && !entity.world.isClient) {
|
||||
|
||||
float currentMana = mana.getMana().get();
|
||||
float foodManaRatio = 10;
|
||||
|
||||
if (currentMana >= foodSubtract * foodManaRatio) {
|
||||
mana.getMana().set(currentMana - (float)foodSubtract * foodManaRatio);
|
||||
} else {
|
||||
mana.getMana().set(0);
|
||||
foodSubtract -= currentMana / foodManaRatio;
|
||||
|
||||
magicExhaustion += foodSubtract;
|
||||
}
|
||||
magicExhaustion += ManaConsumptionUtil.consumeMana(mana.getMana(), foodSubtract);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<ItemStack> getInventoryStacks() {
|
||||
return Streams.concat(
|
||||
|
|
Loading…
Reference in a new issue