fix crash when using MaxEntityCollisions rule in Singleplayer world
This commit is contained in:
1 parent
2a2c41ddce
commit
85803cecbb
1 file changed
+11
-4
@@ -2,6 +2,7 @@ package carpet.mixins;
|
|||||||
|
|
||||||
import carpet.CarpetSettings;
|
import carpet.CarpetSettings;
|
||||||
import carpet.fakes.LevelInterface;
|
import carpet.fakes.LevelInterface;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -33,12 +34,18 @@ public abstract class LivingEntity_maxCollisionsMixin extends Entity
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(this.level() instanceof ServerLevel serverLevel))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
List<Entity> entities;
|
List<Entity> entities;
|
||||||
int maxEntityCramming =-1;
|
int maxEntityCramming =-1;
|
||||||
if (CarpetSettings.maxEntityCollisions > 0)
|
if (CarpetSettings.maxEntityCollisions > 0)
|
||||||
{
|
{
|
||||||
maxEntityCramming = this.getServer().getGameRules().getInt(GameRules.RULE_MAX_ENTITY_CRAMMING);
|
maxEntityCramming = serverLevel.getGameRules().getInt(GameRules.RULE_MAX_ENTITY_CRAMMING);
|
||||||
entities = ((LevelInterface) this.level()).getOtherEntitiesLimited(
|
entities = ((LevelInterface) serverLevel).getOtherEntitiesLimited(
|
||||||
this,
|
this,
|
||||||
this.getBoundingBox(),
|
this.getBoundingBox(),
|
||||||
EntitySelector.pushableBy(this),
|
EntitySelector.pushableBy(this),
|
||||||
@@ -46,11 +53,11 @@ public abstract class LivingEntity_maxCollisionsMixin extends Entity
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
entities = this.level().getEntities(this, this.getBoundingBox(), EntitySelector.pushableBy(this));
|
entities = serverLevel.getEntities(this, this.getBoundingBox(), EntitySelector.pushableBy(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entities.isEmpty()) {
|
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) {
|
if (maxEntityCramming > 0 && entities.size() > maxEntityCramming - 1 && this.random.nextInt(4) == 0) {
|
||||||
int candidates = 0;
|
int candidates = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user