mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-18 04:39:24 +01:00
4806ce5cd5
This prevent the creaking from being pushed with knockback enchant when it can't move
359 lines
26 KiB
Diff
359 lines
26 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Brokkonaut <hannos17@gmx.de>
|
|
Date: Mon, 18 Jun 2018 15:46:23 +0200
|
|
Subject: [PATCH] Add entity knockback events
|
|
|
|
- EntityKnockbackEvent
|
|
- EntityPushedByEntityAttackEvent
|
|
- EntityKnockbackByEntityEvent
|
|
|
|
Co-authored-by: aerulion <aerulion@gmail.com>
|
|
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
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
|
|
}
|
|
|
|
public void push(double deltaX, double deltaY, double deltaZ) {
|
|
- this.setDeltaMovement(this.getDeltaMovement().add(deltaX, deltaY, deltaZ));
|
|
+ // Paper start - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
|
|
+ this.push(deltaX, deltaY, deltaZ, null);
|
|
+ }
|
|
+
|
|
+ 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);
|
|
+ if (!event.callEvent()) {
|
|
+ return;
|
|
+ }
|
|
+ delta = event.getKnockback();
|
|
+ }
|
|
+ this.setDeltaMovement(this.getDeltaMovement().add(delta.getX(), delta.getY(), delta.getZ()));
|
|
+ // Paper end - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
|
|
this.hasImpulse = true;
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
index 9d0b7fc2e6beee1acb28a0dd473023beaafd86e5..5fef8dad5469a1e9409700614a1c861547e42bc7 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -1531,7 +1531,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
d1 = source.getSourcePosition().z() - this.getZ();
|
|
}
|
|
|
|
- this.knockback(0.4000000059604645D, d0, d1, entity1, entity1 == null ? EntityKnockbackEvent.KnockbackCause.DAMAGE : EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); // CraftBukkit
|
|
+ this.knockback(0.4000000059604645D, d0, d1, entity1, entity1 == null ? io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.DAMAGE : io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK); // CraftBukkit // Paper - knockback events
|
|
if (!flag) {
|
|
this.indicateDamage(d0, d1);
|
|
}
|
|
@@ -1631,7 +1631,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
}
|
|
|
|
protected void blockedByShield(LivingEntity target) {
|
|
- target.knockback(0.5D, target.getX() - this.getX(), target.getZ() - this.getZ(), null, EntityKnockbackEvent.KnockbackCause.SHIELD_BLOCK); // CraftBukkit
|
|
+ target.knockback(0.5D, target.getX() - this.getX(), target.getZ() - this.getZ(), this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.SHIELD_BLOCK); // CraftBukkit // Paper - fix attacker & knockback events
|
|
}
|
|
|
|
private boolean checkTotemDeathProtection(DamageSource source) {
|
|
@@ -1917,10 +1917,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
|
|
public void knockback(double strength, double x, double z) {
|
|
// CraftBukkit start - EntityKnockbackEvent
|
|
- this.knockback(strength, x, z, null, EntityKnockbackEvent.KnockbackCause.UNKNOWN);
|
|
+ this.knockback(strength, x, z, null, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.UNKNOWN); // Paper - knockback events
|
|
}
|
|
|
|
- public void knockback(double d0, double d1, double d2, Entity attacker, EntityKnockbackEvent.KnockbackCause cause) {
|
|
+ public void knockback(double d0, double d1, double d2, @Nullable Entity attacker, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause cause) { // Paper - knockback events
|
|
d0 *= 1.0D - this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE);
|
|
if (true || d0 > 0.0D) { // CraftBukkit - Call event even when force is 0
|
|
//this.hasImpulse = true; // CraftBukkit - Move down
|
|
@@ -1933,13 +1933,17 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
|
|
Vec3 vec3d1 = (new Vec3(d1, 0.0D, d2)).normalize().scale(d0);
|
|
|
|
- EntityKnockbackEvent event = CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) this.getBukkitEntity(), attacker, cause, d0, vec3d1, vec3d.x / 2.0D - vec3d1.x, this.onGround() ? Math.min(0.4D, vec3d.y / 2.0D + d0) : vec3d.y, vec3d.z / 2.0D - vec3d1.z);
|
|
+ // Paper start - knockback events
|
|
+ Vec3 finalVelocity = new Vec3(vec3d.x / 2.0D - vec3d1.x, this.onGround() ? Math.min(0.4D, vec3d.y / 2.0D + d0) : vec3d.y, vec3d.z / 2.0D - vec3d1.z);
|
|
+ Vec3 diff = finalVelocity.subtract(vec3d);
|
|
+ io.papermc.paper.event.entity.EntityKnockbackEvent event = CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) this.getBukkitEntity(), attacker, attacker, cause, d0, diff);
|
|
+ // Paper end - knockback events
|
|
if (event.isCancelled()) {
|
|
return;
|
|
}
|
|
|
|
this.hasImpulse = true;
|
|
- this.setDeltaMovement(event.getFinalKnockback().getX(), event.getFinalKnockback().getY(), event.getFinalKnockback().getZ());
|
|
+ this.setDeltaMovement(vec3d.add(event.getKnockback().getX(), event.getKnockback().getY(), event.getKnockback().getZ())); // Paper - knockback events
|
|
// CraftBukkit end
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
index f568ccec14cac96efa03dc888a4a2a0067515b39..6d1f840a328a2081a59aab923595450eb54f685c 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
@@ -1684,7 +1684,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
|
|
if (f1 > 0.0F && target instanceof LivingEntity) {
|
|
entityliving = (LivingEntity) target;
|
|
- entityliving.knockback((double) (f1 * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this, org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); // CraftBukkit
|
|
+ entityliving.knockback((double) (f1 * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK); // CraftBukkit // Paper - knockback events
|
|
this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D));
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/RamTarget.java b/src/main/java/net/minecraft/world/entity/ai/behavior/RamTarget.java
|
|
index 8bf5f18b5835ac97114dfea7dde3876c13433ab4..de81e34cf65318fa5e3034405719ff2a2b05458c 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/RamTarget.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/RamTarget.java
|
|
@@ -89,7 +89,7 @@ public class RamTarget extends Behavior<Goat> {
|
|
float f = 0.25F * (float)(i - j);
|
|
float g = Mth.clamp(entity.getSpeed() * 1.65F, 0.2F, 3.0F) + f;
|
|
float h = livingEntity.isDamageSourceBlocked(world.damageSources().mobAttack(entity)) ? 0.5F : 1.0F;
|
|
- livingEntity.knockback((double)(h * g) * this.getKnockbackForce.applyAsDouble(entity), this.ramDirection.x(), this.ramDirection.z());
|
|
+ livingEntity.knockback(h * g * this.getKnockbackForce.applyAsDouble(entity), this.ramDirection.x(), this.ramDirection.z(), entity, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
|
|
this.finishRam(world, entity);
|
|
world.playSound(null, entity, this.getImpactSound.apply(entity), SoundSource.NEUTRAL, 1.0F, 1.0F);
|
|
} else if (this.hasRammedHornBreakingBlock(world, entity)) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/warden/SonicBoom.java b/src/main/java/net/minecraft/world/entity/ai/behavior/warden/SonicBoom.java
|
|
index dbae113f3447f66e154b302ce0634b0fe446381c..d0fb32feb10f75444e3ed0a50c70ef6f12fb8e18 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/warden/SonicBoom.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/warden/SonicBoom.java
|
|
@@ -83,7 +83,7 @@ public class SonicBoom extends Behavior<Warden> {
|
|
if (target.hurtServer(world, world.damageSources().sonicBoom(entity), 10.0F)) {
|
|
double d = 0.5 * (1.0 - target.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE));
|
|
double e = 2.5 * (1.0 - target.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE));
|
|
- target.push(vec33.x() * e, vec33.y() * d, vec33.z() * e);
|
|
+ target.push(vec33.x() * e, vec33.y() * d, vec33.z() * e, entity); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
|
|
}
|
|
});
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
|
|
index f10d0a03c2bb6487dd05869e05258276bfcec7eb..6e2e570aa1c85eced9ed9578188db43df132a290 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
|
|
@@ -441,7 +441,7 @@ public class EnderDragon extends Mob implements Enemy {
|
|
double d3 = entity.getZ() - d1;
|
|
double d4 = Math.max(d2 * d2 + d3 * d3, 0.1D);
|
|
|
|
- entity.push(d2 / d4 * 4.0D, 0.20000000298023224D, d3 / d4 * 4.0D);
|
|
+ entity.push(d2 / d4 * 4.0D, 0.20000000298023224D, d3 / d4 * 4.0D, this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
|
|
if (!this.phaseManager.getCurrentPhase().isSitting() && entityliving.getLastHurtByMobTimestamp() < entity.tickCount - 2) {
|
|
DamageSource damagesource = this.damageSources().mobAttack(this);
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/decoration/BlockAttachedEntity.java b/src/main/java/net/minecraft/world/entity/decoration/BlockAttachedEntity.java
|
|
index 19f9f4bceca158d9b35be2cdc4d7aa502f44a4b9..cd0a2270b58b6c0dba67270e7e1d1ba253eb7953 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/decoration/BlockAttachedEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/decoration/BlockAttachedEntity.java
|
|
@@ -161,7 +161,7 @@ public abstract class BlockAttachedEntity extends Entity {
|
|
}
|
|
|
|
@Override
|
|
- public void push(double deltaX, double deltaY, double deltaZ) {
|
|
+ public void push(double deltaX, double deltaY, double deltaZ, @Nullable Entity pushingEntity) { // Paper - override correct overload
|
|
Level world = this.level();
|
|
|
|
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..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 {
|
|
}
|
|
|
|
@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.fixed) {
|
|
- super.push(deltaX, deltaY, deltaZ);
|
|
+ super.push(deltaX, deltaY, deltaZ, pushingEntity); // Paper - add push source entity param
|
|
}
|
|
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/monster/Ravager.java b/src/main/java/net/minecraft/world/entity/monster/Ravager.java
|
|
index 1d15465069c8aa57fa89521a8e75c1aeb1cfc096..6c909ea334310f1f9b2d9a2e2cc2f23f2badba37 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/Ravager.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/Ravager.java
|
|
@@ -289,7 +289,7 @@ public class Ravager extends Raider {
|
|
double d1 = entity.getZ() - this.getZ();
|
|
double d2 = Math.max(d0 * d0 + d1 * d1, 0.001D);
|
|
|
|
- entity.push(d0 / d2 * 4.0D, 0.2D, d1 / d2 * 4.0D);
|
|
+ entity.push(d0 / d2 * 4.0D, 0.2D, d1 / d2 * 4.0D, this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
|
|
}
|
|
|
|
@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
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/hoglin/HoglinBase.java
|
|
@@ -45,7 +45,7 @@ public interface HoglinBase {
|
|
double j = f * (double)(attacker.level().random.nextFloat() * 0.5F + 0.2F);
|
|
Vec3 vec3 = new Vec3(g, 0.0, h).normalize().scale(j).yRot(i);
|
|
double k = f * (double)attacker.level().random.nextFloat() * 0.5;
|
|
- target.push(vec3.x, k, vec3.z);
|
|
+ target.push(vec3.x, k, vec3.z, attacker); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
|
|
target.hurtMarked = true;
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
index 3c02f29b3114220b2634d69b413a6724ee4cfdf8..02d8ada43669134695e7edcf33fdac4599969f9d 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -1274,9 +1274,9 @@ public abstract class Player extends LivingEntity {
|
|
if (target instanceof LivingEntity) {
|
|
LivingEntity entityliving1 = (LivingEntity) target;
|
|
|
|
- entityliving1.knockback((double) (f5 * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)));
|
|
+ entityliving1.knockback((double) (f5 * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK); // Paper - knockback events
|
|
} else {
|
|
- target.push((double) (-Mth.sin(this.getYRot() * 0.017453292F) * f5 * 0.5F), 0.1D, (double) (Mth.cos(this.getYRot() * 0.017453292F) * f5 * 0.5F));
|
|
+ target.push((double) (-Mth.sin(this.getYRot() * 0.017453292F) * f5 * 0.5F), 0.1D, (double) (Mth.cos(this.getYRot() * 0.017453292F) * f5 * 0.5F), this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
|
|
}
|
|
|
|
this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D));
|
|
@@ -1304,7 +1304,7 @@ public abstract class Player extends LivingEntity {
|
|
continue;
|
|
}
|
|
// CraftBukkit end
|
|
- entityliving2.knockback(0.4000000059604645D, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)));
|
|
+ entityliving2.knockback(0.4000000059604645D, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.SWEEP_ATTACK); // CraftBukkit // Paper - knockback events
|
|
// entityliving2.hurt(damagesource, f7); // CraftBukkit - moved up
|
|
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..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);
|
|
|
|
if (vec3d.lengthSqr() > 0.0D) {
|
|
- target.push(vec3d.x, 0.1D, vec3d.z);
|
|
+ target.push(vec3d.x, 0.1D, vec3d.z, this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
|
|
}
|
|
}
|
|
|
|
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..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
|
|
}
|
|
|
|
@Override
|
|
- public void push(double deltaX, double deltaY, double deltaZ) {}
|
|
+ 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/src/main/java/net/minecraft/world/level/ServerExplosion.java b/src/main/java/net/minecraft/world/level/ServerExplosion.java
|
|
index e816e54daff781d54a94a007df5c59051347739d..fa22406002ae2c424b8eadbf78eabc2776f43945 100644
|
|
--- a/src/main/java/net/minecraft/world/level/ServerExplosion.java
|
|
+++ b/src/main/java/net/minecraft/world/level/ServerExplosion.java
|
|
@@ -258,13 +258,10 @@ public class ServerExplosion implements Explosion {
|
|
|
|
// CraftBukkit start - Call EntityKnockbackEvent
|
|
if (entity instanceof LivingEntity) {
|
|
- Vec3 result = entity.getDeltaMovement().add(vec3d);
|
|
- org.bukkit.event.entity.EntityKnockbackEvent event = CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) entity.getBukkitEntity(), this.source, org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause.EXPLOSION, d6, vec3d, result.x, result.y, result.z);
|
|
-
|
|
- // SPIGOT-7640: Need to subtract entity movement from the event result,
|
|
- // since the code below (the setDeltaMovement call as well as the hitPlayers map)
|
|
- // want the vector to be the relative velocity will the event provides the absolute velocity
|
|
- vec3d = (event.isCancelled()) ? Vec3.ZERO : new Vec3(event.getFinalKnockback().getX(), event.getFinalKnockback().getY(), event.getFinalKnockback().getZ()).subtract(entity.getDeltaMovement());
|
|
+ // Paper start - knockback events
|
|
+ io.papermc.paper.event.entity.EntityKnockbackEvent event = CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) entity.getBukkitEntity(), this.source, this.damageSource.getEntity() != null ? this.damageSource.getEntity() : this.source, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.EXPLOSION, d6, vec3d);
|
|
+ vec3d = event.isCancelled() ? Vec3.ZERO : org.bukkit.craftbukkit.util.CraftVector.toNMS(event.getKnockback());
|
|
+ // Paper end - knockback events
|
|
}
|
|
// CraftBukkit end
|
|
entity.push(vec3d);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
index f05a19f868be0d685c4fbf64e1dfbefda71131ac..60a16ac62a27a92b763bf90e72fab4ed01aeb592 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -1936,19 +1936,33 @@ public class CraftEventFactory {
|
|
return event;
|
|
}
|
|
|
|
- public static EntityKnockbackEvent callEntityKnockbackEvent(CraftLivingEntity entity, Entity attacker, EntityKnockbackEvent.KnockbackCause cause, double force, Vec3 raw, double x, double y, double z) {
|
|
- Vector bukkitRaw = new Vector(-raw.x, raw.y, -raw.z); // Due to how the knockback calculation works, we need to invert x and z.
|
|
+ // Paper start - replace knockback events
|
|
+ public static io.papermc.paper.event.entity.EntityKnockbackEvent callEntityKnockbackEvent(CraftLivingEntity entity, Entity pusher, Entity attacker, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause cause, double force, Vec3 knockback) {
|
|
+ Vector apiKnockback = CraftVector.toBukkit(knockback);
|
|
+
|
|
+ final Vector currentVelocity = entity.getVelocity();
|
|
+ final Vector legacyFinalKnockback = currentVelocity.clone().add(apiKnockback);
|
|
+ final org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause legacyCause = org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause.valueOf(cause.name());
|
|
+ EntityKnockbackEvent legacyEvent;
|
|
+ if (pusher != null) {
|
|
+ legacyEvent = new EntityKnockbackByEntityEvent(entity, pusher.getBukkitEntity(), legacyCause, force, apiKnockback, legacyFinalKnockback);
|
|
+ } else {
|
|
+ legacyEvent = new EntityKnockbackEvent(entity, legacyCause, force, apiKnockback, legacyFinalKnockback);
|
|
+ }
|
|
+ legacyEvent.callEvent();
|
|
|
|
- EntityKnockbackEvent event;
|
|
+ final io.papermc.paper.event.entity.EntityKnockbackEvent event;
|
|
+ apiKnockback = legacyEvent.getFinalKnockback().subtract(currentVelocity);
|
|
if (attacker != null) {
|
|
- event = new EntityKnockbackByEntityEvent(entity, attacker.getBukkitEntity(), cause, force, new Vector(-raw.x, raw.y, -raw.z), new Vector(x, y, z));
|
|
+ event = new com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent(entity, attacker.getBukkitEntity(), cause, (float) force, apiKnockback);
|
|
} else {
|
|
- event = new EntityKnockbackEvent(entity, cause, force, new Vector(-raw.x, raw.y, -raw.z), new Vector(x, y, z));
|
|
+ event = new io.papermc.paper.event.entity.EntityKnockbackEvent(entity, cause, apiKnockback);
|
|
}
|
|
-
|
|
- Bukkit.getPluginManager().callEvent(event);
|
|
+ event.setCancelled(legacyEvent.isCancelled());
|
|
+ event.callEvent();
|
|
return event;
|
|
}
|
|
+ // Paper end - replace knockback events
|
|
|
|
public static void callEntityRemoveEvent(Entity entity, EntityRemoveEvent.Cause cause) {
|
|
if (entity instanceof ServerPlayer) {
|