Mojira Archive
MC-88096

When using spawn eggs on fences the mobs fall through

I recently saw that there is a part of code intended to make spawn eggs work on fences so that the mob stands on top of the fence.
It looks like that:

ItemSpawnEgg.java (ItemMonsterPlacer.java in MCP)
	...
	public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
		...
		IBlockState var9 = worldIn.getBlockState(pos);
		...
		// It's supposed to check if the block it was placed one is a fence. How ever it's checking the BlockState, not the block.
		// What was meant to be done is var9.getBlock() instead of just var9.
		if(side == EnumFacing.UP && var9 instanceof BlockFence) {
			// Offset for the spawn
			var13 = 0.5D;
		}
		...
	}
	...

Better fix

As seen in the code snippet there is just a .getBlock() missing.

However when fixing this you could also make the offset (here var13) depended on the collision box of the block.
Then it would work for fence gates, cobble walls and also for slabs and so on too.

Video: https://youtu.be/ZkI3uU7hoBA?t=1m09s

This post might be seen as related: MC-65951