Mojira Archive
MC-97685

Spawner ignoring provided Rotation tag

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();
            }
        }
    }
}