aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/og/net/minecraft/world/food/FoodMetaData.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/og/net/minecraft/world/food/FoodMetaData.patch')
-rw-r--r--patch-remap/og/net/minecraft/world/food/FoodMetaData.patch106
1 files changed, 106 insertions, 0 deletions
diff --git a/patch-remap/og/net/minecraft/world/food/FoodMetaData.patch b/patch-remap/og/net/minecraft/world/food/FoodMetaData.patch
new file mode 100644
index 0000000000..ea2002c264
--- /dev/null
+++ b/patch-remap/og/net/minecraft/world/food/FoodMetaData.patch
@@ -0,0 +1,106 @@
+--- a/net/minecraft/world/food/FoodMetaData.java
++++ b/net/minecraft/world/food/FoodMetaData.java
+@@ -7,15 +7,33 @@
+ import net.minecraft.world.item.ItemStack;
+ import net.minecraft.world.level.GameRules;
+
++// CraftBukkit start
++import net.minecraft.network.protocol.game.PacketPlayOutUpdateHealth;
++import net.minecraft.server.level.EntityPlayer;
++// CraftBukkit end
++
+ public class FoodMetaData {
+
+ public int foodLevel = 20;
+ public float saturationLevel = 5.0F;
+ public float exhaustionLevel;
+ private int tickTimer;
++ // CraftBukkit start
++ private EntityHuman entityhuman;
++ public int saturatedRegenRate = 10;
++ public int unsaturatedRegenRate = 80;
++ public int starvationRate = 80;
++ // CraftBukkit end
+ private int lastFoodLevel = 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);
+@@ -25,8 +43,17 @@
+ public void eat(Item item, ItemStack itemstack) {
+ if (item.isEdible()) {
+ FoodInfo foodinfo = item.getFoodProperties();
++ // CraftBukkit start
++ 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, itemstack);
++
++ if (!event.isCancelled()) {
++ this.eat(event.getFoodLevel() - oldFoodLevel, foodinfo.getSaturationModifier());
++ }
++
++ ((EntityPlayer) entityhuman).getBukkitEntity().sendHealthUpdate();
++ // CraftBukkit end
+ }
+
+ }
+@@ -40,7 +67,15 @@
+ 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).connection.send(new PacketPlayOutUpdateHealth(((EntityPlayer) entityhuman).getBukkitEntity().getScaledHealth(), this.foodLevel, this.saturationLevel));
++ // CraftBukkit end
+ }
+ }
+
+@@ -48,23 +83,25 @@
+
+ if (flag && this.saturationLevel > 0.0F && entityhuman.isHurt() && this.foodLevel >= 20) {
+ ++this.tickTimer;
+- if (this.tickTimer >= 10) {
++ if (this.tickTimer >= this.saturatedRegenRate) { // CraftBukkit
+ float f = Math.min(this.saturationLevel, 6.0F);
+
+- entityhuman.heal(f / 6.0F);
+- this.addExhaustion(f);
++ entityhuman.heal(f / 6.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason
++ // this.addExhaustion(f); CraftBukkit - EntityExhaustionEvent
++ entityhuman.causeFoodExhaustion(f, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent
+ this.tickTimer = 0;
+ }
+ } else if (flag && this.foodLevel >= 18 && entityhuman.isHurt()) {
+ ++this.tickTimer;
+- if (this.tickTimer >= 80) {
+- entityhuman.heal(1.0F);
+- this.addExhaustion(6.0F);
++ if (this.tickTimer >= this.unsaturatedRegenRate) { // CraftBukkit - add regen rate manipulation
++ entityhuman.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason
++ // this.a(6.0F); CraftBukkit - EntityExhaustionEvent
++ entityhuman.causeFoodExhaustion(6.0f, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent
+ this.tickTimer = 0;
+ }
+ } else if (this.foodLevel <= 0) {
+ ++this.tickTimer;
+- if (this.tickTimer >= 80) {
++ if (this.tickTimer >= this.starvationRate) { // CraftBukkit - add regen rate manipulation
+ if (entityhuman.getHealth() > 10.0F || enumdifficulty == EnumDifficulty.HARD || entityhuman.getHealth() > 1.0F && enumdifficulty == EnumDifficulty.NORMAL) {
+ entityhuman.hurt(entityhuman.damageSources().starve(), 1.0F);
+ }