aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower/net/minecraft/world/food/FoodData.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-spigotflower/net/minecraft/world/food/FoodData.java.patch')
-rw-r--r--patch-remap/mache-spigotflower/net/minecraft/world/food/FoodData.java.patch194
1 files changed, 194 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower/net/minecraft/world/food/FoodData.java.patch b/patch-remap/mache-spigotflower/net/minecraft/world/food/FoodData.java.patch
new file mode 100644
index 0000000000..c9b63edfe3
--- /dev/null
+++ b/patch-remap/mache-spigotflower/net/minecraft/world/food/FoodData.java.patch
@@ -0,0 +1,194 @@
+--- a/net/minecraft/world/food/FoodData.java
++++ b/net/minecraft/world/food/FoodData.java
+@@ -1,6 +1,8 @@
+ package net.minecraft.world.food;
+
+ import net.minecraft.nbt.CompoundTag;
++import net.minecraft.network.protocol.game.ClientboundSetHealthPacket;
++import net.minecraft.server.level.ServerPlayer;
+ import net.minecraft.world.Difficulty;
+ import net.minecraft.world.entity.player.Player;
+ import net.minecraft.world.item.Item;
+@@ -9,38 +11,68 @@
+
+ public class FoodData {
+
+- private int foodLevel = 20;
+- private float saturationLevel = 5.0F;
+- private float exhaustionLevel;
++ public int foodLevel = 20;
++ public float saturationLevel = 5.0F;
++ public float exhaustionLevel;
+ private int tickTimer;
++ // CraftBukkit start
++ private Player entityhuman;
++ public int saturatedRegenRate = 10;
++ public int unsaturatedRegenRate = 80;
++ public int starvationRate = 80;
++ // CraftBukkit end
+ private int lastFoodLevel = 20;
+
+- public FoodData() {}
++ public FoodData() { throw new AssertionError("Whoopsie, we missed the bukkit."); } // CraftBukkit start - throw an error
+
+- public void eat(int i, float f) {
+- this.foodLevel = Math.min(i + this.foodLevel, 20);
+- this.saturationLevel = Math.min(this.saturationLevel + (float) i * f * 2.0F, (float) this.foodLevel);
++ // CraftBukkit start - added EntityHuman constructor
++ public FoodData(Player entityhuman) {
++ org.apache.commons.lang.Validate.notNull(entityhuman);
++ this.entityhuman = entityhuman;
+ }
++ // CraftBukkit end
+
+- public void eat(Item item, ItemStack itemstack) {
++ public void eat(int foodLevelModifier, float saturationLevelModifier) {
++ this.foodLevel = Math.min(foodLevelModifier + this.foodLevel, 20);
++ this.saturationLevel = Math.min(this.saturationLevel + (float) foodLevelModifier * saturationLevelModifier * 2.0F, (float) this.foodLevel);
++ }
++
++ public void eat(Item item, ItemStack stack) {
+ if (item.isEdible()) {
+- FoodProperties foodproperties = item.getFoodProperties();
++ FoodProperties foodinfo = item.getFoodProperties();
++ // CraftBukkit start
++ int oldFoodLevel = foodLevel;
+
+- this.eat(foodproperties.getNutrition(), foodproperties.getSaturationModifier());
++ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, foodinfo.getNutrition() + oldFoodLevel, stack);
++
++ if (!event.isCancelled()) {
++ this.eat(event.getFoodLevel() - oldFoodLevel, foodinfo.getSaturationModifier());
++ }
++
++ ((ServerPlayer) entityhuman).getBukkitEntity().sendHealthUpdate();
++ // CraftBukkit end
+ }
+
+ }
+
+ public void tick(Player player) {
+- Difficulty difficulty = player.level().getDifficulty();
++ Difficulty enumdifficulty = player.level().getDifficulty();
+
+ this.lastFoodLevel = 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);
+- } else if (difficulty != Difficulty.PEACEFUL) {
+- this.foodLevel = Math.max(this.foodLevel - 1, 0);
++ } else if (enumdifficulty != Difficulty.PEACEFUL) {
++ // CraftBukkit start
++ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(player, Math.max(this.foodLevel - 1, 0));
++
++ if (!event.isCancelled()) {
++ this.foodLevel = event.getFoodLevel();
++ }
++
++ ((ServerPlayer) player).connection.send(new ClientboundSetHealthPacket(((ServerPlayer) player).getBukkitEntity().getScaledHealth(), this.foodLevel, this.saturationLevel));
++ // CraftBukkit end
+ }
+ }
+
+@@ -48,24 +80,26 @@
+
+ if (flag && this.saturationLevel > 0.0F && player.isHurt() && this.foodLevel >= 20) {
+ ++this.tickTimer;
+- if (this.tickTimer >= 10) {
++ if (this.tickTimer >= this.saturatedRegenRate) { // CraftBukkit
+ float f = Math.min(this.saturationLevel, 6.0F);
+
+- player.heal(f / 6.0F);
+- this.addExhaustion(f);
++ player.heal(f / 6.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason
++ // this.addExhaustion(f); CraftBukkit - EntityExhaustionEvent
++ player.causeFoodExhaustion(f, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent
+ this.tickTimer = 0;
+ }
+ } else if (flag && this.foodLevel >= 18 && player.isHurt()) {
+ ++this.tickTimer;
+- if (this.tickTimer >= 80) {
+- player.heal(1.0F);
+- this.addExhaustion(6.0F);
++ if (this.tickTimer >= this.unsaturatedRegenRate) { // CraftBukkit - add regen rate manipulation
++ player.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason
++ // this.a(6.0F); CraftBukkit - EntityExhaustionEvent
++ player.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 (player.getHealth() > 10.0F || difficulty == Difficulty.HARD || player.getHealth() > 1.0F && difficulty == Difficulty.NORMAL) {
++ if (this.tickTimer >= this.starvationRate) { // CraftBukkit - add regen rate manipulation
++ if (player.getHealth() > 10.0F || enumdifficulty == Difficulty.HARD || player.getHealth() > 1.0F && enumdifficulty == Difficulty.NORMAL) {
+ player.hurt(player.damageSources().starve(), 1.0F);
+ }
+
+@@ -77,21 +111,21 @@
+
+ }
+
+- public void readAdditionalSaveData(CompoundTag compoundtag) {
+- if (compoundtag.contains("foodLevel", 99)) {
+- this.foodLevel = compoundtag.getInt("foodLevel");
+- this.tickTimer = compoundtag.getInt("foodTickTimer");
+- this.saturationLevel = compoundtag.getFloat("foodSaturationLevel");
+- this.exhaustionLevel = compoundtag.getFloat("foodExhaustionLevel");
++ public void readAdditionalSaveData(CompoundTag compoundTag) {
++ if (compoundTag.contains("foodLevel", 99)) {
++ this.foodLevel = compoundTag.getInt("foodLevel");
++ this.tickTimer = compoundTag.getInt("foodTickTimer");
++ this.saturationLevel = compoundTag.getFloat("foodSaturationLevel");
++ this.exhaustionLevel = compoundTag.getFloat("foodExhaustionLevel");
+ }
+
+ }
+
+- public void addAdditionalSaveData(CompoundTag compoundtag) {
+- compoundtag.putInt("foodLevel", this.foodLevel);
+- compoundtag.putInt("foodTickTimer", this.tickTimer);
+- compoundtag.putFloat("foodSaturationLevel", this.saturationLevel);
+- compoundtag.putFloat("foodExhaustionLevel", this.exhaustionLevel);
++ public void addAdditionalSaveData(CompoundTag compoundTag) {
++ compoundTag.putInt("foodLevel", this.foodLevel);
++ compoundTag.putInt("foodTickTimer", this.tickTimer);
++ compoundTag.putFloat("foodSaturationLevel", this.saturationLevel);
++ compoundTag.putFloat("foodExhaustionLevel", this.exhaustionLevel);
+ }
+
+ public int getFoodLevel() {
+@@ -106,8 +140,8 @@
+ return this.foodLevel < 20;
+ }
+
+- public void addExhaustion(float f) {
+- this.exhaustionLevel = Math.min(this.exhaustionLevel + f, 40.0F);
++ public void addExhaustion(float exhaustion) {
++ this.exhaustionLevel = Math.min(this.exhaustionLevel + exhaustion, 40.0F);
+ }
+
+ public float getExhaustionLevel() {
+@@ -118,15 +152,15 @@
+ return this.saturationLevel;
+ }
+
+- public void setFoodLevel(int i) {
+- this.foodLevel = i;
++ public void setFoodLevel(int foodLevel) {
++ this.foodLevel = foodLevel;
+ }
+
+- public void setSaturation(float f) {
+- this.saturationLevel = f;
++ public void setSaturation(float saturationLevel) {
++ this.saturationLevel = saturationLevel;
+ }
+
+- public void setExhaustion(float f) {
+- this.exhaustionLevel = f;
++ public void setExhaustion(float exhaustionLevel) {
++ this.exhaustionLevel = exhaustionLevel;
+ }
+ }