From e28654cfb224933135d2027c1464ac7270dbe51b Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 14 Dec 2024 11:29:09 -0800 Subject: [PATCH] net.minecraft.world.food --- .../minecraft/world/food/FoodData.java.patch | 77 +++++++------------ .../world/food/FoodProperties.java.patch | 11 +++ .../world/food/FoodProperties.java.patch | 19 ----- 3 files changed, 39 insertions(+), 68 deletions(-) rename paper-server/patches/{unapplied => sources}/net/minecraft/world/food/FoodData.java.patch (50%) create mode 100644 paper-server/patches/sources/net/minecraft/world/food/FoodProperties.java.patch delete mode 100644 paper-server/patches/unapplied/net/minecraft/world/food/FoodProperties.java.patch diff --git a/paper-server/patches/unapplied/net/minecraft/world/food/FoodData.java.patch b/paper-server/patches/sources/net/minecraft/world/food/FoodData.java.patch similarity index 50% rename from paper-server/patches/unapplied/net/minecraft/world/food/FoodData.java.patch rename to paper-server/patches/sources/net/minecraft/world/food/FoodData.java.patch index 68a35b8aa4..b18d67421a 100644 --- a/paper-server/patches/unapplied/net/minecraft/world/food/FoodData.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/food/FoodData.java.patch @@ -1,22 +1,6 @@ --- a/net/minecraft/world/food/FoodData.java +++ b/net/minecraft/world/food/FoodData.java -@@ -1,11 +1,14 @@ - package net.minecraft.world.food; - -+import net.minecraft.world.level.GameRules; - import net.minecraft.nbt.CompoundTag; -+import net.minecraft.network.protocol.game.ClientboundSetHealthPacket; - import net.minecraft.server.level.ServerLevel; - import net.minecraft.server.level.ServerPlayer; - import net.minecraft.util.Mth; - import net.minecraft.world.Difficulty; --import net.minecraft.world.level.GameRules; -+import net.minecraft.world.item.ItemStack; -+// CraftBukkit end - - public class FoodData { - -@@ -13,6 +16,11 @@ +@@ -12,6 +_,11 @@ public float saturationLevel = 5.0F; public float exhaustionLevel; private int tickTimer; @@ -26,33 +10,30 @@ + public int starvationRate = 80; + // CraftBukkit end - public FoodData() {} - -@@ -29,6 +37,20 @@ - this.add(foodComponent.nutrition(), foodComponent.saturation()); + private void add(int foodLevel, float saturationLevel) { + this.foodLevel = Mth.clamp(foodLevel + this.foodLevel, 0, 20); +@@ -26,6 +_,17 @@ + this.add(foodProperties.nutrition(), foodProperties.saturation()); } + // CraftBukkit start -+ public void eat(FoodProperties foodinfo, ItemStack itemstack, ServerPlayer entityplayer) { ++ public void eat(FoodProperties foodProperties, net.minecraft.world.item.ItemStack stack, ServerPlayer serverPlayer) { + int oldFoodLevel = this.foodLevel; -+ -+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityplayer, foodinfo.nutrition() + oldFoodLevel, itemstack); -+ ++ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(serverPlayer, foodProperties.nutrition() + oldFoodLevel, stack); + if (!event.isCancelled()) { -+ this.add(event.getFoodLevel() - oldFoodLevel, foodinfo.saturation()); ++ this.add(event.getFoodLevel() - oldFoodLevel, foodProperties.saturation()); + } -+ -+ entityplayer.getBukkitEntity().sendHealthUpdate(); ++ serverPlayer.getBukkitEntity().sendHealthUpdate(); + } + // CraftBukkit end + public void tick(ServerPlayer player) { - ServerLevel worldserver = player.serverLevel(); - Difficulty enumdifficulty = worldserver.getDifficulty(); -@@ -38,7 +60,15 @@ + ServerLevel serverLevel = player.serverLevel(); + Difficulty difficulty = serverLevel.getDifficulty(); +@@ -34,29 +_,39 @@ if (this.saturationLevel > 0.0F) { this.saturationLevel = Math.max(this.saturationLevel - 1.0F, 0.0F); - } else if (enumdifficulty != Difficulty.PEACEFUL) { + } else if (difficulty != Difficulty.PEACEFUL) { - this.foodLevel = Math.max(this.foodLevel - 1, 0); + // CraftBukkit start + org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(player, Math.max(this.foodLevel - 1, 0)); @@ -61,28 +42,26 @@ + this.foodLevel = event.getFoodLevel(); + } + -+ player.connection.send(new ClientboundSetHealthPacket(player.getBukkitEntity().getScaledHealth(), this.foodLevel, this.saturationLevel)); ++ player.connection.send(new net.minecraft.network.protocol.game.ClientboundSetHealthPacket(player.getBukkitEntity().getScaledHealth(), this.foodLevel, this.saturationLevel)); + // CraftBukkit end } } -@@ -46,23 +76,25 @@ - - if (flag && this.saturationLevel > 0.0F && player.isHurt() && this.foodLevel >= 20) { - ++this.tickTimer; + boolean _boolean = serverLevel.getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION); + if (_boolean && 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, true); // CraftBukkit - added RegainReason // Paper - This is fast regen -+ // this.addExhaustion(f); CraftBukkit - EntityExhaustionEvent -+ player.causeFoodExhaustion(f, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent + float min = Math.min(this.saturationLevel, 6.0F); +- player.heal(min / 6.0F); +- this.addExhaustion(min); ++ player.heal(min / 6.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED, true); // CraftBukkit - added RegainReason // Paper - This is fast regen ++ // this.addExhaustion(min); CraftBukkit - EntityExhaustionEvent ++ player.causeFoodExhaustion(min, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent this.tickTimer = 0; } - } else if (flag && this.foodLevel >= 18 && player.isHurt()) { - ++this.tickTimer; + } else if (_boolean && this.foodLevel >= 18 && player.isHurt()) { + this.tickTimer++; - if (this.tickTimer >= 80) { - player.heal(1.0F); - this.addExhaustion(6.0F); @@ -93,9 +72,9 @@ this.tickTimer = 0; } } else if (this.foodLevel <= 0) { - ++this.tickTimer; + this.tickTimer++; - if (this.tickTimer >= 80) { + 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.hurtServer(worldserver, player.damageSources().starve(), 1.0F); + if (player.getHealth() > 10.0F || difficulty == Difficulty.HARD || player.getHealth() > 1.0F && difficulty == Difficulty.NORMAL) { + player.hurtServer(serverLevel, player.damageSources().starve(), 1.0F); } diff --git a/paper-server/patches/sources/net/minecraft/world/food/FoodProperties.java.patch b/paper-server/patches/sources/net/minecraft/world/food/FoodProperties.java.patch new file mode 100644 index 0000000000..d6ade19bb4 --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/food/FoodProperties.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/world/food/FoodProperties.java ++++ b/net/minecraft/world/food/FoodProperties.java +@@ -41,7 +_,7 @@ + RandomSource random = entity.getRandom(); + level.playSound(null, entity.getX(), entity.getY(), entity.getZ(), consumable.sound().value(), SoundSource.NEUTRAL, 1.0F, random.triangle(1.0F, 0.4F)); + if (entity instanceof Player player) { +- player.getFoodData().eat(this); ++ player.getFoodData().eat(this, stack, (net.minecraft.server.level.ServerPlayer) player); // CraftBukkit + level.playSound( + null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_BURP, SoundSource.PLAYERS, 0.5F, Mth.randomBetween(random, 0.9F, 1.0F) + ); diff --git a/paper-server/patches/unapplied/net/minecraft/world/food/FoodProperties.java.patch b/paper-server/patches/unapplied/net/minecraft/world/food/FoodProperties.java.patch deleted file mode 100644 index a8c85757de..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/world/food/FoodProperties.java.patch +++ /dev/null @@ -1,19 +0,0 @@ ---- a/net/minecraft/world/food/FoodProperties.java -+++ b/net/minecraft/world/food/FoodProperties.java -@@ -5,6 +5,7 @@ - import net.minecraft.network.RegistryFriendlyByteBuf; - import net.minecraft.network.codec.ByteBufCodecs; - import net.minecraft.network.codec.StreamCodec; -+import net.minecraft.server.level.ServerPlayer; - import net.minecraft.sounds.SoundEvent; - import net.minecraft.sounds.SoundEvents; - import net.minecraft.sounds.SoundSource; -@@ -31,7 +32,7 @@ - - world.playSound((Player) null, user.getX(), user.getY(), user.getZ(), (SoundEvent) consumable.sound().value(), SoundSource.NEUTRAL, 1.0F, randomsource.triangle(1.0F, 0.4F)); - if (user instanceof Player entityhuman) { -- entityhuman.getFoodData().eat(this); -+ entityhuman.getFoodData().eat(this, stack, (ServerPlayer) entityhuman); // CraftBukkit - world.playSound((Player) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEvents.PLAYER_BURP, SoundSource.PLAYERS, 0.5F, Mth.randomBetween(randomsource, 0.9F, 1.0F)); - } -