Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-190669

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Won't Fix
    • Affects Version/s: 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
    • Fix Version/s: None
    • Confirmation Status:
      Community Consensus
    • Category:
      Performance

      Description

      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.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            viktorvn40 Viktor40
            Votes:
            29 Vote for this issue
            Watchers:
            18 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              CHK: