TravelPortals

TravelPortals

70.9k Downloads

Teleport entities, just like the Netherportal

Flying--Dutchman opened this issue ยท 3 comments

commented

Thinking of implementing the possiblity to teleport entities (everything) and not just the player.
This would give the portal way more use cases, just like netherportals.
I'm a bit worried about the extra cpu costs...

Any opinions?

If this would be implemented, then definitly with a config option to activate it (default = off).

commented

Main issue with entities would be that there is no entity move event so the plugin would need to always loop through all entities or portals in order to do that.

Another issue (performance-wise) could be that the target chunks would need to get loaded by the plugin so that the entity can be teleported there. (Granted with Paper's async chunk loading its not that bad but that's not possible on Spigot)

commented

So, in a, or multiple Runnables, I would do:

  • find all portals in currently loaded chunks
  • check with getNearbyEntities (in 2x1 frame) for Entities
  • load destination chunk (if not loaded)
  • teleport entity

Whereas chunkloading would be the most time consuming part...

So lets say,

  • check every 20-30 ticks the portals (configurable), ca 1 to 1.5 seconds
  • store all portals in a concurrent queue and let a new thread check the Entities
  • same game, store entities in a concurrent queue and let a new thread load the chunks and teleport the entities
  • in order to minimize possible lags, stretch the chunkloading over multiple game ticks.

Maybe listen on chunkloading and unloading and keep a record of active chunks with portals to minimize lookup time. Also we would allready know which destination portals are in loaded chunks, and could immediately teleport those entities.

Also, if possible, maybe "hide" entities who are waiting for chunkloading so the player wouldnt notice it, if it takes a bit longer to teleport those.

... Now I really feel the urge to implement this... If I'll find some time, I will begin working on this.

Thank you very much for your insight. ๐Ÿ‘

commented

Some stuff to keep in mind would be that checking the nearby entities on all loaded portals might have a large performance impact if you have a large amount of portals. Maybe it might be possible to spread the search over multiple ticks instead of doing it all at once.

I don't think it's necessary to keep track of loaded portals though (as one would have to keep a chunk -> portal map for that, otherwise all portals would need to be searched on each chunk load/unload). I think simply checking if a chunk is loaded when checking the portal's location should be good enough performance-wise. Also I think that teleporting into unloaded chunks should definitely be an option seeing as that might cause performance issues if done too often. If disabled entities could just stay in portals until the target chunk is loaded.

Another thing that needs to be considered is how it is prevented that entities just bounce between two portals because they never wander out of them. Maybe it would be possible to teleport them in front of the portal and give them some cooldown via Bukkit's metadata.