mojira.dev
MC-190669

For almost all slime spawn attempts the game recalculates if a certain chunk is a slime chunk

In most cases when a slime does a spawn attempt it recalculates if the chunk it tries to spawn in is a slime chunk

// yarn mappings
net.minecraft.entity.mob.SlimeEntity.java
public static boolean canSpawn(EntityType<SlimeEntity> arg, WorldAccess arg2, SpawnReason arg3, BlockPos arg4, Random random) {
    if (arg2.getDifficulty() != Difficulty.PEACEFUL) {
        boolean bl;
        Biome lv = arg2.getBiome(arg4);
        if (lv == Biomes.SWAMP && arg4.getY() > 50 && arg4.getY() < 70 && random.nextFloat() < 0.5f && random.nextFloat() < arg2.getMoonSize() && arg2.getLightLevel(arg4) <= random.nextInt(8)) {
            return SlimeEntity.canMobSpawn(arg, arg2, arg3, arg4, random);
        }
        if (!(arg2 instanceof ServerWorldAccess)) {
            return false;
        }

        ChunkPos lv2 = new ChunkPos(arg4);
        boolean bl2 = bl = ChunkRandom.getSlimeRandom(lv2.x, lv2.z, ((ServerWorldAccess)arg2).getSeed(), 987234911L).nextInt(10) == 0;
        if (random.nextInt(10) == 0 && bl && arg4.getY() < 40) {
            return SlimeEntity.canMobSpawn(arg, arg2, arg3, arg4, random);
        }
    }
    return false;

As you can see in the code, the came checks if the spawn attempt is in a swamp between y50 and y70 first (along with some other stuff). If that is not the case the spawn attempt will always calculate if it's in a slime chunk or not. This is a very inefficient way of handling this.

One better way of doing it would be to either calculate if a chunk is a slime chunk when the world generates and using that each spawn attempt, or at least moving some of the if statements around so it doesn't calculate if its a slime chunk even if the spawn attempt happens at y200 where obviously no slime should ever be able to spawn if it's not in a swamp.

Doing this seems like a waste of resources since it would be very easy to optimize it.

Comments 4

I can confirm that this bug has actually existed since at least 1.12.2, because I actually found it while code digging in 1.12.2, I didn't really consider it to be a bug though. It more just inefficient use of system resources, which this is one of many things that fall into that category.

Would be nice to get this reopened. Slime spawning is unnecessarily resource heavy and as already mentioned could be easily optimised. It greatly affects players with lower end hardware. The height changes being made in 1.18 is only going to exasperate this further

⚠️ Please do not add Affected Versions to resolved reports.

Have a look at the Resolution and the comments to see why this ticket has been resolved. If you think this ticket has been resolved erroneously you can contact the Mojira staff on Discord or Reddit.

-- I am a bot. This action was performed automatically! If you think it was incorrect, please notify us on Discord or Reddit

Viktor40

(Unassigned)

Community Consensus

Performance

Entities, Spawning, mob-spawning

1.15.2, 1.16 Release Candidate 1, 1.16, 1.16.1, 20w28a, 20w30a, 1.16.2 Pre-release 1, 1.16.2, 1.16.3

Retrieved