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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 15w38b, Minecraft 15w44b, Minecraft 15w45a, Minecraft 15w46a, Minecraft 1.9.1 Pre-Release 3, Minecraft 16w36a, Minecraft 1.12.2, Minecraft 1.13-pre8, Minecraft 1.13, Minecraft 1.13.1-pre1, Minecraft 1.13.1, Minecraft 1.13.2, Minecraft 19w03b, Minecraft 19w03c, 1.16.3 Release Candidate 1, 1.16.3, 20w46a, 21w03a, 22w44a, 1.19.4, 1.20 Pre-release 7, 1.20.1, 1.20.4, 24w04a, 24w20a, 1.21.1
    • Confirmed
    • Collision
    • Normal
    • Platform

      The bug

      The problem is that you cannot place armor stands if any entitiy is at this position. This means that this affects items, XPOrbs as well as AreaAffectClouds (particle clouds from lingering potions) and other entities where this restricition makes no sense.
      This is different to normal block placing which works if there are certain entities in the way, for example items.

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

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

              Created:
              Updated:
              CHK: