Getting a block above clicked block

Discussion in 'Plugin Development' started by TechManDylan, Dec 26, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    TechManDylan

    So as the title says I'm drawing a complete blank this is my code so far how do I get the block above the block I'm clicking.
    Code:
        @EventHandler(priority = EventPriority.NORMAL)
        public void growLily(PlayerInteractEvent event) {
            Player p = event.getPlayer();
            ItemStack iih = p.getItemInHand();
            Block block = event.getClickedBlock();
            if (iih.getTypeId() == 351) {
                if (iih.getDurability() == 15) {
                    if (p.hasPermission("FrillyLilys.Grow")) {
                        if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                            if(block.getTypeId() == 8){
                                //Need to get block above and set to Lily pad   
                            }
                        }
                    }
                }
            }
        }
    }
     
  2. Offline

    Unknowncmbk

    I remember seeing a tutorial about this! You ahave to get the position of you and the blockinteractevent and add 1 to the y coordinate I believe!

    What really helps is decompiling WorldEdit as they do a wonderful job of this specific example!
     
  3. Offline

    fireblast709

    block.getRelative(BlockFace.UP, 1);
    block.getLocation().add(0,1,0).getBlock();
     
    legostarwarszach likes this.
  4. Offline

    drampelt

    You can use block.getRelative(BlockFace.UP); to get the block above it. This can also be used to get the block on any side of a block.

    Edit: Aww, fireblast709 beat me to it :p
     
    legostarwarszach likes this.
Thread Status:
Not open for further replies.

Share This Page