GetLocation, SetLocation

Discussion in 'Plugin Development' started by To175, Nov 28, 2014.

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

    To175

    Hi, anyone can help me please ?
    I can't modify the location :(
    Code:java
    1. Location loc = player.getLocation();//I get player location
    2. Location newX = loc.getX() + 2;//Type mismatch: cannot convert from double to Location
    3. newX.setX(1);


    Thanks
     
  2. Offline

    Skionz

    To175 Location#getX() returns a double.
     
  3. Offline

    To175

    Skionz thanks, Yes I now That's why it doesn't work, I don't know how to convert types !
     
    Skionz likes this.
  4. Offline

    Skionz

    To175 Change 'newX's type to a double.
     
  5. Offline

    Googlelover1234

    To175
    You could do

    Code:java
    1. double x = loc.getX() + 2.0;
     
  6. Offline

    To175

    Skionz Thx, I already tried but I have :
    Googlelover1234 Thanks, but I said
     
  7. Offline

    Googlelover1234

    To175
    So you'd do...

    Code:java
    1. double newX = loc.getX() + 2.0;
    2. Location newLoc = new Location(player.getWorld(), newX, y, z, yaw, pitch);
     
  8. Offline

    teej107

    To175 likes this.
  9. Offline

    To175

    Googlelover1234 Wtf :D
    I can't understand your code sorry :p
    I need to :
    - Get player location
    - Create a new location near to the player (2 blocks here)
    - Set a block in this new location
     
  10. Offline

    Googlelover1234

    ChipDev and To175 like this.
  11. Offline

    Skionz

    Thats exactly what he did. I suggest looking at some basic tutorials on oracles website.
     
  12. Offline

    To175

    teej107 ho ok I didn't see the link sorry, thanks you very much I'll try :)

    I don't undrestand,
    1. double newX = loc.getX() + 2.0;
    2. Location newLoc = new Location(player.getWorld(), newX, y, z, yaw, pitch);
    We have here first loc.getX(), and then he is ... ok I didn't see the newX instead of x

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  13. Offline

    Skionz

  14. Offline

    To175

    Skionz I have not any error in log, but this do nothing...
    Code:java
    1. Location loc = player.getLocation();//I get player location
    2. loc.add(1.0,0.0,1.0);
    3. loc.setX(1);
     
  15. Offline

    Freelix2000

    To175
    I'm guessing that when you use
    Location nexX = loc.getX() + 2;
    you want a new location that adds 2 blocks to the x.
    use loc.add(2, 0, 0)
     
  16. Offline

    To175

    Freelix2000
    I made it worked !
    But how can I use 35:1 for example ?
    Code:java
    1. Location loc = player.getLocation();//I get player location
    2. loc.add(2.0,0.0,0.0);
    3. Block block = loc.getBlock();
    4. block.setTypeId(113);
     
  17. Offline

    teej107

  18. Offline

    To175

    teej107
    Thanks !
    And when I do the command, It set blocks front to the east, how can I make a rotation to the player sight please ?
     
  19. Offline

    Skionz

    To175 Read through the Javadocs.
     
  20. Offline

    To175

    Skionz
    News : with setYaw Can I do it once ?
    For example, does it work like that ?
    Player location's yaw is get then used to modify the x,y,z of location ? in the direction of player ?
    I can't really understand...
    I did this but this is strange, I really don't see how to set the new yaw for setting blocks...
    Code:java
    1. Location loc = player.getLocation();//I get player location
    2. float yaw = loc.getYaw();//direction of player's sight
    3. loc.setYaw(yaw);//rotating all blocks we will set
    4. loc.add(2.0,0.0,0.0);
    5. Block block = loc.getBlock();
    6. block.setTypeId(113);
     
  21. Offline

    Skionz

    To175 Teleport the player
     
  22. Offline

    To175

    Skionz
    So why did you say
    ?
    Teleport has not any sens... I need player do /build for example and then the blocks I have decided previously in the program are built ! But in front of the player and nothing else !
    What do I care to teleport him ? I don't care the player be in front of whatever... I need he does a command to set blocks in front of him, else blocks will destroy the other thing at left or right or behind him even if I teleport him...
     
  23. Offline

    Skionz

    To175 Ah my bad I was tired this morning. Thought you wanted to teleport the player to a new location. To rotate certain block check which direction they are facing. It is all in the javadocs.
     
  24. Offline

    To175

    Skionz Yep I know, but explanation is not in javadocs...
    And I really can't figure it out how does that work :eek:
    If player facing north (yaw=north) then ??? No... I don't know :( I have already set blocks :'(
     
  25. Offline

    Skionz

  26. Offline

    To175

    Skionz thanks but.. so what ??
    Null will be returned :(
    ...
    If the player is not facing a block I have just "null" O.O
    Hum it said "block" not "player"... hum... damn I don't understand what "a block faces a block" mean...

    Skionz thx but you didn't understand, I search a way to create a block in front of the player :)
    So that I need to know where he is staring at...
    But then I don't know how to setX Y Z relative to his sight :eek:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  27. Offline

    MexMaster

    Hey, you could also use player.getTargetBlock(null, 2); this will get the block in front of them with a !maximal! distance of 2. If there's a block earlier it will return that. Maybe that helps you.
     
  28. Offline

    ChipDev

Thread Status:
Not open for further replies.

Share This Page