Check if a block is near blocks...?

Discussion in 'Plugin Development' started by maxxb123, Jan 17, 2015.

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

    maxxb123

    Hi, so I have a problem.

    I need to check if the block TnT is near four iron blocks, and then do something if it is. I have no idea at all, but I'm almost certain someone here would. This is what I mean, in a picture.

    [​IMG]

    Any help would be amazing, thanks!
     
  2. Offline

    Skionz

    @maxxb123 Use World#getBlockAt with coordinates relative to the tnt.
     
  3. Offline

    Codex Arcanum

    If you know that the TNT block will be placed last - or you only need to check when the TNT is lighted, then this is trivial. If you don't know either of those things, it's slightly more annoying, but still quite doable.
     
  4. Offline

    ReadySetPawn

    Code:
    if (tnt.getRelative(BlockFace.SOUTH).getType() == Material.IRON_BLOCK &&
    tnt.getRelative(BlockFace.EAST).getType() == Material.IRON_BLOCK &&  tnt.getRelative(BlockFace.NORTH).getType() == Material.IRON_BLOCK &&
    tnt.getRelative(BlockFace.WEST).getType() == Material.IRON_BLOCK){
    //do stuff
    }
     
Thread Status:
Not open for further replies.

Share This Page