properly override push/knockback methods

This prevent the creaking from being pushed with knockback
enchant when it can't move
This commit is contained in:
Lulu13022002 2024-12-04 21:05:57 +01:00
parent f93c8c78db
commit 7d18cb068e
4 changed files with 68 additions and 9 deletions

View file

@ -1625,6 +1625,27 @@ diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/ja
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
+++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
@@ -0,0 +0,0 @@ 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();
@@ -0,0 +0,0 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
/**
* Gets the item which this item will convert to when used.
- * <p>
- * 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
*/
@@ -0,0 +0,0 @@ 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

View file

@ -23,7 +23,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ 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);
@ -166,7 +166,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@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 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
@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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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
@@ -0,0 +0,0 @@ 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
}
}
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/monster/hoglin/HoglinBase.java
@ -228,6 +256,18 @@ diff --git a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.j
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
@@ -0,0 +0,0 @@ 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
}
}
@@ -0,0 +0,0 @@ public abstract class AbstractArrow extends Projectile {
Vec3 vec3d = this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D).normalize().scale(d0 * 0.6D * d1);
@ -246,7 +286,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@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);

View file

@ -65,7 +65,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- 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;

View file

@ -111,12 +111,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java