From 4806ce5cd5755bb3323d27b1302b282f5c9316a3 Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Wed, 4 Dec 2024 21:05:57 +0100 Subject: [PATCH] properly override push/knockback methods This prevent the creaking from being pushed with knockback enchant when it can't move --- patches/api/0053-Fix-upstream-javadocs.patch | 29 ++++++++-- .../0166-Fix-Spigot-annotation-mistakes.patch | 4 +- patches/api/0468-General-ItemMeta-fixes.patch | 4 +- ...CanPlaceOn-and-CanDestroy-NBT-values.patch | 4 +- .../0200-Add-entity-knockback-events.patch | 54 ++++++++++++++++--- .../server/0240-Improve-death-events.patch | 4 +- ...date-ResourceLocation-in-NBT-reading.patch | 14 +++-- 7 files changed, 86 insertions(+), 27 deletions(-) diff --git a/patches/api/0053-Fix-upstream-javadocs.patch b/patches/api/0053-Fix-upstream-javadocs.patch index 47f0cd7be5..a18698396f 100644 --- a/patches/api/0053-Fix-upstream-javadocs.patch +++ b/patches/api/0053-Fix-upstream-javadocs.patch @@ -1622,10 +1622,31 @@ index 35c6594fd1040a1af1029e7260e5e3a9307b107d..d58719ee75bef8bc265bfc81bc5d88a4 void addChargedProjectile(@NotNull ItemStack item); } diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java -index 77f0e0a9e991f65b89909d0307fd93c3ecd9d8ac..5cc1d77a09d2877992433b020ad2c591bb94d3fd 100644 +index 77f0e0a9e991f65b89909d0307fd93c3ecd9d8ac..66315ae78d6143ac6bde2b3a2b40b617dc4b1aab 100644 --- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java +++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java -@@ -767,7 +767,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste +@@ -293,7 +293,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste + /** + * Gets the enchantable component. Higher values allow higher enchantments. + * +- * @return max_stack_size ++ * @return the enchantable value + */ + int getEnchantable(); + +@@ -626,11 +626,6 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste + + /** + * Gets the item which this item will convert to when used. +- *

