mojira.dev
MC-89178

Armor stands and end crystals cannot be placed when any entity occupies the desired location of placement

The bug

You cannot place an armor stand or end crystal if the space is occupied by any entity, including collisionless entities such as items, markers, experience orbs, area effect clouds, and display entities.
This is inconsistent with normal block placing, which succeeds if one of the aforementioned entities is occupying the space.

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.item.ItemArmorStand.onItemUse(ItemStack, EntityPlayer, World, BlockPos, EnumHand, EnumFacing, float, float, float) tests if any entity is at the position where the armor stand should be placed (method net.minecraft.world.World.getEntitiesWithinAABBExcludingEntity(Entity, AxisAlignedBB)). Instead it should probably use the same method that is used when the player wants to place a block: The method net.minecraft.world.World.checkNoEntityCollision(AxisAlignedBB, Entity) which tests if the entities which are in this bounding box prevent block placing.

/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand side, EnumFacing hitX, float hitY, float hitZ, float p_180614_9_)
{
    if (hitX == EnumFacing.DOWN)
    {
        return EnumActionResult.FAIL;
    }
    else
    {
        boolean flag = worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos);
        BlockPos blockpos = flag ? pos : pos.offset(hitX);

        if (!playerIn.canPlayerEdit(blockpos, hitX, stack))
        {
            return EnumActionResult.FAIL;
        }
        else
        {
            BlockPos blockpos1 = blockpos.up();
            boolean flag1 = !worldIn.isAirBlock(blockpos) && !worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
            flag1 = flag1 | (!worldIn.isAirBlock(blockpos1) && !worldIn.getBlockState(blockpos1).getBlock().isReplaceable(worldIn, blockpos1));

            if (flag1)
            {
                return EnumActionResult.FAIL;
            }
            else
            {
                double d0 = (double)blockpos.getX();
                double d1 = (double)blockpos.getY();
                double d2 = (double)blockpos.getZ();

                // Changed bounding box test and re-arranged if statement
                //List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity((Entity)null, new AxisAlignedBB(d0, d1, d2, d0 + 1.0D, d1 + 2.0D, d2 + 1.0D));
                //
                //if (!list.isEmpty())
                //{
                //    return EnumActionResult.FAIL;
                //}
                //else
                //{
                //    if (!worldIn.isRemote)
                //    {
                //        worldIn.setBlockToAir(blockpos);
                //        worldIn.setBlockToAir(blockpos1);
                //        EntityArmorStand entityarmorstand = new EntityArmorStand(worldIn, d0 + 0.5D, d1, d2 + 0.5D);
                //        float f = (float)MathHelper.floor_float((MathHelper.wrapAngleTo180_float(playerIn.rotationYaw - 180.0F) + 22.5F) / 45.0F) * 45.0F;
                //        entityarmorstand.setLocationAndAngles(d0 + 0.5D, d1, d2 + 0.5D, f, 0.0F);
                //        this.applyRandomRotations(entityarmorstand, worldIn.rand);
                //        ItemMonsterPlacer.func_185079_a(worldIn, playerIn, stack, entityarmorstand);
                //        worldIn.spawnEntityInWorld(entityarmorstand);
                //        worldIn.func_184148_a((EntityPlayer)null, entityarmorstand.posX, entityarmorstand.posY, entityarmorstand.posZ, SoundEvents.entity_armorstand_place, SoundCategory.BLOCKS, 0.75F, 0.8F);
                //    }
                //
                //    --stack.stackSize;
                //    return EnumActionResult.SUCCESS;
                //}    
                if (worldIn.checkNoEntityCollision(new AxisAlignedBB(d0, d1, d2, d0 + 1.0D, d1 + 2.0D, d2 + 1.0D), null))
                {
                    if (!worldIn.isRemote)
                    {
                        worldIn.setBlockToAir(blockpos);
                        worldIn.setBlockToAir(blockpos1);
                        EntityArmorStand entityarmorstand = new EntityArmorStand(worldIn, d0 + 0.5D, d1, d2 + 0.5D);
                        float f = (float)MathHelper.floor_float((MathHelper.wrapAngleTo180_float(playerIn.rotationYaw - 180.0F) + 22.5F) / 45.0F) * 45.0F;
                        entityarmorstand.setLocationAndAngles(d0 + 0.5D, d1, d2 + 0.5D, f, 0.0F);
                        this.applyRandomRotations(entityarmorstand, worldIn.rand);
                        ItemMonsterPlacer.func_185079_a(worldIn, playerIn, stack, entityarmorstand);
                        worldIn.spawnEntityInWorld(entityarmorstand);
                        worldIn.func_184148_a((EntityPlayer)null, entityarmorstand.posX, entityarmorstand.posY, entityarmorstand.posZ, SoundEvents.entity_armorstand_place, SoundCategory.BLOCKS, 0.75F, 0.8F);
                    }

                    --stack.stackSize;
                    return EnumActionResult.SUCCESS;
                }
                else {
                    return EnumActionResult.FAIL;
                }
            }
        }
    }
}

Linked issues

MC-296328 end crystal can't be placed if a marker is present Resolved MC-276048 Armor Stands cannot be placed on items Resolved MC-268084 Place the armor stand within a marker does use the item on the client Resolved MC-268083 Display entities can prevent armor stand from being placed Resolved MC-267290 Markers and display entities obstruct placement of armor stands and end crystals Resolved

Comments 4

Can confirm in 24w20a.

Can confirm in 1.21.4

marcono1234

(Unassigned)

Confirmed

Platform

Normal

Collision

armor_stand, entity, placing

Minecraft 15w38b, Minecraft 15w44b, Minecraft 15w45a, Minecraft 15w46a, Minecraft 1.9.1 Pre-Release 3, ..., 1.20.4, 24w04a, 24w20a, 1.21.1, 1.21.4

Retrieved