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

Linked issues

Attachments

Comments

migrated

I've not tried, but it sounds like specifying rotation did work in 1.8.9? (So this is a regression, not a feature request, right?)

marcono1234

I do not know if it worked in 1.8.9 and in my opinion it does not matter. There is very likely a reason why someone provides the Rotation tag

Irbis

Haven't thought about this one. Would be nice to see this fixed with Pos tag. How about linking this bug to MC-97491 as "relates to"? Both are about spawners and position/rotation of spawned entity.

marcono1234

This one here is rather a general problem that (probably) existed before MC-97491 came up

SunCat

Confirmed for 1.9

migrated

Confirmed for 16w40a

migrated

Confirmed for 1.13.1.

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

Confirmed for 1.15.2. Fixing this nasty bug in upcoming 1.16 would've been pretty nice.

Avoma

Can confirm in 21w05b.

Moesh

This is a feature request.

marcono1234

(Unassigned)

Confirmed

(Unassigned)

NBT, Rotation, spawner

Minecraft 1.9 Pre-Release 2, Minecraft 1.9 Pre-Release 3, Minecraft 1.9, Minecraft 1.9.1, Minecraft 1.9.2, ..., 1.17, 1.17.1 Pre-release 1, 1.17.1, 21w37a, 21w39a

Retrieved