Solved Testing for blocks in vision

Discussion in 'Plugin Development' started by Failplease, Jan 6, 2014.

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

    Failplease

    How would I check to see if a group of blocks are in a player's vision, not just his/her target block?
     
  2. Offline

    Xephiro

    Try with the method getLineOfSight from LivingEntity. Player is one of them.
     
  3. Offline

    Jogy34

    Here's a method I use in one of my plugins to check if a player can see a block
    Code:java
    1.  
    2. public boolean canSee(Player player, Location loc2)
    3. {
    4. Location loc1 = player.getEyeLocation();
    5. Location locat = loc2.clone();
    6. Vector toBlock = locat.subtract(loc1).toVector().normalize();
    7. Vector playerLook = loc1.getDirection().normalize();
    8. float angle = toBlock.angle(playerLook);
    9.  
    10. return (angle < 1.0F) && //Checks if the block can be in the players FOV
    11. (((CraftWorld) loc1.getWorld()).getHandle().a(Vec3D.a(loc1.getX(), loc1.getY() +
    12. player.getEyeHeight(), loc1.getZ()), Vec3D.a(loc2.getX(), loc2.getY(), loc2.getZ())) == null);
    13. //Checks if there are no blocks between the player and the block. Doesn't take into account transparent blocks
    14. }
    15.  
     
Thread Status:
Not open for further replies.

Share This Page