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

Trial spawners never try to spawn mobs in peaceful difficulty

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 24w44a, 1.21.3, 24w45a, 1.21.4 Pre-Release 1
    • Community Consensus
    • Mob spawning

      When the difficulty is set to peaceful, trial spawners will never try to spawn mobs and will get stuck in the waiting_for_players state. This occurs even with passive mobs such as a pig, which is inconsistent with regular monster spawners.

      There was a similar bug report about this MC-266556, however this wasn't properly fixed as now the trial spawner gets stuck in the waiting_for_players state and won't actually try to spawn mobs, instead of staying inactive

      Steps to reproduce:

      1. Set the difficulty to peaceful
      2. Place a trial spawner in a grassy area
      3. Right-click on the trial spawner with a pig spawn egg
      4. Go into survival mode
      5. Look at the trial spawner with the F3 screen enabled
      6. Notice how the trial_spawner_state never changes from waiting_for_players

      Expected result:

      The trial spawner should go into the active state and spawn mobs which are passive.

      Code analysis:

      In net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerState#tickAndGetNext, when the state is WAITING_FOR_PLAYERS the TrialSpawner#canSpawnInLevel method is called.

       

      case 1 -> {
              if (!trialSpawner.canSpawnInLevel(serverLevel)) {
                  trialSpawnerData.resetStatistics();
                  yield this;
              }
              if (!trialSpawnerData.hasMobToSpawn(trialSpawner, serverLevel.random)) {
                  yield INACTIVE;
              }
              trialSpawnerData.tryDetectPlayers(serverLevel, blockPos, trialSpawner);
              if (trialSpawnerData.detectedPlayers.isEmpty()) {
                  yield this;
              }
              yield ACTIVE;
          }

      The canSpawnInLevel method in net.minecraft.world.level.block.entity.trialspawner.TrialSpawner always returns false on peaceful difficulty and doesn't check if the mob is passive, resulting in the spawner never trying to spawn passive mobs

      public boolean canSpawnInLevel(ServerLevel serverLevel) {
          if (this.overridePeacefulAndMobSpawnRule) {
              return true;
          }
          if (serverLevel.getDifficulty() == Difficulty.PEACEFUL) {
              return false;
          }
          return serverLevel.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING);
      } 

       

            Unassigned Unassigned
            Enchanted_Games ioblackshaw
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              CHK: