How do I see where player right clicked?

Discussion in 'Plugin Development' started by Plazmotech, May 24, 2012.

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

    Plazmotech

    Here, I have this code:
    Code:
        public void onPlayerInteract(PlayerInteractEvent event) {
            final Action action = event.getAction();
           
            if (action == Action.LEFT_CLICK_BLOCK) {
               
            } else if (action == Action.RIGHT_CLICK_BLOCK) {
               
            }
        }
    How do I know where this player right clicked/left clicked??
     
  2. Offline

    Plazmotech

  3. I was going to answer when I found it :) But that's no reason to be spamming.
     
  4. Offline

    Plazmotech

    I cant seem to use getClickedBlock()
    Location l1 = Action.getClickedBlock()?

    Ik, I needed it quite urgently though :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  5. It's an event method, event.getClickedBlock() and the returned type is Block which also has getLocation() if you need that.

    There's also the search option if you need it *urgently* :}
     
  6. Offline

    Plazmotech

    so Block b1 = event.getClickedBlock()
    and Location l1 = b1.getLocation()
    ??

    Dude, since your still here, I need to for loop and change all the blocks in between l1, and l2, which are defined as so:
    Code:
    Location l1 = b1.getLocation();
    Location l2 = b2.getLocation();
    How would I retrieve the X of l2, etc. and how would I for loop to get every block in that area? Thanks!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  7. Plazmotech
    If you won't use the block for something else, you can just do:
    Location l1 = event.getClickedBlock().getLocation();

    You really should learn to use the Ctrl+Space feature in Eclipse (that is, if you're using Eclipse)... it's l1.getBlockX() (or if you want a double value, just use getX() but it's pointless for blocks, it's useful for entities which can be anywhere on a block)
    Also, Y is the up-down axis in Minecraft, not Z :/
     
  8. Offline

    Plazmotech

    I know, lol. And the ctrl + space didn't display so many features! Thanks tho!
     
Thread Status:
Not open for further replies.

Share This Page