Getting blocks in player's direction?

Discussion in 'Plugin Development' started by Rezeh, Aug 8, 2014.

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

    Rezeh

    How would I get the first 5 blocks in the direction the player is looking at?
     
  2. Rezeh
    just use p.getLineOfSight()
     
  3. You can use the Iterator. Little simplified code:
    Code:java
    1. public final Block getTarget(Player player, Integer range) {
    2. BlockIterator iter = new BlockIterator(player, range);
    3. Block lastBlock = iter.next();
    4. while (iter.hasNext()) {
    5. lastBlock = iter.next();
    6. if (lastBlock.getType() == Material.AIR)
    7. continue;
    8. break;
    9. }
    10. return lastBlock;
    11. }

    Just do getTarget(player, 5)
     
  4. Offline

    Skionz

    Couldn't you just use this?
    Code:
            for(Block block : player.getLineOfSight(null, 5)) {
                block.setType(Material.DIAMOND_BLOCK);
            }
     
Thread Status:
Not open for further replies.

Share This Page