2011-09-15 07:24:45 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
public class FoodMetaData {
|
|
|
|
|
|
|
|
// CraftBukkit start - all made public
|
2011-09-15 18:36:27 +02:00
|
|
|
public int foodLevel = 20;
|
|
|
|
public float saturationLevel = 5.0F;
|
|
|
|
public float exhaustionLevel;
|
|
|
|
public int foodTickTimer = 0;
|
2011-09-15 07:24:45 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
private int e = 20;
|
|
|
|
|
|
|
|
public FoodMetaData() {}
|
|
|
|
|
|
|
|
public void a(int i, float f) {
|
2011-09-15 18:36:27 +02:00
|
|
|
this.foodLevel = Math.min(i + this.foodLevel, 20);
|
|
|
|
this.saturationLevel = Math.min(this.saturationLevel + (float) i * f * 2.0F, (float) this.foodLevel);
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(ItemFood itemfood) {
|
|
|
|
this.a(itemfood.k(), itemfood.l());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(EntityHuman entityhuman) {
|
|
|
|
int i = entityhuman.world.spawnMonsters;
|
|
|
|
|
2011-09-15 18:36:27 +02:00
|
|
|
this.e = this.foodLevel;
|
|
|
|
if (this.exhaustionLevel > 4.0F) {
|
|
|
|
this.exhaustionLevel -= 4.0F;
|
|
|
|
if (this.saturationLevel > 0.0F) {
|
|
|
|
this.saturationLevel = Math.max(this.saturationLevel - 1.0F, 0.0F);
|
2011-09-15 07:24:45 +02:00
|
|
|
} else if (i > 0) {
|
2011-09-15 18:36:27 +02:00
|
|
|
this.foodLevel = Math.max(this.foodLevel - 1, 0);
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-15 18:36:27 +02:00
|
|
|
if (this.foodLevel >= 18 && entityhuman.W()) {
|
|
|
|
++this.foodTickTimer;
|
|
|
|
if (this.foodTickTimer >= 80) {
|
2011-09-15 07:24:45 +02:00
|
|
|
entityhuman.c(1);
|
2011-09-15 18:36:27 +02:00
|
|
|
this.foodTickTimer = 0;
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
2011-09-15 18:36:27 +02:00
|
|
|
} else if (this.foodLevel <= 0) {
|
|
|
|
++this.foodTickTimer;
|
|
|
|
if (this.foodTickTimer >= 80) {
|
2011-09-15 07:24:45 +02:00
|
|
|
if (entityhuman.health > 10 || i >= 3 || entityhuman.health > 1 && i >= 2) {
|
2011-09-15 18:36:27 +02:00
|
|
|
entityhuman.damageEntity(DamageSource.STARVE, 1);
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 18:36:27 +02:00
|
|
|
this.foodTickTimer = 0;
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
|
|
|
} else {
|
2011-09-15 18:36:27 +02:00
|
|
|
this.foodTickTimer = 0;
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
if (nbttagcompound.hasKey("foodLevel")) {
|
2011-09-15 18:36:27 +02:00
|
|
|
this.foodLevel = nbttagcompound.e("foodLevel");
|
|
|
|
this.foodTickTimer = nbttagcompound.e("foodTickTimer");
|
|
|
|
this.saturationLevel = nbttagcompound.g("foodSaturationLevel");
|
|
|
|
this.exhaustionLevel = nbttagcompound.g("foodExhaustionLevel");
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
2011-09-15 18:36:27 +02:00
|
|
|
nbttagcompound.a("foodLevel", this.foodLevel);
|
|
|
|
nbttagcompound.a("foodTickTimer", this.foodTickTimer);
|
|
|
|
nbttagcompound.a("foodSaturationLevel", this.saturationLevel);
|
|
|
|
nbttagcompound.a("foodExhaustionLevel", this.exhaustionLevel);
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int a() {
|
2011-09-15 18:36:27 +02:00
|
|
|
return this.foodLevel;
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean b() {
|
2011-09-15 18:36:27 +02:00
|
|
|
return this.foodLevel < 20;
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(float f) {
|
2011-09-15 18:36:27 +02:00
|
|
|
this.exhaustionLevel = Math.min(this.exhaustionLevel + f, 40.0F);
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public float c() {
|
2011-09-15 18:36:27 +02:00
|
|
|
return this.saturationLevel;
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
2011-09-15 18:36:27 +02:00
|
|
|
}
|