Hitting in the air will always load the chunk at 0,0

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Affects Version/s: None
    • None

      Hey,

      CraftEventFactory will always load the Chunk at 0,0 if a player interacts with air anywhere in the world

          public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, ItemStack itemstack, EnumHand hand) {
              if (action != Action.LEFT_CLICK_AIR && action != Action.RIGHT_CLICK_AIR) {
                  throw new AssertionError(String.format("%s performing %s with %s", who, action, itemstack));
              }
              return callPlayerInteractEvent(who, action, new BlockPosition(0, 256, 0), EnumDirection.SOUTH, itemstack, hand);
          }
      
      
      
          public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand) {
              Player player = (who == null) ? null : (Player) who.getBukkitEntity();
              CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
      
              CraftWorld craftWorld = (CraftWorld) player.getWorld();
              CraftServer craftServer = (CraftServer) player.getServer();
      
              Block blockClicked = craftWorld.getBlockAt(position.getX(), position.getY(), position.getZ());
              BlockFace blockFace = CraftBlock.notchToBlockFace(direction);
      
              if (position.getY() > 255) {
                  blockClicked = null;
                  switch (action) {
                  case LEFT_CLICK_BLOCK:
                      action = Action.LEFT_CLICK_AIR;
                      break;
                  case RIGHT_CLICK_BLOCK:
                      action = Action.RIGHT_CLICK_AIR;
                      break;
                  }
              }
      
      

      Something like this fixes it

      [...]
              CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
              // this fixes massive chunk-requests on interact events with 0,256,0 position
              Block blockClicked = null;
              CraftServer craftServer = (CraftServer) player.getServer();
              if (position.getY() < 256) {
              	CraftWorld craftWorld = (CraftWorld) player.getWorld();
              	blockClicked = craftWorld.getBlockAt(position.getX(), position.getY(), position.getZ());
              }
              BlockFace blockFace = CraftBlock.notchToBlockFace(direction);
              //kade edit end
      		
              if (position.getY() > 255) {
      [...]
      

            Assignee:
            Unassigned
            Reporter:
            Kademlia
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: