Current scenario
entity.setLocation(Location) is used to update the location and send the proper SpawnPackets and EntityRemovePackets.
- Location for players is set in the constructor, to prevent
setLocation() to be triggered
- Locations for monsters is set through the constructor,
setLocation() is invoked to immidiately spawn monsters to it's surroundings
entity.spawn() is used to invoke setLocation with the current location provided through the constructor, to spawn players.
Conclusion
This is nasty. It's really confusing and causes entities to spawn too soon or to late, throwing NullPointerExceptions or making the client crash.
Suggested implementation
- Remove
setLocation(), it's ambigious and should be never used.
- Set the initial coordinates for an entity through it's constructor, but don't spawn it yet!
- Use the
walk, jump and teleport (windscroll/portal) methods to spawn and move entities. These methods should remove the moving identity from players that resist only in the old view, send an entity spawn packet to the clients only in the new view, and optionally propagate a walk or jump packet.
- Use the
spawn() (=teleport(CurrentLocation)) method to spawn entities initially and append them to the array of entities within the map (remove it from the old map as well)
Current scenario
entity.setLocation(Location)is used to update the location and send the proper SpawnPackets and EntityRemovePackets.setLocation()to be triggeredsetLocation()is invoked to immidiately spawn monsters to it's surroundingsentity.spawn()is used to invoke setLocation with the current location provided through the constructor, to spawn players.Conclusion
This is nasty. It's really confusing and causes entities to spawn too soon or to late, throwing
NullPointerExceptionsor making the client crash.Suggested implementation
setLocation(), it's ambigious and should be never used.walk,jumpandteleport(windscroll/portal) methods to spawn and move entities. These methods should remove the moving identity from players that resist only in the old view, send an entity spawn packet to the clients only in the new view, and optionally propagate a walk or jump packet.spawn()(=teleport(CurrentLocation)) method to spawn entities initially and append them to the array of entities within the map (remove it from the old map as well)