Remap CraftBukkit to Mojang+Yarn Mappings

By: Initial Source <noreply+automated@papermc.io>
This commit is contained in:
CraftBukkit/Spigot
2024-12-11 22:26:55 +01:00
parent a265d64138
commit 30e4583dbe
1780 changed files with 44628 additions and 41274 deletions

View File

@@ -0,0 +1,101 @@
--- 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 @@
public float saturationLevel = 5.0F;
public float exhaustionLevel;
private int tickTimer;
+ // CraftBukkit start
+ public int saturatedRegenRate = 10;
+ public int unsaturatedRegenRate = 80;
+ public int starvationRate = 80;
+ // CraftBukkit end
public FoodData() {}
@@ -29,6 +37,20 @@
this.add(foodComponent.nutrition(), foodComponent.saturation());
}
+ // CraftBukkit start
+ public void eat(FoodProperties foodinfo, ItemStack itemstack, ServerPlayer entityplayer) {
+ int oldFoodLevel = this.foodLevel;
+
+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityplayer, foodinfo.nutrition() + oldFoodLevel, itemstack);
+
+ if (!event.isCancelled()) {
+ this.add(event.getFoodLevel() - oldFoodLevel, foodinfo.saturation());
+ }
+
+ entityplayer.getBukkitEntity().sendHealthUpdate();
+ }
+ // CraftBukkit end
+
public void tick(ServerPlayer player) {
ServerLevel worldserver = player.serverLevel();
Difficulty enumdifficulty = worldserver.getDifficulty();
@@ -38,7 +60,15 @@
if (this.saturationLevel > 0.0F) {
this.saturationLevel = Math.max(this.saturationLevel - 1.0F, 0.0F);
} else if (enumdifficulty != 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));
+
+ if (!event.isCancelled()) {
+ this.foodLevel = event.getFoodLevel();
+ }
+
+ player.connection.send(new 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;
- 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.addExhaustion(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 (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);
}

View File

@@ -1,22 +0,0 @@
--- a/net/minecraft/world/food/FoodInfo.java
+++ b/net/minecraft/world/food/FoodInfo.java
@@ -18,6 +18,10 @@
import net.minecraft.world.item.component.ConsumableListener;
import net.minecraft.world.level.World;
+// CraftBukkit start
+import net.minecraft.server.level.EntityPlayer;
+// CraftBukkit end
+
public record FoodInfo(int nutrition, float saturation, boolean canAlwaysEat) implements ConsumableListener {
public static final Codec<FoodInfo> DIRECT_CODEC = RecordCodecBuilder.create((instance) -> {
@@ -31,7 +35,7 @@
world.playSound((EntityHuman) null, entityliving.getX(), entityliving.getY(), entityliving.getZ(), (SoundEffect) consumable.sound().value(), SoundCategory.NEUTRAL, 1.0F, randomsource.triangle(1.0F, 0.4F));
if (entityliving instanceof EntityHuman entityhuman) {
- entityhuman.getFoodData().eat(this);
+ entityhuman.getFoodData().eat(this, itemstack, (EntityPlayer) entityhuman); // CraftBukkit
world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, MathHelper.randomBetween(randomsource, 0.9F, 1.0F));
}

View File

@@ -1,96 +0,0 @@
--- a/net/minecraft/world/food/FoodMetaData.java
+++ b/net/minecraft/world/food/FoodMetaData.java
@@ -7,12 +7,22 @@
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.level.GameRules;
+// CraftBukkit start
+import net.minecraft.network.protocol.game.PacketPlayOutUpdateHealth;
+import net.minecraft.world.item.ItemStack;
+// CraftBukkit end
+
public class FoodMetaData {
public int foodLevel = 20;
public float saturationLevel = 5.0F;
public float exhaustionLevel;
private int tickTimer;
+ // CraftBukkit start
+ public int saturatedRegenRate = 10;
+ public int unsaturatedRegenRate = 80;
+ public int starvationRate = 80;
+ // CraftBukkit end
public FoodMetaData() {}
@@ -29,6 +39,20 @@
this.add(foodinfo.nutrition(), foodinfo.saturation());
}
+ // CraftBukkit start
+ public void eat(FoodInfo foodinfo, ItemStack itemstack, EntityPlayer entityplayer) {
+ int oldFoodLevel = foodLevel;
+
+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityplayer, foodinfo.nutrition() + oldFoodLevel, itemstack);
+
+ if (!event.isCancelled()) {
+ this.add(event.getFoodLevel() - oldFoodLevel, foodinfo.saturation());
+ }
+
+ entityplayer.getBukkitEntity().sendHealthUpdate();
+ }
+ // CraftBukkit end
+
public void tick(EntityPlayer entityplayer) {
WorldServer worldserver = entityplayer.serverLevel();
EnumDifficulty enumdifficulty = worldserver.getDifficulty();
@@ -38,7 +62,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(entityplayer, Math.max(this.foodLevel - 1, 0));
+
+ if (!event.isCancelled()) {
+ this.foodLevel = event.getFoodLevel();
+ }
+
+ entityplayer.connection.send(new PacketPlayOutUpdateHealth(entityplayer.getBukkitEntity().getScaledHealth(), this.foodLevel, this.saturationLevel));
+ // CraftBukkit end
}
}
@@ -46,23 +78,25 @@
if (flag && this.saturationLevel > 0.0F && entityplayer.isHurt() && this.foodLevel >= 20) {
++this.tickTimer;
- if (this.tickTimer >= 10) {
+ if (this.tickTimer >= this.saturatedRegenRate) { // CraftBukkit
float f = Math.min(this.saturationLevel, 6.0F);
- entityplayer.heal(f / 6.0F);
- this.addExhaustion(f);
+ entityplayer.heal(f / 6.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason
+ // this.addExhaustion(f); CraftBukkit - EntityExhaustionEvent
+ entityplayer.causeFoodExhaustion(f, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent
this.tickTimer = 0;
}
} else if (flag && this.foodLevel >= 18 && entityplayer.isHurt()) {
++this.tickTimer;
- if (this.tickTimer >= 80) {
- entityplayer.heal(1.0F);
- this.addExhaustion(6.0F);
+ if (this.tickTimer >= this.unsaturatedRegenRate) { // CraftBukkit - add regen rate manipulation
+ entityplayer.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason
+ // this.addExhaustion(6.0F); CraftBukkit - EntityExhaustionEvent
+ entityplayer.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 (entityplayer.getHealth() > 10.0F || enumdifficulty == EnumDifficulty.HARD || entityplayer.getHealth() > 1.0F && enumdifficulty == EnumDifficulty.NORMAL) {
entityplayer.hurtServer(worldserver, entityplayer.damageSources().starve(), 1.0F);
}

View File

@@ -0,0 +1,19 @@
--- 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));
}