Solved problems while adding values to locations

Discussion in 'Spigot Plugin Development' started by Timmae, Apr 27, 2017.

  1. Hey guys,

    while testing around with a structure testing system I covered... a little bug? (probably I'm simply bad :confused:)

    Starting from the middle of the structure I try to test for every block around it using loc.add(x,y,z). I Never really used locations in-depth before, so I got a little bit in trouble caused by that: (its a little bit hard to explain, so I just wrote it in code here)

    Code (Text):
    Location loc = new Location(world, 100, 100, 100);
    //loc xyz is now 100,101,100
    Nevertheless, that's not my point. I don't really understand the following:

    Code (Text):
    // loc xyz is again 100,100,100
    public void testCode(Location loc){

            Location loc2 = loc;
             // loc2 xyz is now like expected 100,101,100
             // but loc xyz is also now 100,101,100
    Even another location variable couldn't fix this (dunno why I tried)

    Any help would be really appreciated. (like I said on the top, the problem is probably my badness ;))
  2. You're just creating another variable with the exact same content as loc, modifying it will ofcourse modify loc too.

    Location#clone() should do the trick ;)
  3. That's because you set it to be the same location.

    Instead do Location loc2 = new Location(values of loc1 here);
  4. 1. Was a bit misstake by the way it works w/e

    2. Tried that but didnt worked out for me bovre probably did some misstake w/e again

    Could have found that.. like I said my dump brain...;)

    Thank you both! :)
    • Like Like x 1