mirror of
https://github.com/PaperMC/Paper.git
synced 2024-10-31 16:00:18 +01:00
Add cause to knockback events
This commit is contained in:
parent
b8c454c2ba
commit
7a4003b741
@ -5,10 +5,11 @@ Subject: [PATCH] Add EntityKnockbackByEntityEvent and
|
||||
EntityPushedByEntityAttackEvent
|
||||
|
||||
Co-authored-by: aerulion <aerulion@gmail.com>
|
||||
Co-authored-by: leguan <longboard.noah@gmail.com>
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/EntityKnockbackByEntityEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/EntityKnockbackByEntityEvent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..e0ba692c9b107f2b042a9c06549185e1c4777e27
|
||||
index 0000000000000000000000000000000000000000..69b09853d3688bc795fbd0f43d18121a65462dbd
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/event/entity/EntityKnockbackByEntityEvent.java
|
||||
@@ -0,0 +1,48 @@
|
||||
@ -30,8 +31,8 @@ index 0000000000000000000000000000000000000000..e0ba692c9b107f2b042a9c06549185e1
|
||||
+ private final float knockbackStrength;
|
||||
+
|
||||
+ @ApiStatus.Internal
|
||||
+ public EntityKnockbackByEntityEvent(@NotNull LivingEntity entity, @NotNull Entity hitBy, float knockbackStrength, @NotNull Vector acceleration) {
|
||||
+ super(entity, hitBy, acceleration);
|
||||
+ public EntityKnockbackByEntityEvent(@NotNull LivingEntity entity, @NotNull Entity hitBy, @NotNull KnockbackCause cause, float knockbackStrength, @NotNull Vector acceleration) {
|
||||
+ super(entity, hitBy, acceleration, cause);
|
||||
+ this.knockbackStrength = knockbackStrength;
|
||||
+ }
|
||||
+
|
||||
@ -62,10 +63,10 @@ index 0000000000000000000000000000000000000000..e0ba692c9b107f2b042a9c06549185e1
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/event/entity/EntityPushedByEntityAttackEvent.java b/src/main/java/io/papermc/paper/event/entity/EntityPushedByEntityAttackEvent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..404bec776244fd776566c81f671f1009830c6d6e
|
||||
index 0000000000000000000000000000000000000000..c7aada6fa052b05e7310af9af158f8af93fa1f98
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/event/entity/EntityPushedByEntityAttackEvent.java
|
||||
@@ -0,0 +1,82 @@
|
||||
@@ -0,0 +1,124 @@
|
||||
+package io.papermc.paper.event.entity;
|
||||
+
|
||||
+import org.bukkit.entity.Entity;
|
||||
@ -88,14 +89,16 @@ index 0000000000000000000000000000000000000000..404bec776244fd776566c81f671f1009
|
||||
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
+
|
||||
+ private final @NotNull Entity pushedBy;
|
||||
+ private final @NotNull KnockbackCause cause;
|
||||
+ private @NotNull Vector acceleration;
|
||||
+ private boolean cancelled;
|
||||
+
|
||||
+ @ApiStatus.Internal
|
||||
+ public EntityPushedByEntityAttackEvent(@NotNull Entity entity, @NotNull Entity pushedBy, @NotNull Vector acceleration) {
|
||||
+ public EntityPushedByEntityAttackEvent(@NotNull Entity entity, @NotNull Entity pushedBy, @NotNull Vector acceleration, @NotNull KnockbackCause cause) {
|
||||
+ super(entity);
|
||||
+ this.pushedBy = pushedBy;
|
||||
+ this.acceleration = acceleration;
|
||||
+ this.cause = cause;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
@ -119,6 +122,15 @@ index 0000000000000000000000000000000000000000..404bec776244fd776566c81f671f1009
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the cause of the knockback.
|
||||
+ *
|
||||
+ * @return the cause of the knockback
|
||||
+ */
|
||||
+ public @NotNull KnockbackCause getCause() {
|
||||
+ return this.cause;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the relative acceleration that will be applied to the affected entity.
|
||||
+ *
|
||||
+ * @param acceleration the new acceleration vector
|
||||
@ -147,6 +159,37 @@ index 0000000000000000000000000000000000000000..404bec776244fd776566c81f671f1009
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return HANDLER_LIST;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * An enum to specify the cause of the knockback.
|
||||
+ */
|
||||
+ public enum KnockbackCause {
|
||||
+
|
||||
+ /**
|
||||
+ * Knockback caused by non-entity damage.
|
||||
+ */
|
||||
+ DAMAGE,
|
||||
+ /**
|
||||
+ * Knockback caused by an attacking entity.
|
||||
+ */
|
||||
+ ENTITY_ATTACK,
|
||||
+ /**
|
||||
+ * Knockback caused by an explosion.
|
||||
+ */
|
||||
+ EXPLOSION,
|
||||
+ /**
|
||||
+ * Knockback caused by the target blocking with a shield.
|
||||
+ */
|
||||
+ SHIELD_BLOCK,
|
||||
+ /**
|
||||
+ * Knockback caused by a sweeping attack.
|
||||
+ */
|
||||
+ SWEEP_ATTACK,
|
||||
+ /**
|
||||
+ * Knockback with an unknown cause.
|
||||
+ */
|
||||
+ UNKNOWN;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/bukkit/event/entity/EntityKnockbackByEntityEvent.java b/src/main/java/org/bukkit/event/entity/EntityKnockbackByEntityEvent.java
|
||||
index 3f17290c0863cc1d452bb50c524c18b6ab255d70..bd44bc5ed9e20148f9b2ab3d2049187280f3eb18 100644
|
||||
|
@ -5,6 +5,7 @@ Subject: [PATCH] Add EntityKnockbackByEntityEvent and
|
||||
EntityPushedByEntityAttackEvent
|
||||
|
||||
Co-authored-by: aerulion <aerulion@gmail.com>
|
||||
Co-authored-by: leguan <longboard.noah@gmail.com>
|
||||
|
||||
This event is called when an entity receives knockback by another entity.
|
||||
|
||||
@ -26,7 +27,7 @@ index e612921a7fb68dd74d8fd4084a8beccc299ff6ea..49b100e2cf9868c4f06aae0bf538fcd4
|
||||
+ public void push(double deltaX, double deltaY, double deltaZ, @org.jetbrains.annotations.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(getBukkitEntity(), pushingEntity.getBukkitEntity(), delta);
|
||||
+ io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent event = new io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent(getBukkitEntity(), pushingEntity.getBukkitEntity(), delta, io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent.KnockbackCause.ENTITY_ATTACK);
|
||||
+ if (!event.callEvent()) {
|
||||
+ return;
|
||||
+ }
|
||||
@ -39,7 +40,7 @@ index e612921a7fb68dd74d8fd4084a8beccc299ff6ea..49b100e2cf9868c4f06aae0bf538fcd4
|
||||
|
||||
protected void markHurt() {
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
index 3f50533b89345a74392e0e6ef0407e6aa544876e..b153247b4be38e8ecaf3df64db55df88b7501cfd 100644
|
||||
index 3f50533b89345a74392e0e6ef0407e6aa544876e..00264a5364b557e87e2079ba58562f9f9ed4b457 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -1593,7 +1593,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
||||
@ -69,7 +70,7 @@ index 3f50533b89345a74392e0e6ef0407e6aa544876e..b153247b4be38e8ecaf3df64db55df88
|
||||
+ org.bukkit.util.Vector resultingMovement = event.getFinalKnockback();
|
||||
+ final org.bukkit.util.Vector deltaMovement = resultingMovement.clone().subtract(currentMovement);
|
||||
+ if (attacker != null) {
|
||||
+ final com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent knockbackEvent = new com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent(this.getBukkitLivingEntity(), attacker.getBukkitEntity(), (float) event.getForce(), deltaMovement);
|
||||
+ final com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent knockbackEvent = new com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent(this.getBukkitLivingEntity(), attacker.getBukkitEntity(), CraftEventFactory.convertKnockbackCause(cause), (float) event.getForce(), deltaMovement);
|
||||
+ if (!knockbackEvent.callEvent()) {
|
||||
+ return;
|
||||
+ }
|
||||
@ -218,7 +219,7 @@ index 9f9b7373c9a714597858ddcd8932e31b902cf5a1..f7f26d595072372004143c4e26506ed5
|
||||
public abstract void explode();
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
index 754ca46d11dfe0495aa3109b68b1032e6d7d76e9..4c7795e1ba7bb3135fcf5bab1c8aa857b8e7417b 100644
|
||||
index 94f72ff58ac5206878a81e89d32e81c17b1bd1fb..b5b29210d9a6125d98e7dd737ca25f40545e512b 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
@@ -303,6 +303,16 @@ public class Explosion {
|
||||
@ -228,7 +229,7 @@ index 754ca46d11dfe0495aa3109b68b1032e6d7d76e9..4c7795e1ba7bb3135fcf5bab1c8aa857
|
||||
+ // Paper start - call EntityKnockbackByEntityEvent for explosions
|
||||
+ if (this.damageSource.getEntity() != null || this.source != null) {
|
||||
+ final org.bukkit.entity.Entity hitBy = this.damageSource.getEntity() != null ? this.damageSource.getEntity().getBukkitEntity() : this.source.getBukkitEntity();
|
||||
+ com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent paperEvent = new com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent(((LivingEntity) entity).getBukkitLivingEntity(), hitBy, (float) event.getForce(), org.bukkit.craftbukkit.util.CraftVector.toBukkit(vec3d1));
|
||||
+ com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent paperEvent = new com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent(((LivingEntity) entity).getBukkitLivingEntity(), hitBy, com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent.KnockbackCause.EXPLOSION, (float) event.getForce(), org.bukkit.craftbukkit.util.CraftVector.toBukkit(vec3d1));
|
||||
+ if (!paperEvent.callEvent()) {
|
||||
+ continue;
|
||||
+ }
|
||||
@ -238,3 +239,20 @@ index 754ca46d11dfe0495aa3109b68b1032e6d7d76e9..4c7795e1ba7bb3135fcf5bab1c8aa857
|
||||
}
|
||||
// CraftBukkit end
|
||||
entity.setDeltaMovement(entity.getDeltaMovement().add(vec3d1));
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
index f3fd59843e7517eb38bfa06b58445728d2a80001..c15d8e09900af6ce2eb95baf3733ef034193fa59 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
@@ -1873,6 +1873,12 @@ public class CraftEventFactory {
|
||||
return event;
|
||||
}
|
||||
|
||||
+ // Paper start - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent - Add cause
|
||||
+ public static io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent.KnockbackCause convertKnockbackCause(org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause bukkitKnockbackCause) {
|
||||
+ return io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent.KnockbackCause.valueOf(bukkitKnockbackCause.name());
|
||||
+ }
|
||||
+ // Paper end - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent - Add cause
|
||||
+
|
||||
public static void callEntityRemoveEvent(Entity entity, EntityRemoveEvent.Cause cause) {
|
||||
if (entity instanceof ServerPlayer) {
|
||||
return; // Don't call for player
|
||||
|
@ -32,10 +32,10 @@ index e772b6f8f78ad1292b8fa268e8bb4001a38706c6..efa7cf50b5577f87a2dfa61b59bf8105
|
||||
} else {
|
||||
ItemStack itemstack = tileentitydispenser.getItem(i);
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
index 253563371aa05954c19607b98675e37450e772ef..13e4cb7af50b3a03523d84dd72ca6a122ca041ad 100644
|
||||
index 4a8f59abf8377e96ac315cec082fd55b69e0f57a..6a1b959246de14a5197c6edf891034bcf4cbbaa7 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
@@ -2034,4 +2034,12 @@ public class CraftEventFactory {
|
||||
@@ -2040,4 +2040,12 @@ public class CraftEventFactory {
|
||||
return org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getPotion());
|
||||
}
|
||||
// Paper end - WitchReadyPotionEvent
|
||||
|
@ -29,10 +29,10 @@ index efa7cf50b5577f87a2dfa61b59bf81052794fbf1..b4a742e8c513e458b34c216d1e907b47
|
||||
} else {
|
||||
// CraftBukkit start - Fire event when pushing items into other inventories
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
index 13e4cb7af50b3a03523d84dd72ca6a122ca041ad..e6bb82928af3378847722421ce3bad7f5b994890 100644
|
||||
index 6a1b959246de14a5197c6edf891034bcf4cbbaa7..b63df5c5a752cadcd15a312bf9d0e0170b52825d 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
@@ -2041,5 +2041,11 @@ public class CraftEventFactory {
|
||||
@@ -2047,5 +2047,11 @@ public class CraftEventFactory {
|
||||
io.papermc.paper.event.block.BlockFailedDispenseEvent event = new io.papermc.paper.event.block.BlockFailedDispenseEvent(block);
|
||||
return event.callEvent();
|
||||
}
|
||||
|
@ -69,10 +69,10 @@ index a0c52ce65d4035d135b1536c7408a6867a553447..dc035bf94c5f6574ed8ad369b327b7f7
|
||||
this.playSound(SoundEvents.SNIFFER_EGG_PLOP, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 0.5F);
|
||||
} // Paper - Call EntityDropItemEvent
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
index 0ab1cf162016422007426698dec60ffd875631a0..160ebf499b2f088a3fb1ca683e3d7b02acbd548f 100644
|
||||
index 970e71d859426de88d60e1543364212769f02861..3da7e1a93a23b5f85984ff6073c2937d338ee5a3 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
@@ -2109,4 +2109,28 @@ public class CraftEventFactory {
|
||||
@@ -2115,4 +2115,28 @@ public class CraftEventFactory {
|
||||
return event.callEvent();
|
||||
}
|
||||
// Paper end
|
||||
|
@ -50,10 +50,10 @@ index 9507dbbb4b490149b9248c384be5adaccae40c41..5bbadc890a72f1cb22c6881ebcc163b0
|
||||
for (int k = 0; k < 5; ++k) {
|
||||
worldserver.sendParticles(ParticleTypes.SPLASH, (double) blockposition.getX() + worldserver.random.nextDouble(), (double) (blockposition.getY() + 1), (double) blockposition.getZ() + worldserver.random.nextDouble(), 1, 0.0D, 0.0D, 0.0D, 1.0D);
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
index c8627846dc213f2230327e37ac1114d5cd7447ef..3679bc4573346666088995903a3418c359444532 100644
|
||||
index 17aa54a7219773ab6e7fbe548eaa03ae2274645b..3ee679679457f1787753774bcff003b7fa119e9a 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
@@ -2110,6 +2110,32 @@ public class CraftEventFactory {
|
||||
@@ -2116,6 +2116,32 @@ public class CraftEventFactory {
|
||||
}
|
||||
// Paper end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user