Getting location of block and player

Discussion in 'Plugin Development' started by HamOmlet, Jun 19, 2012.

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

    HamOmlet

    So I seem to be having some trouble getting the location of both a player and a block. What I'm trying to do is spawn a block directly at the players location and have the block removed a few seconds later. To do this, I have to save the player's location. Now, the problem is that this block is "special" from other blocks that are similar to it, so I have to somehow differentiate between those blocks and the "special" block. I decided to use a PlayerInteractEvent and compare the saved location of the player with the location of the clicked block. For some reason, the X and Y values match up, but the Z is always different.

    Is there something else I can do? Could I perhaps just use the X and Y values?
     
  2. Offline

    xtreampb

    you must use the z because x is left/right, y is up/down, but your z is your forward/back.

    how about a few different vars.

    Location pLoc=player.getLocation();
    block mBlock=pLoc.getBlock();//this block data type stores the location within itself
    //from here you can now manipulate the block
    mBlock.setTypeID(2);//sets the block to dirt with grass top

    now this is the block at the players location, you can do some math to figure out if you want the block to be one in front of the player, above below etc using something like

    Location bLoc=pLoc;
    bLoc.setX(bLoc.getX() +1);//sets the location to one block more on the x axis
    Block mBlock=bLoc.getBlock();//you could also use the .getState() if the block is a sign or furnace. once you
    //capture the state, it may change and you not know about said change keep that in mind
     
Thread Status:
Not open for further replies.

Share This Page