Getting player target block

Discussion in 'Plugin Development' started by Kleinerminer, Dec 17, 2014.

Thread Status:
Not open for further replies.
  1. Hello,
    I got a little problem: the method LivingEntity.getTargetBlock() is Deprecated and I cant find a replacement. Which method should I use instead (I want to check if the player`s target block is a chest)
     
  2. Offline

    Skionz

    @Kleinerminer You could create your own method which gets the players line of site, increments an integer, add that integer to the location, repeat until the Block at that locations type != to air.
     
  3. Offline

    extended_clip

    Here is a method to get the target block.

    Code:
        public final Block getTarget(Player player, Integer range) {
            BlockIterator bi= new BlockIterator(player, range);
            Block lastBlock = bi.next();
            while (bi.hasNext()) {
                lastBlock = bi.next();
                if (lastBlock.getType() == Material.AIR)
                    continue;
                break;
            }
            return lastBlock;
        }
     
  4. Thank you :) I will try it soon
     
  5. @Kleinerminer If a method is deprecated, and there's no alternative, just use the deprecated method anyway. The only reason this method has been deprecated is because it uses the id system, anyway.


    @extended_clip Please don't spoon-feed. Also, what you've done is effectively recreated Bukkit's method sans the ability to specify other blocks you don't want to include as a target block. Finally, why Integer over int?
     
  6. @AdamQpzm So why is there no method which simply returns the Block itself instead of the ID?
     
  7. @Kleinerminer It does return the block, the only thing it uses for IDs is the parameter for "transparent blocks".
     
Thread Status:
Not open for further replies.

Share This Page