potatolain / TravelPortals

A portal system for Bukkit for Minecraft
BSD 2-Clause "Simplified" License
3 stars 2 forks source link

Teleport entities, just like the Netherportal #32

Open Flying--Dutchman opened 4 years ago

Flying--Dutchman commented 4 years ago

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).

Phoenix616 commented 4 years ago

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)

Flying--Dutchman commented 4 years ago

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

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

So lets say,

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. 👍

Phoenix616 commented 4 years ago

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.