Hi, Im trying to get the block a player is looking at for my plugin, and i've googled and tried a few methods but still cant get it to work. attempt 1 Code (Text): Player player = (Player) sender; Block lookingatblock = player.getTargetBlock((Set<Material>) null, 15); I tried this, but eclipse gives me the error Code (Text): The method getTargetBlock(HashSet<Byte>, int) in the type LivingEntity is not applicable for the arguments (Set<Material>, int) So then I tried this attempt 2 Code (Text): HashSet<Material> transparent = new HashSet<Material>(); transparent.add(Material.AIR); Player player = (Player) sender; Block lookingatblock = player.getTargetBlock(transparent, 15); and eclipse gives me this error Code (Text): The method getTargetBlock(HashSet<Byte>, int) in the type LivingEntity is not applicable for the arguments (HashSet<Material>, int) So im not sure what to do now
You need a hashset with bytes instead. Code (Text): HashSet<Byte> transparent = new HashSet<Byte>(); transparent.add(Material.AIR.getId()); EDIT Your first attempt was better, use that one instead. But same there, you need a Byte, not a Material.
It's deprecated because item IDs can change at all time. However it's impossible for an empty byte hashset to change the values If you can get the one with the material working, sure. If not, it's not a problem to use the byte instead.
I tried using your code, but eclipse now gives me this error Code (Text): The method getId() is undefined for the type Material Tried and it still gives me the same error Code (Text): The method getTargetBlock(HashSet<Byte>, int) in the type LivingEntity is not applicable for the arguments (Set<Material>, int)
I'm sorry about the ambiguity. I'll get around to making another PR to remove the deprecated Byte methods soon. Only reason I left it in before was so it didnt break all plugins that used the deprecated Byte methods. Its been over a year now, so should be safe for me to remove them ^_^ Just be sure you're using the Material methods so your plugin doesnt break when I make this change.
The following works just fine: Code (Java): Player player = (Player)sender; Block targetBlock = player.getTargetBlock((HashSet<Material>)null, 15); Make sure you've imported HashSet and Material.
Try using this: Code (Text): player.getTargetBlock((HashSet<Byte>)null, {your max distance}).getLocation();