2011-09-15 07:24:45 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2012-02-21 13:51:56 +01:00
|
|
|
import org.bukkit.event.entity.EntityDamageEvent; // CraftBukkit
|
2011-09-21 23:11:06 +02:00
|
|
|
|
2011-09-15 07:24:45 +02:00
|
|
|
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() {}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
public void eat(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) {
|
2012-01-14 21:03:48 +01:00
|
|
|
this.eat(itemfood.getNutrition(), itemfood.getSaturationModifier());
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(EntityHuman entityhuman) {
|
2011-09-24 23:03:31 +02:00
|
|
|
int i = entityhuman.world.difficulty;
|
2011-09-15 07:24:45 +02:00
|
|
|
|
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-22 00:54:31 +02:00
|
|
|
// CraftBukkit start
|
2012-03-02 04:47:33 +01:00
|
|
|
org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, Math.max(this.foodLevel - 1, 0));
|
2011-09-22 00:54:31 +02:00
|
|
|
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
this.foodLevel = event.getFoodLevel();
|
|
|
|
}
|
2012-09-13 03:56:06 +02:00
|
|
|
|
|
|
|
((EntityPlayer) entityhuman).netServerHandler.sendPacket(new Packet8UpdateHealth(entityhuman.getHealth(), this.foodLevel, this.saturationLevel));
|
2011-09-22 00:54:31 +02:00
|
|
|
// CraftBukkit end
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (this.foodLevel >= 18 && entityhuman.bM()) {
|
2011-09-15 18:36:27 +02:00
|
|
|
++this.foodTickTimer;
|
|
|
|
if (this.foodTickTimer >= 80) {
|
2012-07-29 09:33:13 +02:00
|
|
|
// CraftBukkit - added RegainReason
|
2012-01-14 21:03:48 +01:00
|
|
|
entityhuman.heal(1, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED);
|
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-11-20 09:01:14 +01:00
|
|
|
if (entityhuman.getHealth() > 10 || i >= 3 || entityhuman.getHealth() > 1 && i >= 2) {
|
2011-09-21 23:11:06 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
EntityDamageEvent event = new EntityDamageEvent(entityhuman.getBukkitEntity(), EntityDamageEvent.DamageCause.STARVATION, 1);
|
|
|
|
entityhuman.world.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (!event.isCancelled()) {
|
2012-07-01 12:04:06 +02:00
|
|
|
event.getEntity().setLastDamageCause(event);
|
2011-09-21 23:11:06 +02:00
|
|
|
entityhuman.damageEntity(DamageSource.STARVE, event.getDamage());
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
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-11-30 00:17:43 +01:00
|
|
|
this.foodLevel = nbttagcompound.getInt("foodLevel");
|
|
|
|
this.foodTickTimer = nbttagcompound.getInt("foodTickTimer");
|
|
|
|
this.saturationLevel = nbttagcompound.getFloat("foodSaturationLevel");
|
|
|
|
this.exhaustionLevel = nbttagcompound.getFloat("foodExhaustionLevel");
|
2011-09-15 07:24:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
2011-11-30 00:17:43 +01:00
|
|
|
nbttagcompound.setInt("foodLevel", this.foodLevel);
|
|
|
|
nbttagcompound.setInt("foodTickTimer", this.foodTickTimer);
|
|
|
|
nbttagcompound.setFloat("foodSaturationLevel", this.saturationLevel);
|
|
|
|
nbttagcompound.setFloat("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
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public boolean c() {
|
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
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public float e() {
|
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
|
|
|
}
|