Get nerby blocks.

Discussion in 'Plugin Development' started by krists23, Sep 28, 2013.

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

    krists23

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event){
    3. {
    4. Player player = event.getPlayer();
    5. int blockId = player.getItemInHand().getType().getId();
    6. if (blockId == 369){
    7. Location loc = player.getTargetBlock(null, 50).getLocation();
    8. Material mat = loc.getBlock().getType();
    9. FallingBlock block = event.getPlayer().getWorld().spawnFallingBlock(loc,mat, loc.getBlock().getData());
    10. block.setVelocity(new Vector(0, 3,0 ));
    11. loc.getBlock().setType(Material.AIR);
    12. }
    13.  
    14. }
    15. }
    16. }
    17.  


    That is my code that when right clicks block shoots it up. I want get nearby blocks, where clicked and shoot up them.
     
  2. Offline

    sharp237

    How 'nearby' are these blocks?
     
    MrSnare likes this.
  3. Offline

    Fluxanoia

    HashMap<Integer, BlockFace> BF = new HashMap<Integer, BlockFace>();
    BF.put(1, BlockFace.DOWN);
    BF.put(2, BlockFace.UP);
    BF.put(3, BlockFace.SOUTH);
    BF.put(4, BlockFace.NORTH);
    BF.put(5, BlockFace.EAST);
    BF.put(6, BlockFace.WEST);
    for (int ee = 1; ee <= 6; ee++) {
    if (event.getBlock().getRelative(BF.get(ee))) {
    //Falling block code
    }

    This only works for blocks directly adjacent to the block you click give a plus effect.
     
  4. Offline

    krists23

    sharp237 4x4 blocks or 3x3 blocks

    Fluxanoia Thanks ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page