SPIGOT-8016: Call knockback event for mace area knockback

This commit is contained in:
Doc 2025-03-13 06:50:51 +11:00 committed by md_5
parent 3f33bb772b
commit 743e59541b
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 32 additions and 2 deletions

View File

@ -0,0 +1,30 @@
--- a/net/minecraft/world/item/MaceItem.java
+++ b/net/minecraft/world/item/MaceItem.java
@@ -27,6 +27,10 @@
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import org.bukkit.craftbukkit.util.CraftVector;
+// CraftBukkit end
+
public class MaceItem extends Item {
private static final int DEFAULT_ATTACK_DAMAGE = 5;
@@ -144,7 +148,15 @@
Vec3D vec3d1 = vec3d.normalize().scale(d0);
if (d0 > 0.0D) {
- entityliving.push(vec3d1.x, 0.699999988079071D, vec3d1.z);
+ // entityliving.push(vec3d1.x, 0.699999988079071D, vec3d1.z); // CraftBukkit - moved below
+ // CraftBukkit start - EntityKnockbackEvent
+ Vec3D vec3dPush = new Vec3D(vec3d1.x, 0.699999988079071D, vec3d1.z);
+ Vec3D result = entity.getDeltaMovement().add(vec3dPush);
+ org.bukkit.event.entity.EntityKnockbackEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) entityliving.getBukkitEntity(), entity1, org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK, d0, result, vec3dPush.x, vec3dPush.y, vec3dPush.z);
+ if (!event.isCancelled()) {
+ entityliving.push(CraftVector.toNMS(event.getFinalKnockback()));
+ }
+ // CraftBukkit end
if (entityliving instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entityliving;

View File

@ -1959,9 +1959,9 @@ public class CraftEventFactory {
EntityKnockbackEvent event; EntityKnockbackEvent event;
if (attacker != null) { 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 EntityKnockbackByEntityEvent(entity, attacker.getBukkitEntity(), cause, force, bukkitRaw, new Vector(x, y, z));
} else { } else {
event = new EntityKnockbackEvent(entity, cause, force, new Vector(-raw.x, raw.y, -raw.z), new Vector(x, y, z)); event = new EntityKnockbackEvent(entity, cause, force, bukkitRaw, new Vector(x, y, z));
} }
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);