+- * The returned component is a snapshot of its current state and does not +- * reflect a live view of what is on an item. After changing any value on +- * this component, it must be set with {@link #setUseRemainder(ItemStack)} +- * to apply the changes. + * + * @return remainder + */ +@@ -767,7 +762,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste * The returned component is a snapshot of its current state and does not * reflect a live view of what is on an item. After changing any value on * this component, it must be set with @@ -1634,7 +1655,7 @@ index 77f0e0a9e991f65b89909d0307fd93c3ecd9d8ac..5cc1d77a09d2877992433b020ad2c591 * to apply the changes. * * @return component -@@ -776,7 +776,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste +@@ -776,7 +771,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste JukeboxPlayableComponent getJukeboxPlayable(); /** @@ -1643,7 +1664,7 @@ index 77f0e0a9e991f65b89909d0307fd93c3ecd9d8ac..5cc1d77a09d2877992433b020ad2c591 * * @param jukeboxPlayable new component */ -@@ -803,7 +803,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste +@@ -803,7 +798,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste /** * Return an immutable copy of all {@link Attribute}s and their * {@link AttributeModifier}s for a given {@link EquipmentSlot}.
diff --git a/patches/api/0166-Fix-Spigot-annotation-mistakes.patch b/patches/api/0166-Fix-Spigot-annotation-mistakes.patch index 25e0de3a4d..03b04b5bf8 100644 --- a/patches/api/0166-Fix-Spigot-annotation-mistakes.patch +++ b/patches/api/0166-Fix-Spigot-annotation-mistakes.patch @@ -1748,7 +1748,7 @@ index 597a18a767b68b47e81454b7d44613c7178c1366..bc3440eb72127824b3961fbdae583bb6 public ItemStack getInput() { return this.ingredient.getItemStack(); diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java -index 5cc1d77a09d2877992433b020ad2c591bb94d3fd..eb14949da2b96aee75e3bba63af8176c5550a380 100644 +index 66315ae78d6143ac6bde2b3a2b40b617dc4b1aab..b770541429649cefed3f7f907cc1d9653e395937 100644 --- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java +++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java @@ -152,6 +152,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste @@ -1775,7 +1775,7 @@ index 5cc1d77a09d2877992433b020ad2c591bb94d3fd..eb14949da2b96aee75e3bba63af8176c * @param name the name to set * @deprecated meta no longer exists */ -@@ -772,7 +775,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste +@@ -767,7 +770,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste * * @return component */ diff --git a/patches/api/0468-General-ItemMeta-fixes.patch b/patches/api/0468-General-ItemMeta-fixes.patch index c4c0a4ab53..e1700256bd 100644 --- a/patches/api/0468-General-ItemMeta-fixes.patch +++ b/patches/api/0468-General-ItemMeta-fixes.patch @@ -112,7 +112,7 @@ index ff6818b6d9e0207eafdd749928f33aeac3f27191..992f39da07bafe9769effaa7dc6adc01 * Checks to see if this item has a maximum amount of damage. * diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java -index 0151a0523069b00a1cf682ad6b54142aaffcfaa6..7cfdeaafa31b0659cc51848346f5105eb82f8ec4 100644 +index e95eac71ab43cadccf99ff594cc77a6d364c46bd..f32102441df03645c1b8c80fdfc944018e5544ca 100644 --- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java +++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java @@ -351,7 +351,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste @@ -124,7 +124,7 @@ index 0151a0523069b00a1cf682ad6b54142aaffcfaa6..7cfdeaafa31b0659cc51848346f5105e */ void setEnchantable(@Nullable Integer enchantable); -@@ -900,8 +900,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste +@@ -895,8 +895,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste /** * Set all {@link Attribute}s and their {@link AttributeModifier}s. diff --git a/patches/api/0478-Add-an-API-for-CanPlaceOn-and-CanDestroy-NBT-values.patch b/patches/api/0478-Add-an-API-for-CanPlaceOn-and-CanDestroy-NBT-values.patch index c31c3a1007..083f89e1ed 100644 --- a/patches/api/0478-Add-an-API-for-CanPlaceOn-and-CanDestroy-NBT-values.patch +++ b/patches/api/0478-Add-an-API-for-CanPlaceOn-and-CanDestroy-NBT-values.patch @@ -228,10 +228,10 @@ index 6d266c111bfa2bd51338e03ed740f6ac81ed07c7..d71531c384c57ea44d1e1fbe394214c1 return key; } diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java -index 7cfdeaafa31b0659cc51848346f5105eb82f8ec4..2f0a775a6754554b00ad9140886da9b0101acaf5 100644 +index f32102441df03645c1b8c80fdfc944018e5544ca..403c4e7138bcee1321b16fb3aa4cffb2178d4757 100644 --- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java +++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java -@@ -1033,4 +1033,98 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste +@@ -1028,4 +1028,98 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste @SuppressWarnings("javadoc") @NotNull ItemMeta clone(); diff --git a/patches/server/0200-Add-entity-knockback-events.patch b/patches/server/0200-Add-entity-knockback-events.patch index acd8ec13b9..c7ea2a1e08 100644 --- a/patches/server/0200-Add-entity-knockback-events.patch +++ b/patches/server/0200-Add-entity-knockback-events.patch @@ -11,7 +11,7 @@ Co-authored-by: aerulion Co-authored-by: Jake Potrebic diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index 9175c61a5c0b8a79c46869649320beaf731a2ab4..3c29f5e1338754728e1acb4676526945b1e7f67c 100644 +index 9175c61a5c0b8a79c46869649320beaf731a2ab4..8d2618d82ca37ef084cec2cdcb5423d806d6ddea 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -2074,7 +2074,21 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess @@ -23,7 +23,7 @@ index 9175c61a5c0b8a79c46869649320beaf731a2ab4..3c29f5e1338754728e1acb4676526945 + this.push(deltaX, deltaY, deltaZ, null); + } + -+ public void push(double deltaX, double deltaY, double deltaZ, @org.jetbrains.annotations.Nullable Entity pushingEntity) { ++ public void push(double deltaX, double deltaY, double deltaZ, @Nullable Entity pushingEntity) { + org.bukkit.util.Vector delta = new org.bukkit.util.Vector(deltaX, deltaY, deltaZ); + if (pushingEntity != null) { + io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent event = new io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent(this.getBukkitEntity(), io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.PUSH, pushingEntity.getBukkitEntity(), delta); @@ -158,7 +158,7 @@ index 19f9f4bceca158d9b35be2cdc4d7aa502f44a4b9..cd0a2270b58b6c0dba67270e7e1d1ba2 if (world instanceof ServerLevel worldserver) { diff --git a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java -index 6a90feef8eb2d65c925c44bc97305a51e3fb7cf0..7dfbcb2ed831cff5d002d79fb81514e6abf587a4 100644 +index 6a90feef8eb2d65c925c44bc97305a51e3fb7cf0..2597f203662cf239f81bd3c75ed70eafbf951169 100644 --- a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java +++ b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java @@ -129,9 +129,9 @@ public class ItemFrame extends HangingEntity { @@ -166,7 +166,7 @@ index 6a90feef8eb2d65c925c44bc97305a51e3fb7cf0..7dfbcb2ed831cff5d002d79fb81514e6 @Override - public void push(double deltaX, double deltaY, double deltaZ) { -+ public void push(double deltaX, double deltaY, double deltaZ, @org.jetbrains.annotations.Nullable Entity pushingEntity) { // Paper - add push source entity param ++ public void push(double deltaX, double deltaY, double deltaZ, @Nullable Entity pushingEntity) { // Paper - add push source entity param if (!this.fixed) { - super.push(deltaX, deltaY, deltaZ); + super.push(deltaX, deltaY, deltaZ, pushingEntity); // Paper - add push source entity param @@ -186,6 +186,34 @@ index 1d15465069c8aa57fa89521a8e75c1aeb1cfc096..6c909ea334310f1f9b2d9a2e2cc2f23f } @Override +diff --git a/src/main/java/net/minecraft/world/entity/monster/creaking/Creaking.java b/src/main/java/net/minecraft/world/entity/monster/creaking/Creaking.java +index bdf2b22f3f57e99ad7bbc24d391c7773663fda41..6a7e725edece3043c8523d387e2929d5ba8932cb 100644 +--- a/src/main/java/net/minecraft/world/entity/monster/creaking/Creaking.java ++++ b/src/main/java/net/minecraft/world/entity/monster/creaking/Creaking.java +@@ -198,9 +198,9 @@ public class Creaking extends Monster { + } + + @Override +- public void push(double deltaX, double deltaY, double deltaZ) { ++ public void push(double deltaX, double deltaY, double deltaZ, @Nullable Entity pushingEntity) { // Paper - add push source entity param + if (this.canMove()) { +- super.push(deltaX, deltaY, deltaZ); ++ super.push(deltaX, deltaY, deltaZ, pushingEntity); // Paper - add push source entity param + } + } + +@@ -502,9 +502,9 @@ public class Creaking extends Monster { + } + + @Override +- public void knockback(double strength, double x, double z) { ++ public void knockback(double strength, double x, double z, @Nullable Entity attacker, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause cause) { // Paper - knockback events + if (this.canMove()) { +- super.knockback(strength, x, z); ++ super.knockback(strength, x, z, attacker, cause); // Paper - knockback events + } + } + diff --git a/src/main/java/net/minecraft/world/entity/monster/hoglin/HoglinBase.java b/src/main/java/net/minecraft/world/entity/monster/hoglin/HoglinBase.java index 8b80f5c2749106f634d962fd0f381aa20e7ef335..a1e3375519fe676b14788d6729a7e71d089cca37 100644 --- a/src/main/java/net/minecraft/world/entity/monster/hoglin/HoglinBase.java @@ -225,9 +253,21 @@ index 3c02f29b3114220b2634d69b413a6724ee4cfdf8..02d8ada43669134695e7edcf33fdac45 Level world = this.level(); diff --git a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java -index dd115d514aeb3d124bc99456044f7d176850acab..a05fc651a952b57a8a2fcb32d26d024875037d38 100644 +index dd115d514aeb3d124bc99456044f7d176850acab..2b4df4e417b5655341a640a1c133457f78338970 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java +++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java +@@ -410,9 +410,9 @@ public abstract class AbstractArrow extends Projectile { + } + + @Override +- public void push(double deltaX, double deltaY, double deltaZ) { ++ public void push(double deltaX, double deltaY, double deltaZ, @Nullable Entity pushingEntity) { // Paper - add push source entity param + if (!this.isInGround()) { +- super.push(deltaX, deltaY, deltaZ); ++ super.push(deltaX, deltaY, deltaZ, pushingEntity); // Paper - add push source entity param + } + } + @@ -568,7 +568,7 @@ public abstract class AbstractArrow extends Projectile { Vec3 vec3d = this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D).normalize().scale(d0 * 0.6D * d1); @@ -238,7 +278,7 @@ index dd115d514aeb3d124bc99456044f7d176850acab..a05fc651a952b57a8a2fcb32d26d0248 } diff --git a/src/main/java/net/minecraft/world/entity/projectile/windcharge/AbstractWindCharge.java b/src/main/java/net/minecraft/world/entity/projectile/windcharge/AbstractWindCharge.java -index dd14e76ca0813e19a7a531e9009b8f156ae8d896..8022d2d9415d8b2dedee2db0e4f1f0aab8c55bde 100644 +index dd14e76ca0813e19a7a531e9009b8f156ae8d896..821c1236901ca0a7d7e0d4c12a69f69e2b5c4363 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/windcharge/AbstractWindCharge.java +++ b/src/main/java/net/minecraft/world/entity/projectile/windcharge/AbstractWindCharge.java @@ -101,7 +101,7 @@ public abstract class AbstractWindCharge extends AbstractHurtingProjectile imple @@ -246,7 +286,7 @@ index dd14e76ca0813e19a7a531e9009b8f156ae8d896..8022d2d9415d8b2dedee2db0e4f1f0aa @Override - public void push(double deltaX, double deltaY, double deltaZ) {} -+ public void push(double deltaX, double deltaY, double deltaZ, @org.jetbrains.annotations.Nullable Entity pushingEntity) {} // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent ++ public void push(double deltaX, double deltaY, double deltaZ, @Nullable Entity pushingEntity) {} // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent public abstract void explode(Vec3 pos); diff --git a/patches/server/0240-Improve-death-events.patch b/patches/server/0240-Improve-death-events.patch index c5edd99375..6dadb58ee5 100644 --- a/patches/server/0240-Improve-death-events.patch +++ b/patches/server/0240-Improve-death-events.patch @@ -19,7 +19,7 @@ public net.minecraft.world.entity.LivingEntity getDeathSound()Lnet/minecraft/sou public net.minecraft.world.entity.LivingEntity getSoundVolume()F diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java -index 0a5aeb9b50dfec3b791040348f6a9e929ef8e59c..cec8e2b8867e348d8c92e76983211e29edd46ed1 100644 +index 0a5aeb9b50dfec3b791040348f6a9e929ef8e59c..6c3569435cdfcf28acaa7b2dac8664dd14e3e6c2 100644 --- a/src/main/java/net/minecraft/server/level/ServerPlayer.java +++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java @@ -294,6 +294,10 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player { @@ -65,7 +65,7 @@ index 0a5aeb9b50dfec3b791040348f6a9e929ef8e59c..cec8e2b8867e348d8c92e76983211e29 - return super.hurtServer(world, source, amount); + // Paper start - cancellable death events -+ //return super.hurt(world, source, amount); ++ // return super.hurtServer(world, source, amount); + this.queueHealthUpdatePacket = true; + boolean damaged = super.hurtServer(world, source, amount); + this.queueHealthUpdatePacket = false; diff --git a/patches/server/0905-Validate-ResourceLocation-in-NBT-reading.patch b/patches/server/0905-Validate-ResourceLocation-in-NBT-reading.patch index 64686a7ba9..670efb3867 100644 --- a/patches/server/0905-Validate-ResourceLocation-in-NBT-reading.patch +++ b/patches/server/0905-Validate-ResourceLocation-in-NBT-reading.patch @@ -103,22 +103,20 @@ index 2715ba6325ecf82dee237bb53372e3aac3972112..95c2e2d73aefcf7c436fad3066e1fedc if (nbt.contains("Brain", 10)) { diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java -index 13064a73a9e3b45d32a098c4179cd980be508abc..8ac12520650501139d53f6db3ae1ee6417db7bb9 100644 +index 13064a73a9e3b45d32a098c4179cd980be508abc..a66ed6527d95b9c40b6c5983455fc078fd9eb2bf 100644 --- a/src/main/java/net/minecraft/world/entity/Mob.java +++ b/src/main/java/net/minecraft/world/entity/Mob.java -@@ -609,9 +609,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab +@@ -609,7 +609,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab this.readLeashData(nbt); this.setLeftHanded(nbt.getBoolean("LeftHanded")); if (nbt.contains("DeathLootTable", 8)) { - this.lootTable = Optional.of(ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.parse(nbt.getString("DeathLootTable")))); -- } else { -- this.lootTable = Optional.empty(); -+ this.lootTable = Optional.ofNullable(ResourceLocation.tryParse(nbt.getString("DeathLootTable"))).map((rs) -> ResourceKey.create(Registries.LOOT_TABLE, rs)); // Paper - Validate ResourceLocation } else { ++ this.lootTable = Optional.ofNullable(ResourceLocation.tryParse(nbt.getString("DeathLootTable"))).map((rs) -> ResourceKey.create(Registries.LOOT_TABLE, rs)); // Paper - Validate ResourceLocation + } else { + this.lootTable = Optional.empty(); } - - this.lootTableSeed = nbt.getLong("DeathLootTableSeed"); diff --git a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java -index 0abe2fe6d7cf0a2084b7219c3ab0c5118586a8fe..9c781ad45fd0295cc8ffe5ba901dc7a59ece06f2 100644 +index 758fa49f9b420fdbb583ca3443b81ca151478ea8..6edb5a76a503242a6528875184ccd62d6499205f 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java +++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java @@ -710,7 +710,7 @@ public abstract class AbstractArrow extends Projectile {