2015-05-25 12:37:24 +02:00
|
|
|
--- a/net/minecraft/server/FoodMetaData.java
|
|
|
|
+++ b/net/minecraft/server/FoodMetaData.java
|
2015-06-06 11:33:48 +02:00
|
|
|
@@ -6,9 +6,17 @@
|
|
|
|
public float saturationLevel = 5.0F;
|
|
|
|
public float exhaustionLevel;
|
2015-02-26 23:41:06 +01:00
|
|
|
private int foodTickTimer;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ private EntityHuman entityhuman; // CraftBukkit
|
|
|
|
private int e = 20;
|
|
|
|
|
|
|
|
- public FoodMetaData() {}
|
|
|
|
+ public FoodMetaData() { throw new AssertionError("Whoopsie, we missed the bukkit."); } // CraftBukkit start - throw an error
|
|
|
|
+
|
|
|
|
+ // CraftBukkit start - added EntityHuman constructor
|
|
|
|
+ public FoodMetaData(EntityHuman entityhuman) {
|
|
|
|
+ org.apache.commons.lang.Validate.notNull(entityhuman);
|
|
|
|
+ this.entityhuman = entityhuman;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
|
|
|
|
public void eat(int i, float f) {
|
|
|
|
this.foodLevel = Math.min(i + this.foodLevel, 20);
|
|
|
|
@@ -16,7 +24,17 @@
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(ItemFood itemfood, ItemStack itemstack) {
|
|
|
|
- this.eat(itemfood.getNutrition(itemstack), itemfood.getSaturationModifier(itemstack));
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ int oldFoodLevel = foodLevel;
|
|
|
|
+
|
|
|
|
+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, itemfood.getNutrition(itemstack) + oldFoodLevel);
|
|
|
|
+
|
|
|
|
+ if (!event.isCancelled()) {
|
|
|
|
+ this.eat(event.getFoodLevel() - oldFoodLevel, itemfood.getSaturationModifier(itemstack));
|
|
|
|
+ }
|
|
|
|
+
|
2016-07-01 03:20:31 +02:00
|
|
|
+ ((EntityPlayer) entityhuman).getBukkitEntity().sendHealthUpdate();
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(EntityHuman entityhuman) {
|
2016-02-29 22:32:46 +01:00
|
|
|
@@ -28,7 +46,15 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
if (this.saturationLevel > 0.0F) {
|
|
|
|
this.saturationLevel = Math.max(this.saturationLevel - 1.0F, 0.0F);
|
|
|
|
} else if (enumdifficulty != EnumDifficulty.PEACEFUL) {
|
|
|
|
- this.foodLevel = Math.max(this.foodLevel - 1, 0);
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, Math.max(this.foodLevel - 1, 0));
|
|
|
|
+
|
|
|
|
+ if (!event.isCancelled()) {
|
|
|
|
+ this.foodLevel = event.getFoodLevel();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutUpdateHealth(((EntityPlayer) entityhuman).getBukkitEntity().getScaledHealth(), this.foodLevel, this.saturationLevel));
|
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-12 01:12:38 +01:00
|
|
|
@@ -39,14 +65,14 @@
|
|
|
|
if (this.foodTickTimer >= 10) {
|
2016-11-17 02:41:03 +01:00
|
|
|
float f = Math.min(this.saturationLevel, 6.0F);
|
2016-03-12 01:12:38 +01:00
|
|
|
|
2016-11-17 02:41:03 +01:00
|
|
|
- entityhuman.heal(f / 6.0F);
|
|
|
|
+ entityhuman.heal(f / 6.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason
|
2016-03-12 01:12:38 +01:00
|
|
|
this.a(f);
|
|
|
|
this.foodTickTimer = 0;
|
|
|
|
}
|
2018-07-15 02:00:00 +02:00
|
|
|
} else if (flag && this.foodLevel >= 18 && entityhuman.dw()) {
|
2014-11-25 22:32:16 +01:00
|
|
|
++this.foodTickTimer;
|
|
|
|
if (this.foodTickTimer >= 80) {
|
|
|
|
- entityhuman.heal(1.0F);
|
2016-03-12 01:12:38 +01:00
|
|
|
+ entityhuman.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason
|
2016-11-17 02:41:03 +01:00
|
|
|
this.a(6.0F);
|
2014-11-25 22:32:16 +01:00
|
|
|
this.foodTickTimer = 0;
|
|
|
|
}
|