use of squeek.applecore.asm.util.IAppleCoreFoodStats in project AppleCore by squeek502.
the class Hooks method getExhaustionCap.
public static float getExhaustionCap(FoodStats foodStats) {
verifyFoodStats(foodStats, null);
EntityPlayer player = ((IAppleCoreFoodStats) foodStats).getPlayer();
ExhaustionEvent.GetExhaustionCap event = new ExhaustionEvent.GetExhaustionCap(player);
MinecraftForge.EVENT_BUS.post(event);
return event.exhaustionLevelCap;
}
use of squeek.applecore.asm.util.IAppleCoreFoodStats in project AppleCore by squeek502.
the class Hooks method onExhaustionAdded.
public static float onExhaustionAdded(FoodStats foodStats, float deltaExhaustion) {
verifyFoodStats(foodStats, null);
EntityPlayer player = ((IAppleCoreFoodStats) foodStats).getPlayer();
ExhaustionEvent.ExhaustionAddition event = new ExhaustionEvent.ExhaustionAddition(player, deltaExhaustion);
MinecraftForge.EVENT_BUS.post(event);
return event.deltaExhaustion;
}
use of squeek.applecore.asm.util.IAppleCoreFoodStats in project AppleCore by squeek502.
the class Hooks method getMaxHunger.
public static int getMaxHunger(FoodStats foodStats) {
verifyFoodStats(foodStats, null);
EntityPlayer player = ((IAppleCoreFoodStats) foodStats).getPlayer();
return AppleCoreAPI.accessor.getMaxHunger(player);
}
use of squeek.applecore.asm.util.IAppleCoreFoodStats in project AppleCore by squeek502.
the class Hooks method getHungerForDisplay.
@SideOnly(Side.CLIENT)
public static int getHungerForDisplay(FoodStats foodStats) {
if (!(foodStats instanceof IAppleCoreFoodStats))
return foodStats.getFoodLevel();
// return a scaled value so that the HUD can still use the same logic
// as if the max was 20
EntityPlayer player = ((IAppleCoreFoodStats) foodStats).getPlayer();
float scale = 20f / AppleCoreAPI.accessor.getMaxHunger(player);
int realHunger = foodStats.getFoodLevel();
// only return 0 if the real hunger value is 0
if (realHunger == 0)
return 0;
// floor here so that full hunger is only drawn when its actually maxed
int scaledHunger = MathHelper.floor(realHunger * scale);
// starving
return Math.max(scaledHunger, 1);
}
use of squeek.applecore.asm.util.IAppleCoreFoodStats in project AppleCore by squeek502.
the class Hooks method onAppleCoreFoodStatsUpdate.
public static boolean onAppleCoreFoodStatsUpdate(FoodStats foodStats, EntityPlayer player) {
verifyFoodStats(foodStats, player);
IAppleCoreFoodStats appleCoreFoodStats = (IAppleCoreFoodStats) foodStats;
appleCoreFoodStats.setPrevFoodLevel(foodStats.getFoodLevel());
Result allowExhaustionResult = Hooks.fireAllowExhaustionEvent(player);
float maxExhaustion = Hooks.fireExhaustionTickEvent(player, appleCoreFoodStats.getExhaustion());
if (allowExhaustionResult == Result.ALLOW || (allowExhaustionResult == Result.DEFAULT && appleCoreFoodStats.getExhaustion() >= maxExhaustion)) {
ExhaustionEvent.Exhausted exhaustedEvent = Hooks.fireExhaustionMaxEvent(player, maxExhaustion, appleCoreFoodStats.getExhaustion());
appleCoreFoodStats.setExhaustion(appleCoreFoodStats.getExhaustion() + exhaustedEvent.deltaExhaustion);
if (!exhaustedEvent.isCanceled()) {
appleCoreFoodStats.setSaturation(Math.max(foodStats.getSaturationLevel() + exhaustedEvent.deltaSaturation, 0.0F));
foodStats.setFoodLevel(Math.max(foodStats.getFoodLevel() + exhaustedEvent.deltaHunger, 0));
}
}
boolean hasNaturalRegen = player.world.getGameRules().getBoolean("naturalRegeneration");
Result allowSaturatedRegenResult = Hooks.fireAllowSaturatedRegenEvent(player);
boolean shouldDoSaturatedRegen = allowSaturatedRegenResult == Result.ALLOW || (allowSaturatedRegenResult == Result.DEFAULT && hasNaturalRegen && foodStats.getSaturationLevel() > 0.0F && player.shouldHeal() && foodStats.getFoodLevel() >= 20);
Result allowRegenResult = shouldDoSaturatedRegen ? Result.DENY : Hooks.fireAllowRegenEvent(player);
boolean shouldDoRegen = allowRegenResult == Result.ALLOW || (allowRegenResult == Result.DEFAULT && hasNaturalRegen && foodStats.getFoodLevel() >= 18 && player.shouldHeal());
if (shouldDoSaturatedRegen) {
appleCoreFoodStats.setFoodTimer(appleCoreFoodStats.getFoodTimer() + 1);
if (appleCoreFoodStats.getFoodTimer() >= Hooks.fireSaturatedRegenTickEvent(player)) {
HealthRegenEvent.SaturatedRegen saturatedRegenEvent = Hooks.fireSaturatedRegenEvent(player);
if (!saturatedRegenEvent.isCanceled()) {
player.heal(saturatedRegenEvent.deltaHealth);
foodStats.addExhaustion(saturatedRegenEvent.deltaExhaustion);
}
appleCoreFoodStats.setFoodTimer(0);
}
} else if (shouldDoRegen) {
appleCoreFoodStats.setFoodTimer(appleCoreFoodStats.getFoodTimer() + 1);
if (appleCoreFoodStats.getFoodTimer() >= Hooks.fireRegenTickEvent(player)) {
HealthRegenEvent.Regen regenEvent = Hooks.fireRegenEvent(player);
if (!regenEvent.isCanceled()) {
player.heal(regenEvent.deltaHealth);
foodStats.addExhaustion(regenEvent.deltaExhaustion);
}
appleCoreFoodStats.setFoodTimer(0);
}
} else {
appleCoreFoodStats.setFoodTimer(0);
}
Result allowStarvationResult = Hooks.fireAllowStarvation(player);
if (allowStarvationResult == Result.ALLOW || (allowStarvationResult == Result.DEFAULT && foodStats.getFoodLevel() <= 0)) {
appleCoreFoodStats.setStarveTimer(appleCoreFoodStats.getStarveTimer() + 1);
if (appleCoreFoodStats.getStarveTimer() >= Hooks.fireStarvationTickEvent(player)) {
StarvationEvent.Starve starveEvent = Hooks.fireStarveEvent(player);
if (!starveEvent.isCanceled()) {
player.attackEntityFrom(DamageSource.STARVE, starveEvent.starveDamage);
}
appleCoreFoodStats.setStarveTimer(0);
}
} else {
appleCoreFoodStats.setStarveTimer(0);
}
return true;
}
Aggregations