zhuowei/RaspberryJuice

getPos() showing wrong coordinates

Closed this issue · 4 comments

Comparing the XYZ coordinates I get from mc.player.getPos() and the coordinates from the Minecraft client by pressing F3, I seem to be getting different numbers.

From Minecraft: 0, 6, 0
From getPos(): -930, 2, 296

From Minecraft: 50, 6, 0
From getPos(): -880, 2, 296

From Minecraft: 50, 6, 50
From getPos(): -880, 2, -346

From Minecraft: 50, 50, 50
From getPos(): -880, 46, 346

After deleting the world map and regenerating it, I still get a discrepancy but of a different amount:
From Minecraft: 161.5, 67.0, 259.5
From getPos(): 9.5, 3.0, 3.5

These discrepancies persist even after I restart the server. This is using the Python libraries that were originally supplied by Mojang with the Pi (though it also happens with the Python files I pulled from this github repo), on Bukkit build #3092 (1.7.9-R0.2) and Minecraft 1.7.10.

This is usual behavior and by design. Its because the Pi edition of Minecraft sets the spawn location as 0,0,0 so the plugin applies the spawn position to the actual positions to they are relative around a spawn of 0,0,0.

Is there any way to get the actual coordinates? I'm using a coordinates overlay mod to make it easy to know where the player is.

Also, isn't RaspberryJuice and Bukkit meant to be run on PCs, and not the Raspberry Pi?

There is no way to get the actualy coordinates with the current plugin, but I doubt it would be a difficult change.

It is, of course, meant to run on bukkit but it is also meant to be compatible with programs that were created for the raspberry pi version.

If you wanted to fork the plugin and make your own, you would have the change the following functions so it doesnt add / minus the origin to the return location:

public Location parseRelativeBlockLocation(String xstr, String ystr, String zstr) {
    int x = (int) Double.parseDouble(xstr);
    int y = (int) Double.parseDouble(ystr);
    int z = (int) Double.parseDouble(zstr);
    return new Location(origin.getWorld(), origin.getBlockX() + x, origin.getBlockY() + y, origin.getBlockZ() + z);
}

public Location parseRelativeLocation(String xstr, String ystr, String zstr) {
    double x = Double.parseDouble(xstr);
    double y = Double.parseDouble(ystr);
    double z = Double.parseDouble(zstr);
    return new Location(origin.getWorld(), origin.getX() + x, origin.getY() + y, origin.getZ() + z);
}

public String blockLocationToRelative(Location loc) {
    return (loc.getBlockX() - origin.getBlockX()) + "," + (loc.getBlockY() - origin.getBlockY()) + "," +
        (loc.getBlockZ() - origin.getBlockZ());
}

public String locationToRelative(Location loc) {
    return (loc.getX() - origin.getX()) + "," + (loc.getY() - origin.getY()) + "," +
        (loc.getZ() - origin.getZ());
}

If however you fancy creating a function which switches between relative and absolute positions and sending us a push that would be great. Or feel free to request an enhancement and we will put it on the list.

I thought of an alternative to this problem. If you set the spawn point in bukkit to be 0,0,0, then all the co-ordinates will match! Run the command setworldspawn 0 0 0 in Bukkit