Solved event.getBlock() and player.getTargetBlock returning different locations

Discussion in 'Plugin Development' started by Blackwing_Forged, Aug 18, 2018.

Thread Status:
Not open for further replies.
  1. Title says it all, i don't know why they are returning different locations
    Code:
    Block b = e.getBlock();
    Location firstLoc = new Location(p.getWorld(), b.getLocation().getBlockX(), b.getLocation().getBlockY(), b.getLocation().getBlockZ());
    Block bl = p.getTargetBlock((Set<Material>)null, 1);
    Location secondLoc = new Location(p.getWorld(), bl.getLocation().getBlockX(), bl.getLocation().getBlockY(), bl.getLocation().getBlockZ());
    p.sendMessage(firstLoc.toString());
    p.sendMessage(secondLoc.toString());
    whenever i move around but click on the same block both locations return different values and they keep changing when i move
     
    Last edited: Aug 18, 2018
  2. Online

    timtower Administrator Administrator Moderator

    @Blackwing_Forged
    1. How far are they apart?
    2. What type of blocks do you hit?
    3. Did you try it with a solid wall without blocks between you and the wall?
    4. Which event are we talking about?
     
  3. @timtower
    Im using PlayerInteractEvent, the type doesn't matter, any block i hit the location changes and the only location that keeps changing now is the player.getTargetBlock
     
  4. Online

    timtower Administrator Administrator Moderator

    @Blackwing_Forged Type can tell things, tall grass isn't always being checked for instance.
    What are you hitting?
     
  5. @timtower
    Obsidian and ive also hit dirt
     
  6. Online

    timtower Administrator Administrator Moderator

  7. Online

    timtower Administrator Administrator Moderator

  8. @timtower
    Its getting the water block and not the block im actually looking at, how would i fix that?
     
  9. Online

    timtower Administrator Administrator Moderator

    @Blackwing_Forged transparent - HashSet containing all transparent block IDs (set to null for only air)
    Add it to the list
     
  10. @timtower
    Thanks, got it working

    Code:
    HashSet<Material> transparentBlocks = new HashSet<Material>();
    transparentBlocks.add(Material.STATIONARY_WATER);
    transparentBlocks.add(null);
    Block bl = p.getTargetBlock(transparentBlocks, 5);
     
Thread Status:
Not open for further replies.

Share This Page