Recently I have been developing a plugin allowing players to teleport any kind of entity anywhere in a server.
I have a problem when I attempt to teleport a non-player entity from one world to another using the entity.teleport(Location<World>)
method. Players can be teleported fairly seamlessly between worlds, and non-player entities can be teleported around in the same world just fine. But when I teleport a non-player entity into another world, the entity will vanish. I have checked the entity’s location using entity.getLocation()
after the teleport and the position is changed correctly, but the world remains the same world that the entity was teleported from. Furthermore, when I go to the reported location that entity.getLocation()
says the entity is at, the entity is gone. I have checked the area for the teleported entity in MCEdit but was unable to find it.
Back when I wrote this plugin for Bukkit, I faced the same problems. The main difference between Bukkit’s behavior and Sponge’s behavior is that in Bukkit the entities could be found at the position they were supposed to be teleported to, but in the world they were supposed to be teleported from. I solved the problem in my Bukkit plugin by killing the entity in the old world and copying the data to an entity spawned in the new world.
I have tried the same approach I used in my Bukkit plugin in my Sponge plugin, but have encountered problems with it (spawn condition constraints like being unable to spawn a minecart on the ground or in a block, and some weird effects when automatically remounting a teleported player onto the teleported entity, but that might be unrelated). There might have been some problems with my Sponge version of this solution. For example: I used entity.toContainer()
and created the new entity from the returned DataContainer
, but I am not sure if that is a good idea.
In short: I am searching for a way to teleport non-player entities from one world to any location in another world without having to worry about de-sync, the teleported entity getting lost along the way, satisfying spawn conditions, or defining custom cases for every entity type to copy the entity’s data to a newly spawned one.
Any help would be appreciated.
Thanks in advance.