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

Spawner ignoring provided Rotation tag

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • None
    • Minecraft 1.9 Pre-Release 2, Minecraft 1.9 Pre-Release 3, Minecraft 1.9, Minecraft 1.9.1, Minecraft 1.9.2, Minecraft 1.9.4, Minecraft 1.10 Pre-Release 1, Minecraft 1.10.2, Minecraft 16w32b, Minecraft 16w40a, Minecraft 1.11.2, Minecraft 1.12.2, Minecraft 18w06a, Minecraft 1.13.1, Minecraft 1.13.2, Minecraft 19w05a, Minecraft 19w06a, Minecraft 19w07a, 1.14.4, 19w46b, 1.15.2, 20w12a, 1.16.2, 1.16.3 Release Candidate 1, 1.16.3, 1.16.4 Pre-release 1, 1.16.4 Pre-release 2, 1.16.4, 20w45a, 20w46a, 20w48a, 20w49a, 20w51a, 21w03a, 1.16.5, 21w05a, 21w05b, 21w06a, 21w15a, 21w16a, 21w17a, 21w18a, 21w19a, 21w20a, 1.17 Pre-release 1, 1.17 Pre-release 4, 1.17, 1.17.1 Pre-release 1, 1.17.1, 21w37a, 21w39a
    • Confirmed
    • (Unassigned)

      The bug

      Spawners ignore the Rotation tag of the entity to spawn and instead give them a random rotation.

      How to reproduce

      Use the following command

      /setblock ~ ~1 ~ minecraft:spawner{SpawnData:{entity:{id:"minecraft:armor_stand",Rotation:[180f,0f]}},MinSpawnDelay:10s,MaxSpawnDelay:10s,SpawnCount:1,SpawnRange:5}
      

      You will see that the armor stands spawn with a random rotation

      The reason

      The following is based on decompiled version of Minecraft 1.9 using MCP 9.24 beta. All method and class names are the names used in the decompiled version.

      The reason why this happens is because the method net.minecraft.tileentity.MobSpawnerBaseLogic.updateSpawner() always uses a random yaw value and 0f as pitch value.

      public void updateSpawner()
      {
          if (!this.isActivated())
          {
              this.prevMobRotation = this.mobRotation;
          }
          else
          {
              BlockPos blockpos = this.getSpawnerPosition();
      
              if (this.getSpawnerWorld().isRemote)
              {
                  //...
              }
              else
              {
                  //...
      
                  for (int i = 0; i < this.spawnCount; ++i)
                  {
                      NBTTagCompound nbttagcompound = this.randomEntity.func_185277_b();
                      NBTTagList nbttaglist = nbttagcompound.getTagList("Pos", 6);
                      World world = this.getSpawnerWorld();
                      int j = nbttaglist.tagCount();
                      double d0 = j >= 1 ? nbttaglist.getDoubleAt(0) : (double)blockpos.getX() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double)this.spawnRange + 0.5D;
                      double d1 = j >= 2 ? nbttaglist.getDoubleAt(1) : (double)(blockpos.getY() + world.rand.nextInt(3) - 1);
                      double d2 = j >= 3 ? nbttaglist.getDoubleAt(2) : (double)blockpos.getZ() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double)this.spawnRange + 0.5D;
                      Entity entity = AnvilChunkLoader.func_186054_a(nbttagcompound, world, d0, d1, d2, false);
      
                      if (entity == null)
                      {
                          return;
                      }
      
                      int k = world.getEntitiesWithinAABB(entity.getClass(), (new AxisAlignedBB((double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ(), (double)(blockpos.getX() + 1), (double)(blockpos.getY() + 1), (double)(blockpos.getZ() + 1))).func_186662_g((double)this.spawnRange)).size();
      
                      if (k >= this.maxNearbyEntities)
                      {
                          this.resetTimer();
                          return;
                      }
      
                      EntityLiving entityliving = entity instanceof EntityLiving ? (EntityLiving)entity : null;
                      
                      // Replaced this
                      //entity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, world.rand.nextFloat() * 360.0F, 0.0F);
                      NBTTagList nbtRotation = nbttagcompound.getTagList("Rotation", 5);
                      int nbtRotationTagCount = nbtRotation.tagCount();
                      float yaw = nbtRotationTagCount >= 1 ? nbtRotation.getFloatAt(0) : world.rand.nextFloat() * 360.0F;
                      float pitch = nbtRotationTagCount >= 2 ? nbtRotation.getFloatAt(1) : 0.0F;
                      entity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, yaw, pitch);
      
                      //...
                  }
      
                  if (flag)
                  {
                      this.resetTimer();
                  }
              }
          }
      }
      

            Unassigned Unassigned
            marcono1234 Marcono1234
            Votes:
            11 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: