diff --git a/src/main/java/carpet/mixins/LivingEntity_maxCollisionsMixin.java b/src/main/java/carpet/mixins/LivingEntity_maxCollisionsMixin.java index 7adfd1f9d..90474f0ed 100644 --- a/src/main/java/carpet/mixins/LivingEntity_maxCollisionsMixin.java +++ b/src/main/java/carpet/mixins/LivingEntity_maxCollisionsMixin.java @@ -2,6 +2,7 @@ import carpet.CarpetSettings; import carpet.fakes.LevelInterface; +import net.minecraft.server.level.ServerLevel; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -33,12 +34,18 @@ private void tickPushingReplacement(CallbackInfo ci) { { return; } + + if (!(this.level() instanceof ServerLevel serverLevel)) + { + return; + } + List entities; int maxEntityCramming =-1; if (CarpetSettings.maxEntityCollisions > 0) { - maxEntityCramming = this.getServer().getGameRules().getInt(GameRules.RULE_MAX_ENTITY_CRAMMING); - entities = ((LevelInterface) this.level()).getOtherEntitiesLimited( + maxEntityCramming = serverLevel.getGameRules().getInt(GameRules.RULE_MAX_ENTITY_CRAMMING); + entities = ((LevelInterface) serverLevel).getOtherEntitiesLimited( this, this.getBoundingBox(), EntitySelector.pushableBy(this), @@ -46,11 +53,11 @@ private void tickPushingReplacement(CallbackInfo ci) { } else { - entities = this.level().getEntities(this, this.getBoundingBox(), EntitySelector.pushableBy(this)); + entities = serverLevel.getEntities(this, this.getBoundingBox(), EntitySelector.pushableBy(this)); } if (!entities.isEmpty()) { - if (maxEntityCramming < 0) maxEntityCramming = this.getServer().getGameRules().getInt(GameRules.RULE_MAX_ENTITY_CRAMMING); + if (maxEntityCramming < 0) maxEntityCramming = serverLevel.getGameRules().getInt(GameRules.RULE_MAX_ENTITY_CRAMMING); if (maxEntityCramming > 0 && entities.size() > maxEntityCramming - 1 && this.random.nextInt(4) == 0) { int candidates = 0;