diff --git a/nms-patches/FoodMetaData.patch b/nms-patches/FoodMetaData.patch index 53d872776f..316c443b12 100644 --- a/nms-patches/FoodMetaData.patch +++ b/nms-patches/FoodMetaData.patch @@ -27,7 +27,7 @@ + int oldFoodLevel = foodLevel; - this.eat(foodinfo.getNutrition(), foodinfo.getSaturationModifier()); -+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, foodinfo.getNutrition() + oldFoodLevel); ++ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, foodinfo.getNutrition() + oldFoodLevel, itemstack); + + if (!event.isCancelled()) { + this.eat(event.getFoodLevel() - oldFoodLevel, foodinfo.getSaturationModifier()); diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 7e682826e0..a09240d8a7 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -980,7 +980,11 @@ public class CraftEventFactory { } public static FoodLevelChangeEvent callFoodLevelChangeEvent(EntityHuman entity, int level) { - FoodLevelChangeEvent event = new FoodLevelChangeEvent(entity.getBukkitEntity(), level); + return callFoodLevelChangeEvent(entity, level, null); + } + + public static FoodLevelChangeEvent callFoodLevelChangeEvent(EntityHuman entity, int level, ItemStack item) { + FoodLevelChangeEvent event = new FoodLevelChangeEvent(entity.getBukkitEntity(), level, (item == null) ? null : CraftItemStack.asBukkitCopy(item)); entity.getBukkitEntity().getServer().getPluginManager().callEvent(event); return event; }