From 96f03d906578da759c1cf1d4caff7e7cd49cf18c Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 23 Dec 2016 22:39:33 +1100 Subject: [PATCH] SPIGOT-2127: Add DamageCause.ENTITY_SWEEP_ATTACK --- nms-patches/DamageSource.patch | 21 +++++++++++++++++++ nms-patches/EntityHuman.patch | 2 +- .../craftbukkit/event/CraftEventFactory.java | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 nms-patches/DamageSource.patch diff --git a/nms-patches/DamageSource.patch b/nms-patches/DamageSource.patch new file mode 100644 index 000000000..ac9ca78e7 --- /dev/null +++ b/nms-patches/DamageSource.patch @@ -0,0 +1,21 @@ +--- a/net/minecraft/server/DamageSource.java ++++ b/net/minecraft/server/DamageSource.java +@@ -34,6 +34,18 @@ + private boolean C; + private boolean D; + public String translationIndex; ++ // CraftBukkit start ++ private boolean sweep; ++ ++ public boolean isSweep() { ++ return sweep; ++ } ++ ++ public DamageSource sweep() { ++ this.sweep = true; ++ return this; ++ } ++ // CraftBukkit end + + public static DamageSource mobAttack(EntityLiving entityliving) { + return new EntityDamageSource("mob", entityliving); diff --git a/nms-patches/EntityHuman.patch b/nms-patches/EntityHuman.patch index fce5fd79b..7bc17380f 100644 --- a/nms-patches/EntityHuman.patch +++ b/nms-patches/EntityHuman.patch @@ -279,7 +279,7 @@ if (entityliving != this && entityliving != entity && !this.r(entityliving) && this.h(entityliving) < 9.0D) { + // CraftBukkit start - Only apply knockback if the damage hits -+ if (entityliving.damageEntity(DamageSource.playerAttack(this), f4)) { ++ if (entityliving.damageEntity(DamageSource.playerAttack(this).sweep(), f4)) { entityliving.a(this, 0.4F, (double) MathHelper.sin(this.yaw * 0.017453292F), (double) (-MathHelper.cos(this.yaw * 0.017453292F))); - entityliving.damageEntity(DamageSource.playerAttack(this), f4); + } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 74faf9955..a6c152834 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -464,7 +464,7 @@ public class CraftEventFactory { return event; } else if (source instanceof EntityDamageSource) { Entity damager = source.getEntity(); - DamageCause cause = DamageCause.ENTITY_ATTACK; + DamageCause cause = (source.isSweep()) ? DamageCause.ENTITY_SWEEP_ATTACK : DamageCause.ENTITY_ATTACK; if (source instanceof EntityDamageSourceIndirect) { damager = ((EntityDamageSourceIndirect) source).getProximateDamageSource();