Sight

Discussion in 'Spigot Plugin Development' started by harveycat1, Jun 1, 2017.

  1. Whats best method for checking the block a player is looking at
     
  2. Some thing like?
    Code (Text):
    Player player = (Player) sender;
    Block block = player.getTargetBlock(null, 100);
    Location bl = block.getLocation();
     
  3. Player#getTargetBlock does the trick
     
  4. Hey, the easiest way is to use the getTargetBlock method in the LivingEntity class.
    Documentation: https://hub.spigotmc.org/javadocs/bukkit/
    I think the method is easy to understand and your problem should be solved :)
     
  5. As you can see in the bukkit documentation, 100 ist the maximum distance to scan for blocks.
     
  6. Code (Text):
    Block block = p.getTargetBlock(null, 100);
    is underlinder red? with "The method getTargetBlock(HashSet<Byte>, int) is ambiguous for the type Player"
     
  7. Gotta cast the null to what the getTargetBlock function wants
     
    • Like Like x 1
  8. which is? sorry never used block methods like dis and just says its ambiguous for type player
     
  9. Mas

    Mas

    Cast null to Set<Material> so the compiler knows which of the getTargetBlock methods you are trying to call.
     
  10. Choco

    Moderator

    The HashSet method was removed in the 1.12 API, so updating tomorrow won't give you this compilation issue