Coordinates Should Take Into Account The Spawn Point
opticyclic opened this issue · 6 comments
According to this #12 (comment) the getPos and setPos are wrong because the spawn point is set to (0,0,0) on the Pi edition.
However, it is unlikely and often inconvenient to set the spawn point to that on a Bukkit server.
All coordinate based operations should get the value of the spawn point first so that correct positions are calculated and returned.
It's been on the to-do list for a while to add a config option so you can choose whether co-ords are relative or absolute. It's not an fault though, it works this way by design.
Yeah, this is more of a feature request.
Can you point me towards where and how to make the change so I can create a pull request.
I can't see the code mentioned in the linked comment.
It should be a config option in config.yml and the change will be to the parseRelative*Location() methods in remotesession.
As I am debugging this, I don't understand the logic.
If the Raspberry Pi sets the spawn point to (0,0,0), what is the point of subtracting the spawn point here?
XYZ of the spawn point are zero on the Raspberry PI so adding/subtracting zero to the coordinates does nothing and the relative location is the same as the actual location.
XYZ of the spawn point are non-zero on Bukkit so adding/subtracting the value means the relative and actual coordinates are not the same.
If you remove the addition/subtraction then relative is still the same as actual for the Raspberry Pi but now relative and actual are the same for Bukkit. This means there is no need for a config option.
What if we change the implementation so that mc.player.getPos()
returns the actual position and add an extra API mc.player.getRelativePos()
that returns the relative position (I'm not sure what you would want it for though).
In this way, mc.player.getPos()
is unchanged for Raspberry Pi but fixed for Bukkit.
mc.player.getRelativePos()
would be identical to mc.player.getPos()
for the Raspberry Pi (due to subtracting 0 having no effect) but properly relative for Bukkit as the spawn point is non-zero.
origin is the spawn location of the minecraft server. By subtracting the origin you get a position which is relative to the spawn location e.g. if spawn was 100, 60, 100 - 10 blocks north from spawn would have a location 10,0,0, where as the absolute position would be be 110, 60, 100.
I wont change the API to have absolute position as we put at risk all the users who rely on spawn being 0,0,0 and mean that you cannot move projects between the raspberry pi and raspberry juice.
e.g. lots of education users use code which says mc.player.setPos(0,50,0) as its simple for beginners to get their head around, when the position changes from server to server this becomes more difficult.
Relative positioning for beginners regardless of where you are makes sense now.
Do you still want a config option or would you rather have a new API to make it abundantly clear and not have any chance of breaking existing scripts?
e.g. player.getPos
stays as is and a new one called player.getAbsolutePos
is added
I suppose the downside of a new API is that it becomes a superset and scripts that use it can only work with RaspberryJuice and not with the Pi directly.