3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-22 14:28:09 +01:00
Paper/nms-patches/FoodMetaData.patch

74 Zeilen
3.4 KiB
Diff

2015-02-26 23:41:06 +01:00
--- /home/matt/mc-dev-private//net/minecraft/server/FoodMetaData.java 2015-02-26 22:40:22.751608138 +0000
+++ src/main/java/net/minecraft/server/FoodMetaData.java 2015-02-26 22:40:22.751608138 +0000
@@ -2,13 +2,21 @@
public class FoodMetaData {
- private int foodLevel = 20;
- private float saturationLevel = 5.0F;
- private float exhaustionLevel;
+ public int foodLevel = 20; // CraftBukkit - public
+ public float saturationLevel = 5.0F; // CraftBukkit - public
+ public float exhaustionLevel; // CraftBukkit - public
private int foodTickTimer;
+ 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));
+ }
+
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutUpdateHealth(((EntityPlayer) entityhuman).getBukkitEntity().getScaledHealth(), entityhuman.getFoodData().foodLevel, entityhuman.getFoodData().saturationLevel));
+ // CraftBukkit end
}
public void a(EntityHuman entityhuman) {
@@ -28,14 +46,23 @@
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
}
}
2015-02-26 23:41:06 +01:00
if (entityhuman.world.getGameRules().getBoolean("naturalRegeneration") && this.foodLevel >= 18 && entityhuman.cm()) {
++this.foodTickTimer;
if (this.foodTickTimer >= 80) {
- entityhuman.heal(1.0F);
+ // CraftBukkit - added RegainReason
+ entityhuman.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED);
this.a(3.0F);
this.foodTickTimer = 0;
}