I've been working on a script for setting the player's location to where they last logged off for single player (like on a multi-player server). I've been able to find things and do stuff, but it has about a 50% success rate.
I've been tracing everything to see if there's an issue in something somewhere, and since last night I was expecting a multi-threading issue, but that's not the case.
I've traced it to here, that finally calls the position setting (this is in case you don't really remember how it was last programmed):
this.client.initialize();
this.client.start();
the
this.client.initialize() calls the original
setLocation to set the position to 512, 512, 80:
setLocation(512.5F, 512.5F, 80.0F);
Then, it will call the
this.client.start(); method, and it will publish the
playerJoined event, nearing the end of the method (and that should be where I come in.
)
After all of that, I made sure things are set up properly and such, and here is a screenshot of an unsuccessful set position:
The debug messages should be clear. THe first line is the current position, which was the one that was manually set; the Last location is the one loaded from the file, and what I tried setting the player's location to.
Now for my code, if you feel it's necessary:
// This here was a test to see if there was a threading issue.
// If this were to be a Vector3f with positions of 0 on all axis,
// it would verify this thought.
Vector3f currentPos = gameClient.getLocation()
if (currentPos == null) currentPos = new Vector3f(0f, 0f, 0f)
console.echo(currentPos.x + ", " + currentPos.y + ", " + currentPos.z)
Vector3f pos = Manager.location // gets the Last Location.
if (pos != null) {
console.echo("setting position")
console.echo(pos.x + "," + pos.y + "," + pos.z)
// Position set.
gameClient.setLocation(pos.x, pos.y, pos.z)
}