Cap Entity Collisions

Limit a single entity to colliding a max of configurable times per tick.
This will alleviate issues where living entities are hoarded in 1x1 pens

This is not tied to the maxEntityCramming rule. Cramming will still apply
just as it does in Vanilla, but entity pushing logic will be capped.

You can set this to 0 to disable collisions.
This commit is contained in:
Aikar
2017-01-22 18:07:56 -05:00
parent 110bcadcdf
commit d2f4d82ce2
2 changed files with 127 additions and 112 deletions

View File

@@ -168,7 +168,7 @@
private static final EntityDataAccessor<Integer> DATA_TICKS_FROZEN = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.INT); private static final EntityDataAccessor<Integer> DATA_TICKS_FROZEN = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.INT);
private EntityInLevelCallback levelCallback; private EntityInLevelCallback levelCallback;
private final VecDeltaCodec packetPositionCodec; private final VecDeltaCodec packetPositionCodec;
@@ -253,7 +384,62 @@ @@ -253,7 +384,63 @@
private final List<Entity.Movement> movementThisTick; private final List<Entity.Movement> movementThisTick;
private final Set<BlockState> blocksInside; private final Set<BlockState> blocksInside;
private final LongSet visitedBlocks; private final LongSet visitedBlocks;
@@ -193,6 +193,7 @@
+ public long activatedTick = Integer.MIN_VALUE; + public long activatedTick = Integer.MIN_VALUE;
+ public void inactiveTick() { } + public void inactiveTick() { }
+ // Spigot end + // Spigot end
+ protected int numCollisions = 0; // Paper - Cap entity collisions
+ // Paper start - Entity origin API + // Paper start - Entity origin API
+ @javax.annotation.Nullable + @javax.annotation.Nullable
+ private org.bukkit.util.Vector origin; + private org.bukkit.util.Vector origin;
@@ -231,7 +232,7 @@
public Entity(EntityType<?> type, Level world) { public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet(); this.id = Entity.ENTITY_COUNTER.incrementAndGet();
this.passengers = ImmutableList.of(); this.passengers = ImmutableList.of();
@@ -261,7 +447,7 @@ @@ -261,7 +448,7 @@
this.bb = Entity.INITIAL_AABB; this.bb = Entity.INITIAL_AABB;
this.stuckSpeedMultiplier = Vec3.ZERO; this.stuckSpeedMultiplier = Vec3.ZERO;
this.nextStep = 1.0F; this.nextStep = 1.0F;
@@ -240,7 +241,7 @@
this.remainingFireTicks = -this.getFireImmuneTicks(); this.remainingFireTicks = -this.getFireImmuneTicks();
this.fluidHeight = new Object2DoubleArrayMap(2); this.fluidHeight = new Object2DoubleArrayMap(2);
this.fluidOnEyes = new HashSet(); this.fluidOnEyes = new HashSet();
@@ -284,6 +470,13 @@ @@ -284,6 +471,13 @@
this.position = Vec3.ZERO; this.position = Vec3.ZERO;
this.blockPosition = BlockPos.ZERO; this.blockPosition = BlockPos.ZERO;
this.chunkPosition = ChunkPos.ZERO; this.chunkPosition = ChunkPos.ZERO;
@@ -254,7 +255,7 @@
SynchedEntityData.Builder datawatcher_a = new SynchedEntityData.Builder(this); SynchedEntityData.Builder datawatcher_a = new SynchedEntityData.Builder(this);
datawatcher_a.define(Entity.DATA_SHARED_FLAGS_ID, (byte) 0); datawatcher_a.define(Entity.DATA_SHARED_FLAGS_ID, (byte) 0);
@@ -292,7 +485,7 @@ @@ -292,7 +486,7 @@
datawatcher_a.define(Entity.DATA_CUSTOM_NAME, Optional.empty()); datawatcher_a.define(Entity.DATA_CUSTOM_NAME, Optional.empty());
datawatcher_a.define(Entity.DATA_SILENT, false); datawatcher_a.define(Entity.DATA_SILENT, false);
datawatcher_a.define(Entity.DATA_NO_GRAVITY, false); datawatcher_a.define(Entity.DATA_NO_GRAVITY, false);
@@ -263,7 +264,7 @@
datawatcher_a.define(Entity.DATA_TICKS_FROZEN, 0); datawatcher_a.define(Entity.DATA_TICKS_FROZEN, 0);
this.defineSynchedData(datawatcher_a); this.defineSynchedData(datawatcher_a);
this.entityData = datawatcher_a.build(); this.entityData = datawatcher_a.build();
@@ -362,19 +555,35 @@ @@ -362,20 +556,36 @@
} }
public void kill(ServerLevel world) { public void kill(ServerLevel world) {
@@ -287,8 +288,8 @@
public SynchedEntityData getEntityData() { public SynchedEntityData getEntityData() {
return this.entityData; return this.entityData;
+ } }
+
+ // CraftBukkit start + // CraftBukkit start
+ public void refreshEntityData(ServerPlayer to) { + public void refreshEntityData(ServerPlayer to) {
+ List<SynchedEntityData.DataValue<?>> list = this.getEntityData().getNonDefaultValues(); + List<SynchedEntityData.DataValue<?>> list = this.getEntityData().getNonDefaultValues();
@@ -296,12 +297,13 @@
+ if (list != null) { + if (list != null) {
+ to.connection.send(new ClientboundSetEntityDataPacket(this.getId(), list)); + to.connection.send(new ClientboundSetEntityDataPacket(this.getId(), list));
+ } + }
} + }
+ // CraftBukkit end + // CraftBukkit end
+
public boolean equals(Object object) { public boolean equals(Object object) {
return object instanceof Entity ? ((Entity) object).id == this.id : false; return object instanceof Entity ? ((Entity) object).id == this.id : false;
@@ -385,22 +594,34 @@ }
@@ -385,22 +595,34 @@
} }
public void remove(Entity.RemovalReason reason) { public void remove(Entity.RemovalReason reason) {
@@ -341,7 +343,7 @@
return this.getPose() == pose; return this.getPose() == pose;
} }
@@ -417,6 +638,33 @@ @@ -417,6 +639,33 @@
} }
public void setRot(float yaw, float pitch) { public void setRot(float yaw, float pitch) {
@@ -375,7 +377,7 @@
this.setYRot(yaw % 360.0F); this.setYRot(yaw % 360.0F);
this.setXRot(pitch % 360.0F); this.setXRot(pitch % 360.0F);
} }
@@ -460,7 +708,16 @@ @@ -460,7 +709,16 @@
public void tick() { public void tick() {
this.baseTick(); this.baseTick();
@@ -392,7 +394,7 @@
public void baseTick() { public void baseTick() {
ProfilerFiller gameprofilerfiller = Profiler.get(); ProfilerFiller gameprofilerfiller = Profiler.get();
@@ -475,7 +732,7 @@ @@ -475,7 +733,7 @@
--this.boardingCooldown; --this.boardingCooldown;
} }
@@ -401,7 +403,7 @@
if (this.canSpawnSprintParticle()) { if (this.canSpawnSprintParticle()) {
this.spawnSprintParticle(); this.spawnSprintParticle();
} }
@@ -514,6 +771,10 @@ @@ -514,6 +772,10 @@
if (this.isInLava()) { if (this.isInLava()) {
this.lavaHurt(); this.lavaHurt();
this.fallDistance *= 0.5F; this.fallDistance *= 0.5F;
@@ -412,7 +414,7 @@
} }
this.checkBelowWorld(); this.checkBelowWorld();
@@ -525,7 +786,7 @@ @@ -525,7 +787,7 @@
world = this.level(); world = this.level();
if (world instanceof ServerLevel worldserver) { if (world instanceof ServerLevel worldserver) {
if (this instanceof Leashable) { if (this instanceof Leashable) {
@@ -421,7 +423,7 @@
} }
} }
@@ -537,7 +798,11 @@ @@ -537,7 +799,11 @@
} }
public void checkBelowWorld() { public void checkBelowWorld() {
@@ -434,7 +436,7 @@
this.onBelowWorld(); this.onBelowWorld();
} }
@@ -568,15 +833,32 @@ @@ -568,15 +834,32 @@
public void lavaHurt() { public void lavaHurt() {
if (!this.fireImmune()) { if (!this.fireImmune()) {
@@ -469,15 +471,15 @@
} }
} }
@@ -587,7 +869,23 @@ @@ -587,9 +870,25 @@
} }
public final void igniteForSeconds(float seconds) { public final void igniteForSeconds(float seconds) {
- this.igniteForTicks(Mth.floor(seconds * 20.0F)); - this.igniteForTicks(Mth.floor(seconds * 20.0F));
+ // CraftBukkit start + // CraftBukkit start
+ this.igniteForSeconds(seconds, true); + this.igniteForSeconds(seconds, true);
+ } }
+
+ public final void igniteForSeconds(float f, boolean callEvent) { + public final void igniteForSeconds(float f, boolean callEvent) {
+ if (callEvent) { + if (callEvent) {
+ EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity(), f); + EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity(), f);
@@ -491,10 +493,12 @@
+ } + }
+ // CraftBukkit end + // CraftBukkit end
+ this.igniteForTicks(Mth.floor(f * 20.0F)); + this.igniteForTicks(Mth.floor(f * 20.0F));
} + }
+
public void igniteForTicks(int ticks) { public void igniteForTicks(int ticks) {
@@ -610,7 +908,7 @@ if (this.remainingFireTicks < ticks) {
this.setRemainingFireTicks(ticks);
@@ -610,7 +909,7 @@
} }
protected void onBelowWorld() { protected void onBelowWorld() {
@@ -503,7 +507,7 @@
} }
public boolean isFree(double offsetX, double offsetY, double offsetZ) { public boolean isFree(double offsetX, double offsetY, double offsetZ) {
@@ -750,6 +1048,28 @@ @@ -750,6 +1049,28 @@
} }
} }
@@ -532,17 +536,15 @@
if (!this.level().isClientSide() || this.isControlledByLocalInstance()) { if (!this.level().isClientSide() || this.isControlledByLocalInstance()) {
Entity.MovementEmission entity_movementemission = this.getMovementEmission(); Entity.MovementEmission entity_movementemission = this.getMovementEmission();
@@ -1131,8 +1451,22 @@ @@ -1133,6 +1454,20 @@
protected SoundEvent getSwimHighSpeedSplashSound() {
return SoundEvents.GENERIC_SPLASH; return SoundEvents.GENERIC_SPLASH;
+ } }
+
+ // CraftBukkit start - Add delegate methods + // CraftBukkit start - Add delegate methods
+ public SoundEvent getSwimSound0() { + public SoundEvent getSwimSound0() {
+ return this.getSwimSound(); + return this.getSwimSound();
} + }
+
+ public SoundEvent getSwimSplashSound0() { + public SoundEvent getSwimSplashSound0() {
+ return this.getSwimSplashSound(); + return this.getSwimSplashSound();
+ } + }
@@ -555,7 +557,7 @@
public void recordMovementThroughBlocks(Vec3 oldPos, Vec3 newPos) { public void recordMovementThroughBlocks(Vec3 oldPos, Vec3 newPos) {
this.movementThisTick.add(new Entity.Movement(oldPos, newPos)); this.movementThisTick.add(new Entity.Movement(oldPos, newPos));
} }
@@ -1609,6 +1943,7 @@ @@ -1609,6 +1944,7 @@
this.yo = y; this.yo = y;
this.zo = d4; this.zo = d4;
this.setPos(d3, y, d4); this.setPos(d3, y, d4);
@@ -563,21 +565,20 @@
} }
public void moveTo(Vec3 pos) { public void moveTo(Vec3 pos) {
@@ -1859,7 +2194,13 @@ @@ -1861,6 +2197,12 @@
public boolean isPushable() {
return false; return false;
+ } }
+
+ // CraftBukkit start - collidable API + // CraftBukkit start - collidable API
+ public boolean canCollideWithBukkit(Entity entity) { + public boolean canCollideWithBukkit(Entity entity) {
+ return this.isPushable(); + return this.isPushable();
} + }
+ // CraftBukkit end + // CraftBukkit end
+
public void awardKillScore(Entity entityKilled, DamageSource damageSource) { public void awardKillScore(Entity entityKilled, DamageSource damageSource) {
if (entityKilled instanceof ServerPlayer) { if (entityKilled instanceof ServerPlayer) {
@@ -1889,16 +2230,22 @@ CriteriaTriggers.ENTITY_KILLED_PLAYER.trigger((ServerPlayer) entityKilled, this, damageSource);
@@ -1889,16 +2231,22 @@
} }
public boolean saveAsPassenger(CompoundTag nbt) { public boolean saveAsPassenger(CompoundTag nbt) {
@@ -603,7 +604,7 @@
return true; return true;
} }
} }
@@ -1909,54 +2256,98 @@ @@ -1909,54 +2257,98 @@
} }
public CompoundTag saveWithoutId(CompoundTag nbt) { public CompoundTag saveWithoutId(CompoundTag nbt) {
@@ -722,7 +723,7 @@
} }
ListTag nbttaglist; ListTag nbttaglist;
@@ -1972,10 +2363,10 @@ @@ -1972,10 +2364,10 @@
nbttaglist.add(StringTag.valueOf(s)); nbttaglist.add(StringTag.valueOf(s));
} }
@@ -735,7 +736,7 @@
if (this.isVehicle()) { if (this.isVehicle()) {
nbttaglist = new ListTag(); nbttaglist = new ListTag();
iterator = this.getPassengers().iterator(); iterator = this.getPassengers().iterator();
@@ -1984,17 +2375,31 @@ @@ -1984,17 +2376,31 @@
Entity entity = (Entity) iterator.next(); Entity entity = (Entity) iterator.next();
CompoundTag nbttagcompound1 = new CompoundTag(); CompoundTag nbttagcompound1 = new CompoundTag();
@@ -770,7 +771,7 @@
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT"); CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being saved"); CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being saved");
@@ -2080,6 +2485,64 @@ @@ -2080,6 +2486,64 @@
} else { } else {
throw new IllegalStateException("Entity has invalid position"); throw new IllegalStateException("Entity has invalid position");
} }
@@ -835,7 +836,7 @@
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT"); CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded"); CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
@@ -2101,6 +2564,12 @@ @@ -2101,6 +2565,12 @@
return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null; return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null;
} }
@@ -848,7 +849,7 @@
protected abstract void readAdditionalSaveData(CompoundTag nbt); protected abstract void readAdditionalSaveData(CompoundTag nbt);
protected abstract void addAdditionalSaveData(CompoundTag nbt); protected abstract void addAdditionalSaveData(CompoundTag nbt);
@@ -2153,9 +2622,22 @@ @@ -2153,9 +2623,22 @@
if (stack.isEmpty()) { if (stack.isEmpty()) {
return null; return null;
} else { } else {
@@ -871,7 +872,7 @@
world.addFreshEntity(entityitem); world.addFreshEntity(entityitem);
return entityitem; return entityitem;
} }
@@ -2184,6 +2666,12 @@ @@ -2184,6 +2667,12 @@
if (this.isAlive() && this instanceof Leashable leashable) { if (this.isAlive() && this instanceof Leashable leashable) {
if (leashable.getLeashHolder() == player) { if (leashable.getLeashHolder() == player) {
if (!this.level().isClientSide()) { if (!this.level().isClientSide()) {
@@ -884,7 +885,7 @@
if (player.hasInfiniteMaterials()) { if (player.hasInfiniteMaterials()) {
leashable.removeLeash(); leashable.removeLeash();
} else { } else {
@@ -2200,6 +2688,13 @@ @@ -2200,6 +2689,13 @@
if (itemstack.is(Items.LEAD) && leashable.canHaveALeashAttachedToIt()) { if (itemstack.is(Items.LEAD) && leashable.canHaveALeashAttachedToIt()) {
if (!this.level().isClientSide()) { if (!this.level().isClientSide()) {
@@ -898,7 +899,7 @@
leashable.setLeashedTo(player, true); leashable.setLeashedTo(player, true);
} }
@@ -2265,7 +2760,7 @@ @@ -2265,7 +2761,7 @@
} }
public boolean showVehicleHealth() { public boolean showVehicleHealth() {
@@ -907,7 +908,7 @@
} }
public boolean startRiding(Entity entity, boolean force) { public boolean startRiding(Entity entity, boolean force) {
@@ -2273,7 +2768,7 @@ @@ -2273,7 +2769,7 @@
return false; return false;
} else if (!entity.couldAcceptPassenger()) { } else if (!entity.couldAcceptPassenger()) {
return false; return false;
@@ -916,7 +917,7 @@
return false; return false;
} else { } else {
for (Entity entity1 = entity; entity1.vehicle != null; entity1 = entity1.vehicle) { for (Entity entity1 = entity; entity1.vehicle != null; entity1 = entity1.vehicle) {
@@ -2285,11 +2780,32 @@ @@ -2285,11 +2781,32 @@
if (!force && (!this.canRide(entity) || !entity.canAddPassenger(this))) { if (!force && (!this.canRide(entity) || !entity.canAddPassenger(this))) {
return false; return false;
} else { } else {
@@ -950,7 +951,7 @@
this.vehicle = entity; this.vehicle = entity;
this.vehicle.addPassenger(this); this.vehicle.addPassenger(this);
entity.getIndirectPassengersStream().filter((entity2) -> { entity.getIndirectPassengersStream().filter((entity2) -> {
@@ -2318,7 +2834,7 @@ @@ -2318,7 +2835,7 @@
Entity entity = this.vehicle; Entity entity = this.vehicle;
this.vehicle = null; this.vehicle = null;
@@ -959,7 +960,7 @@
} }
} }
@@ -2349,21 +2865,50 @@ @@ -2349,21 +2866,50 @@
} }
} }
@@ -1016,7 +1017,7 @@
} }
protected boolean canAddPassenger(Entity passenger) { protected boolean canAddPassenger(Entity passenger) {
@@ -2464,7 +3009,7 @@ @@ -2464,7 +3010,7 @@
if (teleporttransition != null) { if (teleporttransition != null) {
ServerLevel worldserver1 = teleporttransition.newLevel(); ServerLevel worldserver1 = teleporttransition.newLevel();
@@ -1025,7 +1026,7 @@
this.teleport(teleporttransition); this.teleport(teleporttransition);
} }
} }
@@ -2547,7 +3092,7 @@ @@ -2547,7 +3093,7 @@
} }
public boolean isCrouching() { public boolean isCrouching() {
@@ -1034,7 +1035,7 @@
} }
public boolean isSprinting() { public boolean isSprinting() {
@@ -2563,7 +3108,7 @@ @@ -2563,7 +3109,7 @@
} }
public boolean isVisuallySwimming() { public boolean isVisuallySwimming() {
@@ -1043,7 +1044,7 @@
} }
public boolean isVisuallyCrawling() { public boolean isVisuallyCrawling() {
@@ -2571,6 +3116,13 @@ @@ -2571,6 +3117,13 @@
} }
public void setSwimming(boolean swimming) { public void setSwimming(boolean swimming) {
@@ -1057,7 +1058,7 @@
this.setSharedFlag(4, swimming); this.setSharedFlag(4, swimming);
} }
@@ -2609,6 +3161,7 @@ @@ -2609,6 +3162,7 @@
@Nullable @Nullable
public PlayerTeam getTeam() { public PlayerTeam getTeam() {
@@ -1065,7 +1066,7 @@
return this.level().getScoreboard().getPlayersTeam(this.getScoreboardName()); return this.level().getScoreboard().getPlayersTeam(this.getScoreboardName());
} }
@@ -2624,8 +3177,12 @@ @@ -2624,8 +3178,12 @@
return this.getTeam() != null ? this.getTeam().isAlliedTo(team) : false; return this.getTeam() != null ? this.getTeam().isAlliedTo(team) : false;
} }
@@ -1079,7 +1080,7 @@
} }
public boolean getSharedFlag(int index) { public boolean getSharedFlag(int index) {
@@ -2644,7 +3201,7 @@ @@ -2644,7 +3202,7 @@
} }
public int getMaxAirSupply() { public int getMaxAirSupply() {
@@ -1088,7 +1089,7 @@
} }
public int getAirSupply() { public int getAirSupply() {
@@ -2652,7 +3209,18 @@ @@ -2652,7 +3210,18 @@
} }
public void setAirSupply(int air) { public void setAirSupply(int air) {
@@ -1108,7 +1109,7 @@
} }
public int getTicksFrozen() { public int getTicksFrozen() {
@@ -2679,11 +3247,40 @@ @@ -2679,11 +3248,40 @@
public void thunderHit(ServerLevel world, LightningBolt lightning) { public void thunderHit(ServerLevel world, LightningBolt lightning) {
this.setRemainingFireTicks(this.remainingFireTicks + 1); this.setRemainingFireTicks(this.remainingFireTicks + 1);
@@ -1151,7 +1152,7 @@
} }
public void onAboveBubbleCol(boolean drag) { public void onAboveBubbleCol(boolean drag) {
@@ -2713,7 +3310,7 @@ @@ -2713,7 +3311,7 @@
this.resetFallDistance(); this.resetFallDistance();
} }
@@ -1160,7 +1161,7 @@
return true; return true;
} }
@@ -2852,6 +3449,18 @@ @@ -2852,6 +3450,18 @@
if (world instanceof ServerLevel worldserver) { if (world instanceof ServerLevel worldserver) {
if (!this.isRemoved()) { if (!this.isRemoved()) {
@@ -1179,7 +1180,7 @@
ServerLevel worldserver1 = teleportTarget.newLevel(); ServerLevel worldserver1 = teleportTarget.newLevel();
boolean flag = worldserver1.dimension() != worldserver.dimension(); boolean flag = worldserver1.dimension() != worldserver.dimension();
@@ -2920,8 +3529,12 @@ @@ -2920,8 +3530,12 @@
} else { } else {
entity.restoreFrom(this); entity.restoreFrom(this);
this.removeAfterChangingDimensions(); this.removeAfterChangingDimensions();
@@ -1193,7 +1194,7 @@
Iterator iterator1 = list1.iterator(); Iterator iterator1 = list1.iterator();
while (iterator1.hasNext()) { while (iterator1.hasNext()) {
@@ -2947,7 +3560,7 @@ @@ -2947,7 +3561,7 @@
} }
private void sendTeleportTransitionToRidingPlayers(TeleportTransition teleportTarget) { private void sendTeleportTransitionToRidingPlayers(TeleportTransition teleportTarget) {
@@ -1202,7 +1203,7 @@
Iterator iterator = this.getIndirectPassengers().iterator(); Iterator iterator = this.getIndirectPassengers().iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
@@ -2995,8 +3608,9 @@ @@ -2995,8 +3609,9 @@
} }
protected void removeAfterChangingDimensions() { protected void removeAfterChangingDimensions() {
@@ -1213,7 +1214,7 @@
leashable.removeLeash(); leashable.removeLeash();
} }
@@ -3004,7 +3618,21 @@ @@ -3004,7 +3619,21 @@
public Vec3 getRelativePortalPosition(Direction.Axis portalAxis, BlockUtil.FoundRectangle portalRect) { public Vec3 getRelativePortalPosition(Direction.Axis portalAxis, BlockUtil.FoundRectangle portalRect) {
return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose())); return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose()));
@@ -1235,7 +1236,7 @@
public boolean canUsePortal(boolean allowVehicles) { public boolean canUsePortal(boolean allowVehicles) {
return (allowVehicles || !this.isPassenger()) && this.isAlive(); return (allowVehicles || !this.isPassenger()) && this.isAlive();
@@ -3134,9 +3762,15 @@ @@ -3134,9 +3763,15 @@
return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE); return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE);
} }
@@ -1254,7 +1255,7 @@
return entity != null; return entity != null;
} }
@@ -3187,7 +3821,7 @@ @@ -3187,7 +3822,7 @@
/** @deprecated */ /** @deprecated */
@Deprecated @Deprecated
protected void fixupDimensions() { protected void fixupDimensions() {
@@ -1263,7 +1264,7 @@
EntityDimensions entitysize = this.getDimensions(entitypose); EntityDimensions entitysize = this.getDimensions(entitypose);
this.dimensions = entitysize; this.dimensions = entitysize;
@@ -3196,7 +3830,7 @@ @@ -3196,7 +3831,7 @@
public void refreshDimensions() { public void refreshDimensions() {
EntityDimensions entitysize = this.dimensions; EntityDimensions entitysize = this.dimensions;
@@ -1272,7 +1273,7 @@
EntityDimensions entitysize1 = this.getDimensions(entitypose); EntityDimensions entitysize1 = this.getDimensions(entitypose);
this.dimensions = entitysize1; this.dimensions = entitysize1;
@@ -3258,10 +3892,29 @@ @@ -3258,10 +3893,29 @@
} }
public final void setBoundingBox(AABB boundingBox) { public final void setBoundingBox(AABB boundingBox) {
@@ -1304,7 +1305,7 @@
return this.getDimensions(pose).eyeHeight(); return this.getDimensions(pose).eyeHeight();
} }
@@ -3335,7 +3988,7 @@ @@ -3335,7 +3989,7 @@
} }
@Nullable @Nullable
@@ -1313,7 +1314,7 @@
return null; return null;
} }
@@ -3435,7 +4088,7 @@ @@ -3435,7 +4089,7 @@
} }
public boolean isControlledByLocalInstance() { public boolean isControlledByLocalInstance() {
@@ -1322,7 +1323,7 @@
if (entityliving instanceof Player entityhuman) { if (entityliving instanceof Player entityhuman) {
return entityhuman.isLocalPlayer(); return entityhuman.isLocalPlayer();
@@ -3445,7 +4098,7 @@ @@ -3445,7 +4099,7 @@
} }
public boolean isControlledByClient() { public boolean isControlledByClient() {
@@ -1331,7 +1332,7 @@
return entityliving != null && entityliving.isControlledByClient(); return entityliving != null && entityliving.isControlledByClient();
} }
@@ -3463,7 +4116,7 @@ @@ -3463,7 +4117,7 @@
return new Vec3((double) f1 * d2 / (double) f3, 0.0D, (double) f2 * d2 / (double) f3); return new Vec3((double) f1 * d2 / (double) f3, 0.0D, (double) f2 * d2 / (double) f3);
} }
@@ -1340,7 +1341,7 @@
return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ()); return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ());
} }
@@ -3488,9 +4141,38 @@ @@ -3488,9 +4142,38 @@
public int getFireImmuneTicks() { public int getFireImmuneTicks() {
return 1; return 1;
} }
@@ -1380,7 +1381,7 @@
} }
public void lookAt(EntityAnchorArgument.Anchor anchorPoint, Vec3 target) { public void lookAt(EntityAnchorArgument.Anchor anchorPoint, Vec3 target) {
@@ -3550,7 +4232,12 @@ @@ -3550,7 +4233,12 @@
vec3d = vec3d.add(vec3d1); vec3d = vec3d.add(vec3d1);
++k1; ++k1;
@@ -1393,7 +1394,7 @@
} }
} }
} }
@@ -3613,7 +4300,7 @@ @@ -3613,7 +4301,7 @@
return new ClientboundAddEntityPacket(this, entityTrackerEntry); return new ClientboundAddEntityPacket(this, entityTrackerEntry);
} }
@@ -1402,7 +1403,7 @@
return this.type.getDimensions(); return this.type.getDimensions();
} }
@@ -3818,8 +4505,16 @@ @@ -3818,8 +4506,16 @@
@Override @Override
public final void setRemoved(Entity.RemovalReason reason) { public final void setRemoved(Entity.RemovalReason reason) {
@@ -1420,7 +1421,7 @@
} }
if (this.removalReason.shouldDestroy()) { if (this.removalReason.shouldDestroy()) {
@@ -3827,8 +4522,8 @@ @@ -3827,8 +4523,8 @@
} }
this.getPassengers().forEach(Entity::stopRiding); this.getPassengers().forEach(Entity::stopRiding);
@@ -1431,7 +1432,7 @@
} }
public void unsetRemoved() { public void unsetRemoved() {
@@ -3887,7 +4582,7 @@ @@ -3887,7 +4583,7 @@
} }
public Vec3 getKnownMovement() { public Vec3 getKnownMovement() {

View File

@@ -161,24 +161,23 @@
} }
public void onEquipItem(EquipmentSlot slot, ItemStack oldStack, ItemStack newStack) { public void onEquipItem(EquipmentSlot slot, ItemStack oldStack, ItemStack newStack) {
- if (!this.level().isClientSide() && !this.isSpectator()) {
- boolean flag = newStack.isEmpty() && oldStack.isEmpty();
+ // CraftBukkit start + // CraftBukkit start
+ this.onEquipItem(slot, oldStack, newStack, false); + this.onEquipItem(slot, oldStack, newStack, false);
+ } + }
+
+ public void onEquipItem(EquipmentSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1, boolean silent) {
+ // CraftBukkit end
if (!this.level().isClientSide() && !this.isSpectator()) {
- boolean flag = newStack.isEmpty() && oldStack.isEmpty();
+ boolean flag = itemstack1.isEmpty() && itemstack.isEmpty();
- if (!flag && !ItemStack.isSameItemSameComponents(oldStack, newStack) && !this.firstTick) { - if (!flag && !ItemStack.isSameItemSameComponents(oldStack, newStack) && !this.firstTick) {
- Equippable equippable = (Equippable) newStack.get(DataComponents.EQUIPPABLE); - Equippable equippable = (Equippable) newStack.get(DataComponents.EQUIPPABLE);
+ public void onEquipItem(EquipmentSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1, boolean silent) { + if (!flag && !ItemStack.isSameItemSameComponents(itemstack, itemstack1) && !this.firstTick) {
+ // CraftBukkit end + Equippable equippable = (Equippable) itemstack1.get(DataComponents.EQUIPPABLE);
+ if (!this.level().isClientSide() && !this.isSpectator()) {
+ boolean flag = itemstack1.isEmpty() && itemstack.isEmpty();
- if (!this.isSilent() && equippable != null && slot == equippable.slot()) { - if (!this.isSilent() && equippable != null && slot == equippable.slot()) {
- this.level().playSeededSound((Player) null, this.getX(), this.getY(), this.getZ(), equippable.equipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong()); - this.level().playSeededSound((Player) null, this.getX(), this.getY(), this.getZ(), equippable.equipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong());
+ if (!flag && !ItemStack.isSameItemSameComponents(itemstack, itemstack1) && !this.firstTick) {
+ Equippable equippable = (Equippable) itemstack1.get(DataComponents.EQUIPPABLE);
+
+ if (!this.isSilent() && equippable != null && enumitemslot == equippable.slot() && !silent) { // CraftBukkit + if (!this.isSilent() && equippable != null && enumitemslot == equippable.slot() && !silent) { // CraftBukkit
+ this.level().playSeededSound((net.minecraft.world.entity.player.Player) null, this.getX(), this.getY(), this.getZ(), equippable.equipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong()); + this.level().playSeededSound((net.minecraft.world.entity.player.Player) null, this.getX(), this.getY(), this.getZ(), equippable.equipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong());
} }
@@ -311,11 +310,10 @@
iterator.remove(); iterator.remove();
this.onEffectsRemoved(List.of(mobeffect)); this.onEffectsRemoved(List.of(mobeffect));
} }
@@ -840,7 +955,18 @@ @@ -841,6 +956,17 @@
}
} catch (ConcurrentModificationException concurrentmodificationexception) { } catch (ConcurrentModificationException concurrentmodificationexception) {
; ;
+ } }
+ // CraftBukkit start + // CraftBukkit start
+ this.isTickingEffects = false; + this.isTickingEffects = false;
+ for (ProcessableEffect e : this.effectsToProcess) { + for (ProcessableEffect e : this.effectsToProcess) {
@@ -324,7 +322,7 @@
+ } else { + } else {
+ this.removeEffect(e.type, e.cause); + this.removeEffect(e.type, e.cause);
+ } + }
} + }
+ this.effectsToProcess.clear(); + this.effectsToProcess.clear();
+ // CraftBukkit end + // CraftBukkit end
@@ -936,7 +934,7 @@
+ }; + };
+ float freezingModifier = freezing.apply((double) f).floatValue(); + float freezingModifier = freezing.apply((double) f).floatValue();
+ f += freezingModifier; + f += freezingModifier;
+
+ com.google.common.base.Function<Double, Double> hardHat = new com.google.common.base.Function<Double, Double>() { + com.google.common.base.Function<Double, Double> hardHat = new com.google.common.base.Function<Double, Double>() {
+ @Override + @Override
+ public Double apply(Double f) { + public Double apply(Double f) {
@@ -957,7 +955,7 @@
+ }; + };
+ float blockingModifier = blocking.apply((double) f).floatValue(); + float blockingModifier = blocking.apply((double) f).floatValue();
+ f += blockingModifier; + f += blockingModifier;
+
+ com.google.common.base.Function<Double, Double> armor = new com.google.common.base.Function<Double, Double>() { + com.google.common.base.Function<Double, Double> armor = new com.google.common.base.Function<Double, Double>() {
+ @Override + @Override
+ public Double apply(Double f) { + public Double apply(Double f) {
@@ -1116,26 +1114,27 @@
} }
public CombatTracker getCombatTracker() { public CombatTracker getCombatTracker() {
@@ -1935,8 +2432,18 @@ @@ -1935,9 +2432,19 @@
} }
public final void setArrowCount(int stuckArrowCount) { public final void setArrowCount(int stuckArrowCount) {
- this.entityData.set(LivingEntity.DATA_ARROW_COUNT_ID, stuckArrowCount); - this.entityData.set(LivingEntity.DATA_ARROW_COUNT_ID, stuckArrowCount);
+ // CraftBukkit start + // CraftBukkit start
+ this.setArrowCount(stuckArrowCount, false); + this.setArrowCount(stuckArrowCount, false);
+ } }
+
+ public final void setArrowCount(int i, boolean flag) { + public final void setArrowCount(int i, boolean flag) {
+ ArrowBodyCountChangeEvent event = CraftEventFactory.callArrowBodyCountChangeEvent(this, this.getArrowCount(), i, flag); + ArrowBodyCountChangeEvent event = CraftEventFactory.callArrowBodyCountChangeEvent(this, this.getArrowCount(), i, flag);
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ return; + return;
+ } + }
+ this.entityData.set(LivingEntity.DATA_ARROW_COUNT_ID, event.getNewAmount()); + this.entityData.set(LivingEntity.DATA_ARROW_COUNT_ID, event.getNewAmount());
} + }
+ // CraftBukkit end + // CraftBukkit end
+
public final int getStingerCount() { public final int getStingerCount() {
return (Integer) this.entityData.get(LivingEntity.DATA_STINGER_COUNT_ID); return (Integer) this.entityData.get(LivingEntity.DATA_STINGER_COUNT_ID);
}
@@ -1999,7 +2506,7 @@ @@ -1999,7 +2506,7 @@
this.playSound(soundeffect, this.getSoundVolume(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); this.playSound(soundeffect, this.getSoundVolume(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
} }
@@ -1246,7 +1245,22 @@
} else { } else {
List list = this.level().getEntities((Entity) this, this.getBoundingBox(), EntitySelector.pushableBy(this)); List list = this.level().getEntities((Entity) this, this.getBoundingBox(), EntitySelector.pushableBy(this));
@@ -3305,15 +3819,22 @@ @@ -3138,10 +3652,12 @@
}
Iterator iterator1 = list.iterator();
+ this.numCollisions = Math.max(0, this.numCollisions - this.level().paperConfig().collisions.maxEntityCollisions); // Paper - Cap entity collisions
- while (iterator1.hasNext()) {
+ while (iterator1.hasNext() && this.numCollisions < this.level().paperConfig().collisions.maxEntityCollisions) { // Paper - Cap entity collisions
Entity entity1 = (Entity) iterator1.next();
-
+ entity1.numCollisions++; // Paper - Cap entity collisions
+ this.numCollisions++; // Paper - Cap entity collisions
this.doPush(entity1);
}
}
@@ -3305,15 +3821,22 @@
@Override @Override
public boolean isPickable() { public boolean isPickable() {
@@ -1271,7 +1285,7 @@
public float getYHeadRot() { public float getYHeadRot() {
return this.yHeadRot; return this.yHeadRot;
} }
@@ -3342,7 +3863,7 @@ @@ -3342,7 +3865,7 @@
} }
public final void setAbsorptionAmount(float absorptionAmount) { public final void setAbsorptionAmount(float absorptionAmount) {
@@ -1280,7 +1294,7 @@
} }
protected void internalSetAbsorptionAmount(float absorptionAmount) { protected void internalSetAbsorptionAmount(float absorptionAmount) {
@@ -3483,13 +4004,48 @@ @@ -3483,13 +4006,48 @@
this.releaseUsingItem(); this.releaseUsingItem();
} else { } else {
if (!this.useItem.isEmpty() && this.isUsingItem()) { if (!this.useItem.isEmpty() && this.isUsingItem()) {
@@ -1330,7 +1344,7 @@
} }
} }
@@ -3568,12 +4124,18 @@ @@ -3568,12 +4126,18 @@
} }
public boolean randomTeleport(double x, double y, double z, boolean particleEffects) { public boolean randomTeleport(double x, double y, double z, boolean particleEffects) {
@@ -1351,7 +1365,7 @@
Level world = this.level(); Level world = this.level();
if (world.hasChunkAt(blockposition)) { if (world.hasChunkAt(blockposition)) {
@@ -3592,18 +4154,43 @@ @@ -3592,18 +4156,43 @@
} }
if (flag2) { if (flag2) {
@@ -1399,7 +1413,7 @@
world.broadcastEntityEvent(this, (byte) 46); world.broadcastEntityEvent(this, (byte) 46);
} }
@@ -3613,7 +4200,7 @@ @@ -3613,7 +4202,7 @@
entitycreature.getNavigation().stop(); entitycreature.getNavigation().stop();
} }
@@ -1408,7 +1422,7 @@
} }
} }
@@ -3706,7 +4293,7 @@ @@ -3706,7 +4295,7 @@
} }
public void stopSleeping() { public void stopSleeping() {
@@ -1417,7 +1431,7 @@
Level world = this.level(); Level world = this.level();
java.util.Objects.requireNonNull(world); java.util.Objects.requireNonNull(world);
@@ -3718,9 +4305,9 @@ @@ -3718,9 +4307,9 @@
this.level().setBlock(blockposition, (BlockState) iblockdata.setValue(BedBlock.OCCUPIED, false), 3); this.level().setBlock(blockposition, (BlockState) iblockdata.setValue(BedBlock.OCCUPIED, false), 3);
Vec3 vec3d = (Vec3) BedBlock.findStandUpPosition(this.getType(), this.level(), blockposition, enumdirection, this.getYRot()).orElseGet(() -> { Vec3 vec3d = (Vec3) BedBlock.findStandUpPosition(this.getType(), this.level(), blockposition, enumdirection, this.getYRot()).orElseGet(() -> {
@@ -1429,7 +1443,7 @@
}); });
Vec3 vec3d1 = Vec3.atBottomCenterOf(blockposition).subtract(vec3d).normalize(); Vec3 vec3d1 = Vec3.atBottomCenterOf(blockposition).subtract(vec3d).normalize();
float f = (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D); float f = (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
@@ -3740,7 +4327,7 @@ @@ -3740,7 +4329,7 @@
@Nullable @Nullable
public Direction getBedOrientation() { public Direction getBedOrientation() {
@@ -1438,7 +1452,7 @@
return blockposition != null ? BedBlock.getBedOrientation(this.level(), blockposition) : null; return blockposition != null ? BedBlock.getBedOrientation(this.level(), blockposition) : null;
} }
@@ -3905,7 +4492,7 @@ @@ -3905,7 +4494,7 @@
public float maxUpStep() { public float maxUpStep() {
float f = (float) this.getAttributeValue(Attributes.STEP_HEIGHT); float f = (float) this.getAttributeValue(Attributes.STEP_HEIGHT);