MCPcopy Create free account
hub / github.com/DGVPSH/SlackOpen / onUpdate

Method onUpdate

src/main/java/net/minecraft/util/FoodStats.java:41–89  ·  view source on GitHub ↗

Handles the food game logic.

(EntityPlayer player)

Source from the content-addressed store, hash-verified

39 * Handles the food game logic.
40 */
41 public void onUpdate(EntityPlayer player)
42 {
43 EnumDifficulty enumdifficulty = player.worldObj.getDifficulty();
44 this.prevFoodLevel = this.foodLevel;
45
46 if (this.foodExhaustionLevel > 4.0F)
47 {
48 this.foodExhaustionLevel -= 4.0F;
49
50 if (this.foodSaturationLevel > 0.0F)
51 {
52 this.foodSaturationLevel = Math.max(this.foodSaturationLevel - 1.0F, 0.0F);
53 }
54 else if (enumdifficulty != EnumDifficulty.PEACEFUL)
55 {
56 this.foodLevel = Math.max(this.foodLevel - 1, 0);
57 }
58 }
59
60 if (player.worldObj.getGameRules().getGameRuleBooleanValue("naturalRegeneration") && this.foodLevel >= 18 && player.shouldHeal())
61 {
62 ++this.foodTimer;
63
64 if (this.foodTimer >= 80)
65 {
66 player.heal(1.0F);
67 this.addExhaustion(3.0F);
68 this.foodTimer = 0;
69 }
70 }
71 else if (this.foodLevel <= 0)
72 {
73 ++this.foodTimer;
74
75 if (this.foodTimer >= 80)
76 {
77 if (player.getHealth() > 10.0F || enumdifficulty == EnumDifficulty.HARD || player.getHealth() > 1.0F && enumdifficulty == EnumDifficulty.NORMAL)
78 {
79 player.attackEntityFrom(DamageSource.starve, 1.0F);
80 }
81
82 this.foodTimer = 0;
83 }
84 }
85 else
86 {
87 this.foodTimer = 0;
88 }
89 }
90
91 /**
92 * Reads the food data for the player.

Callers

nothing calls this directly

Calls 8

addExhaustionMethod · 0.95
shouldHealMethod · 0.80
getHealthMethod · 0.65
getDifficultyMethod · 0.45
getGameRulesMethod · 0.45
healMethod · 0.45
attackEntityFromMethod · 0.45

Tested by

no test coverage detected