Add entity knockback events

- EntityKnockbackEvent
- EntityPushedByEntityAttackEvent
- EntityKnockbackByEntityEvent

Co-authored-by: aerulion <aerulion@gmail.com>
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
This commit is contained in:
Brokkonaut
2018-06-18 15:46:23 +02:00
parent d68fcd321f
commit 991875920d
16 changed files with 356 additions and 180 deletions

View File

@@ -205,12 +205,12 @@
+ this.origin = location.toVector();
+ this.originWorld = location.getWorld().getUID();
+ }
+
+ @javax.annotation.Nullable
+ public org.bukkit.util.Vector getOriginVector() {
+ return this.origin != null ? this.origin.clone() : null;
+ }
+
+ @javax.annotation.Nullable
+ public UUID getOriginWorld() {
+ return this.originWorld;
@@ -265,7 +265,7 @@
datawatcher_a.define(Entity.DATA_TICKS_FROZEN, 0);
this.defineSynchedData(datawatcher_a);
this.entityData = datawatcher_a.build();
@@ -362,19 +557,35 @@
@@ -362,20 +557,36 @@
}
public void kill(ServerLevel world) {
@@ -290,7 +290,7 @@
public SynchedEntityData getEntityData() {
return this.entityData;
}
+
+ // CraftBukkit start
+ public void refreshEntityData(ServerPlayer to) {
+ List<SynchedEntityData.DataValue<?>> list = this.getEntityData().getNonDefaultValues();
@@ -300,9 +300,10 @@
+ }
+ }
+ // CraftBukkit end
+
public boolean equals(Object object) {
return object instanceof Entity ? ((Entity) object).id == this.id : false;
}
@@ -385,22 +596,34 @@
}
@@ -310,13 +311,13 @@
- this.setRemoved(reason);
+ // CraftBukkit start - add Bukkit remove cause
+ this.setRemoved(reason, null);
}
+ }
+
+ public void remove(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) {
+ this.setRemoved(entity_removalreason, cause);
+ // CraftBukkit end
+ }
+
}
public void onClientRemoval() {}
public void onRemoval(Entity.RemovalReason reason) {}
@@ -506,10 +507,13 @@
}
public boolean isFree(double offsetX, double offsetY, double offsetZ) {
@@ -750,6 +1050,28 @@
}
}
@@ -747,8 +1047,30 @@
if (movement.y != vec3d1.y) {
block.updateEntityMovementAfterFallOn(this.level(), this);
+ }
+ }
+
+ // CraftBukkit start
+ if (this.horizontalCollision && this.getBukkitEntity() instanceof Vehicle) {
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
@@ -528,13 +532,12 @@
+ if (!bl.getType().isAir()) {
+ VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl);
+ this.level.getCraftServer().getPluginManager().callEvent(event);
+ }
+ }
}
}
+ // CraftBukkit end
+
if (!this.level().isClientSide() || this.isControlledByLocalInstance()) {
Entity.MovementEmission entity_movementemission = this.getMovementEmission();
@@ -1131,7 +1453,21 @@
protected SoundEvent getSwimHighSpeedSplashSound() {
@@ -548,11 +551,11 @@
+
+ public SoundEvent getSwimSplashSound0() {
+ return this.getSwimSplashSound();
}
+ }
+
+ public SoundEvent getSwimHighSpeedSplashSound0() {
+ return this.getSwimHighSpeedSplashSound();
+ }
}
+ // CraftBukkit end
public void recordMovementThroughBlocks(Vec3 oldPos, Vec3 newPos) {
@@ -565,7 +568,30 @@
}
public void moveTo(Vec3 pos) {
@@ -1861,6 +2198,12 @@
@@ -1737,7 +2074,21 @@
}
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;
}
@@ -1861,6 +2212,12 @@
return false;
}
@@ -578,7 +604,7 @@
public void awardKillScore(Entity entityKilled, DamageSource damageSource) {
if (entityKilled instanceof ServerPlayer) {
CriteriaTriggers.ENTITY_KILLED_PLAYER.trigger((ServerPlayer) entityKilled, this, damageSource);
@@ -1889,16 +2232,22 @@
@@ -1889,16 +2246,22 @@
}
public boolean saveAsPassenger(CompoundTag nbt) {
@@ -604,7 +630,7 @@
return true;
}
}
@@ -1909,54 +2258,98 @@
@@ -1909,54 +2272,98 @@
}
public CompoundTag saveWithoutId(CompoundTag nbt) {
@@ -723,7 +749,7 @@
}
ListTag nbttaglist;
@@ -1972,10 +2365,10 @@
@@ -1972,10 +2379,10 @@
nbttaglist.add(StringTag.valueOf(s));
}
@@ -736,7 +762,7 @@
if (this.isVehicle()) {
nbttaglist = new ListTag();
iterator = this.getPassengers().iterator();
@@ -1984,17 +2377,35 @@
@@ -1984,17 +2391,35 @@
Entity entity = (Entity) iterator.next();
CompoundTag nbttagcompound1 = new CompoundTag();
@@ -775,7 +801,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being saved");
@@ -2080,6 +2491,66 @@
@@ -2080,6 +2505,66 @@
} else {
throw new IllegalStateException("Entity has invalid position");
}
@@ -842,7 +868,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
@@ -2101,6 +2572,12 @@
@@ -2101,6 +2586,12 @@
return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null;
}
@@ -855,7 +881,7 @@
protected abstract void readAdditionalSaveData(CompoundTag nbt);
protected abstract void addAdditionalSaveData(CompoundTag nbt);
@@ -2153,9 +2630,22 @@
@@ -2153,9 +2644,22 @@
if (stack.isEmpty()) {
return null;
} else {
@@ -878,7 +904,7 @@
world.addFreshEntity(entityitem);
return entityitem;
}
@@ -2184,6 +2674,12 @@
@@ -2184,6 +2688,12 @@
if (this.isAlive() && this instanceof Leashable leashable) {
if (leashable.getLeashHolder() == player) {
if (!this.level().isClientSide()) {
@@ -891,7 +917,7 @@
if (player.hasInfiniteMaterials()) {
leashable.removeLeash();
} else {
@@ -2200,6 +2696,13 @@
@@ -2200,6 +2710,13 @@
if (itemstack.is(Items.LEAD) && leashable.canHaveALeashAttachedToIt()) {
if (!this.level().isClientSide()) {
@@ -905,7 +931,7 @@
leashable.setLeashedTo(player, true);
}
@@ -2265,7 +2768,7 @@
@@ -2265,7 +2782,7 @@
}
public boolean showVehicleHealth() {
@@ -914,7 +940,7 @@
}
public boolean startRiding(Entity entity, boolean force) {
@@ -2273,7 +2776,7 @@
@@ -2273,7 +2790,7 @@
return false;
} else if (!entity.couldAcceptPassenger()) {
return false;
@@ -923,7 +949,7 @@
return false;
} else {
for (Entity entity1 = entity; entity1.vehicle != null; entity1 = entity1.vehicle) {
@@ -2285,11 +2788,32 @@
@@ -2285,11 +2802,32 @@
if (!force && (!this.canRide(entity) || !entity.canAddPassenger(this))) {
return false;
} else {
@@ -957,7 +983,7 @@
this.vehicle = entity;
this.vehicle.addPassenger(this);
entity.getIndirectPassengersStream().filter((entity2) -> {
@@ -2318,7 +2842,7 @@
@@ -2318,7 +2856,7 @@
Entity entity = this.vehicle;
this.vehicle = null;
@@ -966,7 +992,7 @@
}
}
@@ -2349,21 +2873,50 @@
@@ -2349,21 +2887,50 @@
}
}
@@ -1023,7 +1049,7 @@
}
protected boolean canAddPassenger(Entity passenger) {
@@ -2464,7 +3017,7 @@
@@ -2464,7 +3031,7 @@
if (teleporttransition != null) {
ServerLevel worldserver1 = teleporttransition.newLevel();
@@ -1032,7 +1058,7 @@
this.teleport(teleporttransition);
}
}
@@ -2547,7 +3100,7 @@
@@ -2547,7 +3114,7 @@
}
public boolean isCrouching() {
@@ -1041,7 +1067,7 @@
}
public boolean isSprinting() {
@@ -2563,7 +3116,7 @@
@@ -2563,7 +3130,7 @@
}
public boolean isVisuallySwimming() {
@@ -1050,7 +1076,7 @@
}
public boolean isVisuallyCrawling() {
@@ -2571,6 +3124,13 @@
@@ -2571,6 +3138,13 @@
}
public void setSwimming(boolean swimming) {
@@ -1064,7 +1090,7 @@
this.setSharedFlag(4, swimming);
}
@@ -2609,6 +3169,7 @@
@@ -2609,6 +3183,7 @@
@Nullable
public PlayerTeam getTeam() {
@@ -1072,7 +1098,7 @@
return this.level().getScoreboard().getPlayersTeam(this.getScoreboardName());
}
@@ -2624,8 +3185,12 @@
@@ -2624,8 +3199,12 @@
return this.getTeam() != null ? this.getTeam().isAlliedTo(team) : false;
}
@@ -1086,7 +1112,7 @@
}
public boolean getSharedFlag(int index) {
@@ -2644,7 +3209,7 @@
@@ -2644,7 +3223,7 @@
}
public int getMaxAirSupply() {
@@ -1095,7 +1121,7 @@
}
public int getAirSupply() {
@@ -2652,7 +3217,18 @@
@@ -2652,7 +3231,18 @@
}
public void setAirSupply(int air) {
@@ -1115,7 +1141,7 @@
}
public int getTicksFrozen() {
@@ -2679,11 +3255,40 @@
@@ -2679,11 +3269,40 @@
public void thunderHit(ServerLevel world, LightningBolt lightning) {
this.setRemainingFireTicks(this.remainingFireTicks + 1);
@@ -1158,7 +1184,7 @@
}
public void onAboveBubbleCol(boolean drag) {
@@ -2713,7 +3318,7 @@
@@ -2713,7 +3332,7 @@
this.resetFallDistance();
}
@@ -1167,7 +1193,7 @@
return true;
}
@@ -2852,6 +3457,26 @@
@@ -2852,6 +3471,26 @@
if (world instanceof ServerLevel worldserver) {
if (!this.isRemoved()) {
@@ -1194,7 +1220,7 @@
ServerLevel worldserver1 = teleportTarget.newLevel();
boolean flag = worldserver1.dimension() != worldserver.dimension();
@@ -2920,8 +3545,12 @@
@@ -2920,8 +3559,12 @@
} else {
entity.restoreFrom(this);
this.removeAfterChangingDimensions();
@@ -1208,7 +1234,7 @@
Iterator iterator1 = list1.iterator();
while (iterator1.hasNext()) {
@@ -2947,7 +3576,7 @@
@@ -2947,7 +3590,7 @@
}
private void sendTeleportTransitionToRidingPlayers(TeleportTransition teleportTarget) {
@@ -1217,7 +1243,7 @@
Iterator iterator = this.getIndirectPassengers().iterator();
while (iterator.hasNext()) {
@@ -2995,8 +3624,9 @@
@@ -2995,8 +3638,9 @@
}
protected void removeAfterChangingDimensions() {
@@ -1228,7 +1254,7 @@
leashable.removeLeash();
}
@@ -3004,7 +3634,21 @@
@@ -3004,7 +3648,21 @@
public Vec3 getRelativePortalPosition(Direction.Axis portalAxis, BlockUtil.FoundRectangle portalRect) {
return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose()));
@@ -1250,7 +1276,7 @@
public boolean canUsePortal(boolean allowVehicles) {
return (allowVehicles || !this.isPassenger()) && this.isAlive();
@@ -3134,9 +3778,15 @@
@@ -3134,10 +3792,16 @@
return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE);
}
@@ -1261,15 +1287,16 @@
+ public final boolean teleportTo(ServerLevel world, double destX, double destY, double destZ, Set<Relative> flags, float yaw, float pitch, boolean resetCamera) {
+ return this.teleportTo(world, destX, destY, destZ, flags, yaw, pitch, resetCamera, PlayerTeleportEvent.TeleportCause.UNKNOWN);
+ }
+
+ public boolean teleportTo(ServerLevel worldserver, double d0, double d1, double d2, Set<Relative> set, float f, float f1, boolean flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
+ float f2 = Mth.clamp(f1, -90.0F, 90.0F);
+ Entity entity = this.teleport(new TeleportTransition(worldserver, new Vec3(d0, d1, d2), Vec3.ZERO, f, f2, set, TeleportTransition.DO_NOTHING, cause));
+ // CraftBukkit end
+
return entity != null;
}
@@ -3187,7 +3837,7 @@
@@ -3187,7 +3851,7 @@
/** @deprecated */
@Deprecated
protected void fixupDimensions() {
@@ -1278,7 +1305,7 @@
EntityDimensions entitysize = this.getDimensions(entitypose);
this.dimensions = entitysize;
@@ -3196,7 +3846,7 @@
@@ -3196,7 +3860,7 @@
public void refreshDimensions() {
EntityDimensions entitysize = this.dimensions;
@@ -1287,7 +1314,7 @@
EntityDimensions entitysize1 = this.getDimensions(entitypose);
this.dimensions = entitysize1;
@@ -3258,10 +3908,29 @@
@@ -3258,10 +3922,29 @@
}
public final void setBoundingBox(AABB boundingBox) {
@@ -1319,7 +1346,7 @@
return this.getDimensions(pose).eyeHeight();
}
@@ -3335,7 +4004,7 @@
@@ -3335,7 +4018,7 @@
}
@Nullable
@@ -1328,7 +1355,7 @@
return null;
}
@@ -3435,7 +4104,7 @@
@@ -3435,7 +4118,7 @@
}
public boolean isControlledByLocalInstance() {
@@ -1337,7 +1364,7 @@
if (entityliving instanceof Player entityhuman) {
return entityhuman.isLocalPlayer();
@@ -3445,7 +4114,7 @@
@@ -3445,7 +4128,7 @@
}
public boolean isControlledByClient() {
@@ -1346,7 +1373,7 @@
return entityliving != null && entityliving.isControlledByClient();
}
@@ -3463,7 +4132,7 @@
@@ -3463,7 +4146,7 @@
return new Vec3((double) f1 * d2 / (double) f3, 0.0D, (double) f2 * d2 / (double) f3);
}
@@ -1355,7 +1382,7 @@
return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ());
}
@@ -3488,9 +4157,38 @@
@@ -3488,9 +4171,38 @@
public int getFireImmuneTicks() {
return 1;
}
@@ -1395,20 +1422,19 @@
}
public void lookAt(EntityAnchorArgument.Anchor anchorPoint, Vec3 target) {
@@ -3550,7 +4248,12 @@
@@ -3551,6 +4263,11 @@
vec3d = vec3d.add(vec3d1);
++k1;
+ }
}
+ // CraftBukkit start - store last lava contact location
+ if (tag == FluidTags.LAVA) {
+ this.lastLavaContact = blockposition_mutableblockposition.immutable();
}
+ }
+ // CraftBukkit end
}
}
}
@@ -3613,7 +4316,7 @@
@@ -3613,7 +4330,7 @@
return new ClientboundAddEntityPacket(this, entityTrackerEntry);
}
@@ -1417,7 +1443,7 @@
return this.type.getDimensions();
}
@@ -3818,8 +4521,16 @@
@@ -3818,8 +4535,16 @@
@Override
public final void setRemoved(Entity.RemovalReason reason) {
@@ -1435,7 +1461,7 @@
}
if (this.removalReason.shouldDestroy()) {
@@ -3827,8 +4538,8 @@
@@ -3827,8 +4552,8 @@
}
this.getPassengers().forEach(Entity::stopRiding);
@@ -1446,7 +1472,7 @@
}
public void unsetRemoved() {
@@ -3887,7 +4598,7 @@
@@ -3887,7 +4612,7 @@
}
public Vec3 getKnownMovement() {