Solved Setting a target block that isn't air

Discussion in 'Plugin Development' started by bijx, Mar 25, 2016.

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

    bijx

    I'm surprised I didn't find a thread that relates to this problem, though I may not have asked Google the right question. My issue is that I am using a line in my code to find the block a player is looking at and then set it to a beacon. However I cannot find the fix to make it find the non air block that the player was looking at. When I run my command, it just takes the block a few blocks ahead of me because its air. Here's my code:

    Code:
    Block b = player.getTargetBlock((Set<Material>)null, 5);
    Location loc = b.getLocation();
    player.getWorld().getBlockAt(loc).setType(Material.BEACON);
    If you're wondering why I put in the (Set<Material>), its because the .getTargetBlock text would get a strikethrough when I put 'null' alone. Also, I am using spigot 1.9, if that information is useful.
     
  2. Offline

    Zombie_Striker

    This is the max distance of the block you want to get. It only returns air when it could not find any other blocks within the distance of the number provided. If you want to only find blocks, then set this value equal to the Maximum value for an int .
     
  3. Offline

    mcdorli

    If getTargetBlock can't find a solid block, it returns the last blocks it checks, check if it is null, befire you do anything
     
Thread Status:
Not open for further replies.

Share This Page