Solved Find block above the event block in BlockBreakEvent

Discussion in 'Plugin Development' started by KittyKatt, Apr 12, 2013.

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

    KittyKatt

    Hello,

    I'm trying to make lamp plugin, if you destroy a block in BlockBreakEvent and there is a glowstone 5 blocks over that block, it should change to something else.

    Guess I have to do something with event.getBlock().getLocation() ? Not sure how I would check 5 blocks over and if its a glowstone. Help please? =)))
     
  2. event.getBlock() returns a Block object.

    Block has a getRelative(BlockFace face) that returns a Block.

    Thus, event.getBlock().getRelative(BlockFace.UP) will give you the block one block above that.

    There is also getRelative(BlockFace face,int x) that gets the block x away in the blockface's direction.

    http://jd.bukkit.org/rb/apidocs/org/bukkit/block/Block.html
    Information on the Block object, such as methods that let you get the type of block and such.
     
  3. Offline

    mcoder

    One way to do this would be

    Code:java
    1.  
    2. Block brokenBlock = event.getBlock()
    3. Block lampBlock = brokenBlock.getWorld().getBlockAt(brokenBlock.getX(), brokenBlock.getY + 5, brokenBlock.getZ());
    4. if (lampBlock != null && lampBlock.getType() == Material.GLOWSTONE) {
    5. //your codde
    6. }
    7.  


    regards, mcoder
     
    KittyKatt likes this.
  4. Offline

    KittyKatt

    Code:
            Material lamp = event.getBlock().getWorld().getBlockAt(event.getBlock().getLocation().add(0,5,0)).getType();
            if(lamp == Material.GLOWSTONE)
            {
                Bukkit.broadcastMessage("GLOWSTONE FOUND!");
            }
     
Thread Status:
Not open for further replies.

Share This Page