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

ArmorStand placing does not work when any entitiy is in the way

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Works As Intended
    • Affects Version/s: Minecraft 15w38b, Minecraft 15w44b, Minecraft 15w45a, Minecraft 15w46a, Minecraft 1.9.1 Pre-Release 3, Minecraft 16w36a
    • Fix Version/s: None
    • Confirmation Status:
      Confirmed

      Description

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                searge [Mojang] Searge (Michael Stoyke)
                Reporter:
                marcono1234 [Mod] Marcono1234
              • Votes:
                6 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  CHK: