Really confused about vectors

Discussion in 'Spigot Plugin Development' started by Igasi, May 16, 2017.

  1. So yeah I just got into vectors, read the javadocs, read a document, and watched a youtube video, and am still reallllllly confused.

    So I want to get all the entities in this block with the player standing here:
    [​IMG]

    With the player facing the 3 blocks, of course.

    What I've got so far:
    Code (Text):

    {
    @Override
    public void onEnable(){
        Bukkit.getPluginManager().registerEvents(this, this);
        }
    @EventHandler
    public void onPlayerRightClick(PlayerInteractEvent e){
        if(e.getAction().equals(Action.RIGHT_CLICK_AIR)){
            if(e.getItem().equals(Material.IRON_SWORD)){
                Vector my = ((Location) e.getPlayer()).getDirection();
                }          
            }      
        }
    }
     
    All I want is a list with all the entities in said area

    But then all I really need is to figure out how to select the 3 blocks in front of the player.
     

    Attached Files:

  2. Most stuff is done with a radius, like, the 1 radius, meaning 1 block around the player basically, making it the center of a 3x3 area. So entities not where you are 'looking' but on the left, right, front, back loaded active chunks?
     
  3. What if the player is not at a 90-degree angle? Should it get a diagonal set of blocks, or other odd shapes?

    If not, then this is easier and you don't need vectors (figure out if player facing N, S, E or W, get block in front of player and blocks to the N/S/E/W accordingly, can all be done with Block methods and no Vectors)

    Otherwise it's a little trickier, you'd need to generate two vectors at right angles to the player's facing direction, for the player's left and right, then get the block in front of the player, then use those two vectors to get the blocks next to that block in the right direction. This will get you some odd shapes, though, depending on the direction the player is facing (if I was more creative and less lazy I'd make an animation to show you what I mean...)
     
  4. Alright thanks! Never actually heard of this.... I'll test it out.

    Yeah one problem I have is if the player is facing down. Also, there is nnw, or nne, etc. Very confusing and I would rather use vectors where it is less confusing and more efficient
     
    #5 Igasi, May 16, 2017
    Last edited: May 16, 2017
  5. What I was thinking is the direction the player is looking, which is why I'm looking towards vectors. If I can't though, then I'll change it to BlockFace enums.