diff --git a/patches/api/Add-EntityKnockbackByEntityEvent.patch b/patches/api/Add-EntityKnockbackByEntityEvent-and-EntityPushedByE.patch similarity index 55% rename from patches/api/Add-EntityKnockbackByEntityEvent.patch rename to patches/api/Add-EntityKnockbackByEntityEvent-and-EntityPushedByE.patch index 5263806568..3639107edd 100644 --- a/patches/api/Add-EntityKnockbackByEntityEvent.patch +++ b/patches/api/Add-EntityKnockbackByEntityEvent-and-EntityPushedByE.patch @@ -1,8 +1,10 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Mon, 18 Jun 2018 15:40:39 +0200 -Subject: [PATCH] Add EntityKnockbackByEntityEvent +Subject: [PATCH] Add EntityKnockbackByEntityEvent and + EntityPushedByEntityAttackEvent +Co-authored-by: aerulion 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 @@ -12,11 +14,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @@ -0,0 +0,0 @@ +package com.destroystokyo.paper.event.entity; + ++import io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; -+import org.bukkit.event.Cancellable; -+import org.bukkit.event.HandlerList; -+import org.bukkit.event.entity.EntityEvent; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; + @@ -25,18 +25,72 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * vector can be modified. If this event is cancelled, the entity is not knocked back. + * + */ -+public class EntityKnockbackByEntityEvent extends EntityEvent implements Cancellable { -+ private static final HandlerList handlers = new HandlerList(); -+ -+ @NotNull private final Entity hitBy; ++public class EntityKnockbackByEntityEvent extends EntityPushedByEntityAttackEvent { + private final float knockbackStrength; -+ @NotNull private final Vector acceleration; -+ private boolean cancelled = false; + + public EntityKnockbackByEntityEvent(@NotNull LivingEntity entity, @NotNull Entity hitBy, float knockbackStrength, @NotNull Vector acceleration) { -+ super(entity); -+ this.hitBy = hitBy; ++ super(entity, hitBy, acceleration); + this.knockbackStrength = knockbackStrength; ++ } ++ ++ /** ++ * @return the entity which was knocked back ++ */ ++ @NotNull ++ @Override ++ public LivingEntity getEntity() { ++ return (LivingEntity) super.getEntity(); ++ } ++ ++ /** ++ * @return the original knockback strength. ++ */ ++ public float getKnockbackStrength() { ++ return knockbackStrength; ++ } ++ ++ /** ++ * @return the Entity which hit ++ */ ++ @NotNull ++ public Entity getHitBy() { ++ return super.getPushedBy(); ++ } ++ ++} +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..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/event/entity/EntityPushedByEntityAttackEvent.java +@@ -0,0 +0,0 @@ ++package io.papermc.paper.event.entity; ++ ++import org.bukkit.entity.Entity; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.HandlerList; ++import org.bukkit.event.entity.EntityEvent; ++import org.bukkit.util.Vector; ++import org.jetbrains.annotations.NotNull; ++ ++/** ++ * Fired when an entity is pushed by another entity's attack. The acceleration vector can be ++ * modified. If this event is cancelled, the entity will not get pushed. ++ *

++ * Note: Some entities might trigger this multiple times on the same entity ++ * as multiple acceleration calculations are done. ++ */ ++public class EntityPushedByEntityAttackEvent extends EntityEvent implements Cancellable { ++ ++ private static final HandlerList handlers = new HandlerList(); ++ ++ private final @NotNull Entity pushedBy; ++ private final @NotNull Vector acceleration; ++ private boolean cancelled = false; ++ ++ public EntityPushedByEntityAttackEvent(@NotNull Entity entity, @NotNull Entity pushedBy, @NotNull Vector acceleration) { ++ super(entity); ++ this.pushedBy = pushedBy; + this.acceleration = acceleration; + } + @@ -61,31 +115,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + + /** -+ * @return the entity which was knocked back ++ * Gets the entity which pushed the affected entity. ++ * ++ * @return the pushing entity + */ + @NotNull -+ @Override -+ public LivingEntity getEntity() { -+ return (LivingEntity) super.getEntity(); ++ public Entity getPushedBy() { ++ return pushedBy; + } + + /** -+ * @return the original knockback strength. -+ */ -+ public float getKnockbackStrength() { -+ return knockbackStrength; -+ } -+ -+ /** -+ * @return the Entity which hit -+ */ -+ @NotNull -+ public Entity getHitBy() { -+ return hitBy; -+ } -+ -+ /** -+ * @return the acceleration that will be applied ++ * Gets the acceleration that will be applied to the affected entity. ++ * ++ * @return the acceleration vector + */ + @NotNull + public Vector getAcceleration() { diff --git a/patches/server/Implement-EntityKnockbackByEntityEvent.patch b/patches/server/Implement-EntityKnockbackByEntityEvent-and-EntityPus.patch similarity index 53% rename from patches/server/Implement-EntityKnockbackByEntityEvent.patch rename to patches/server/Implement-EntityKnockbackByEntityEvent-and-EntityPus.patch index a6e884f1fd..915d46bc4a 100644 --- a/patches/server/Implement-EntityKnockbackByEntityEvent.patch +++ b/patches/server/Implement-EntityKnockbackByEntityEvent-and-EntityPus.patch @@ -1,10 +1,37 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Brokkonaut Date: Mon, 18 Jun 2018 15:46:23 +0200 -Subject: [PATCH] Implement EntityKnockbackByEntityEvent +Subject: [PATCH] Implement EntityKnockbackByEntityEvent and + EntityPushedByEntityAttackEvent + +Co-authored-by: aerulion This event is called when an entity receives knockback by another entity. +diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/entity/Entity.java ++++ b/src/main/java/net/minecraft/world/entity/Entity.java +@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { + } + + public void push(double deltaX, double deltaY, double deltaZ) { +- this.setDeltaMovement(this.getDeltaMovement().add(deltaX, deltaY, deltaZ)); +- this.hasImpulse = true; ++ // Paper start - call EntityPushedByEntityEvent ++ this.push(deltaX, deltaY, deltaZ, null); ++ } ++ ++ 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 || new io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent(getBukkitEntity(), pushingEntity.getBukkitEntity(), delta).callEvent()) { ++ this.setDeltaMovement(this.getDeltaMovement().add(delta.getX(), delta.getY(), delta.getZ())); ++ this.hasImpulse = true; ++ } ++ // Paper end - call EntityPushedByEntityEvent + } + + 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -14,7 +41,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 this.hurtDir = (float) (Mth.atan2(d1, d0) * 57.2957763671875D - (double) this.getYRot()); - this.knockback(0.4000000059604645D, d0, d1); -+ this.knockback(0.4000000059604645D, d0, d1, entity1); ++ this.knockback(0.4000000059604645D, d0, d1, entity1); // Paper } else { this.hurtDir = (float) ((int) (Math.random() * 2.0D) * 180); } @@ -23,7 +50,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 protected void blockedByShield(LivingEntity target) { - target.knockback(0.5D, target.getX() - this.getX(), target.getZ() - this.getZ()); -+ target.knockback(0.5D, target.getX() - this.getX(), target.getZ() - this.getZ(), this); ++ target.knockback(0.5D, target.getX() - this.getX(), target.getZ() - this.getZ(), this); // Paper } private boolean checkTotemDeathProtection(DamageSource source) { @@ -81,6 +108,58 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 this.finishRam(world, entity); world.playSound((Player)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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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 +@@ -0,0 +0,0 @@ public class SonicBoom extends Behavior { + target.hurt(DamageSource.sonicBoom(entity), 10.0F); + double d = 0.5D * (1.0D - target.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE)); + double e = 2.5D * (1.0D - 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 + }); + } + } +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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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 +@@ -0,0 +0,0 @@ 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 + if (!this.phaseManager.getCurrentPhase().isSitting() && ((LivingEntity) entity).getLastHurtByMobTimestamp() < entity.tickCount - 2) { + entity.hurt(DamageSource.mobAttack(this), 5.0F); + this.doEnchantDamageEffects(this, entity); +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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/entity/monster/Ravager.java ++++ b/src/main/java/net/minecraft/world/entity/monster/Ravager.java +@@ -0,0 +0,0 @@ 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 + } + + @Override +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 ++++ b/src/main/java/net/minecraft/world/entity/monster/hoglin/HoglinBase.java +@@ -0,0 +0,0 @@ public interface HoglinBase { + double j = f * (double)(attacker.level.random.nextFloat() * 0.5F + 0.2F); + Vec3 vec3 = (new Vec3(g, 0.0D, h)).normalize().scale(j).yRot(i); + double k = f * (double)attacker.level.random.nextFloat() * 0.5D; +- target.push(vec3.x, k, vec3.z); ++ target.push(vec3.x, k, vec3.z, attacker); // Paper + 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/player/Player.java @@ -92,8 +171,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 - ((LivingEntity) target).knockback((double) ((float) i * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F))); + ((LivingEntity) target).knockback((double) ((float) i * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this); // Paper } else { - target.push((double) (-Mth.sin(this.getYRot() * 0.017453292F) * (float) i * 0.5F), 0.1D, (double) (Mth.cos(this.getYRot() * 0.017453292F) * (float) i * 0.5F)); +- target.push((double) (-Mth.sin(this.getYRot() * 0.017453292F) * (float) i * 0.5F), 0.1D, (double) (Mth.cos(this.getYRot() * 0.017453292F) * (float) i * 0.5F)); ++ target.push((double) (-Mth.sin(this.getYRot() * 0.017453292F) * (float) i * 0.5F), 0.1D, (double) (Mth.cos(this.getYRot() * 0.017453292F) * (float) i * 0.5F), this); // Paper } + + this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D)); @@ -0,0 +0,0 @@ public abstract class Player extends LivingEntity { if (entityliving != this && entityliving != target && !this.isAlliedTo((Entity) entityliving) && (!(entityliving instanceof ArmorStand) || !((ArmorStand) entityliving).isMarker()) && this.distanceToSqr((Entity) entityliving) < 9.0D) { // CraftBukkit start - Only apply knockback if the damage hits @@ -103,3 +185,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } // CraftBukkit end } +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 ++++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java +@@ -0,0 +0,0 @@ public abstract class AbstractArrow extends Projectile { + Vec3 vec3d = this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D).normalize().scale((double) this.knockback * 0.6D * d0); + + if (vec3d.lengthSqr() > 0.0D) { +- entityliving.push(vec3d.x, 0.1D, vec3d.z); ++ entityliving.push(vec3d.x, 0.1D, vec3d.z, this); // Paper + } + } +