fixes #1105 maxEntityCollisions will not affect maxEntityCramming setting

This commit is contained in:
gnembon committed 2021-11-27 20:58:23 +01:00
1 parent 7bd18a27e4
commit 0e1a8f20d4
1 file changed
+21 -5
@@ -31,17 +31,23 @@ public abstract class LivingEntity_maxCollisionsMixin extends Entity
@Inject(method = "tickCramming", cancellable = true, at = @At("HEAD")) @Inject(method = "tickCramming", cancellable = true, at = @At("HEAD"))
private void tickPushingReplacement(CallbackInfo ci) { private void tickPushingReplacement(CallbackInfo ci) {
List<Entity> entities; List<Entity> entities;
int maxEntityCramming =-1;
if (CarpetSettings.maxEntityCollisions > 0) if (CarpetSettings.maxEntityCollisions > 0)
{
maxEntityCramming = this.world.getGameRules().getInt(GameRules.MAX_ENTITY_CRAMMING);
entities = ((WorldInterface) this.world).getOtherEntitiesLimited( entities = ((WorldInterface) this.world).getOtherEntitiesLimited(
this, this,
this.getBoundingBox(), this.getBoundingBox(),
EntityPredicates.canBePushedBy(this), EntityPredicates.canBePushedBy(this),
CarpetSettings.maxEntityCollisions); Math.max(CarpetSettings.maxEntityCollisions, maxEntityCramming));
}
else else
{
entities = this.world.getOtherEntities(this, this.getBoundingBox(), EntityPredicates.canBePushedBy(this)); entities = this.world.getOtherEntities(this, this.getBoundingBox(), EntityPredicates.canBePushedBy(this));
}
if (!entities.isEmpty()) { if (!entities.isEmpty()) {
int maxEntityCramming = this.world.getGameRules().getInt(GameRules.MAX_ENTITY_CRAMMING); if (maxEntityCramming < 0) maxEntityCramming = this.world.getGameRules().getInt(GameRules.MAX_ENTITY_CRAMMING);
if (maxEntityCramming > 0 && entities.size() > maxEntityCramming - 1 && this.random.nextInt(4) == 0) { if (maxEntityCramming > 0 && entities.size() > maxEntityCramming - 1 && this.random.nextInt(4) == 0) {
int candidates = 0; int candidates = 0;
@@ -55,9 +61,19 @@ public abstract class LivingEntity_maxCollisionsMixin extends Entity
this.damage(DamageSource.CRAMMING, 6.0F); this.damage(DamageSource.CRAMMING, 6.0F);
} }
} }
if (CarpetSettings.maxEntityCollisions > 0 && entities.size() > CarpetSettings.maxEntityCollisions)
for (Entity entity : entities) { {
this.pushAway(entity); for (Entity entity : entities.subList(0, CarpetSettings.maxEntityCollisions))
{
this.pushAway(entity);
}
}
else
{
for (Entity entity : entities)
{
this.pushAway(entity);
}
} }
} }
ci.cancel(); ci.cancel();