Hytale Modding
Hytale Modding
Server Plugins

Teleporting the player

Learn how to teleport the player.

Written by oskarscot

Teleporting players in Hytale works by simply attaching a Teleport component to a player with the desired world and transform. You can only trigger teleports from a world where the player is currently present. Teleport itself is a component but it also provides factory methods to configure the Teleport. Just as with any entity component, an EntityStore and a Ref to the EntityStore is required

We can create a simple teleport utility like this:

public static void teleportPlayer(Ref<EntityStore> ref, Store<EntityStore> store, World targetWorld, double x, double y, double z) {                                                                                       
    Transform transform = new Transform(x, y, z);                                                                                                                           
    Teleport teleport = Teleport.createForPlayer(targetWorld, transform);                                                                                                   
    store.addComponent(ref, Teleport.getComponentType(), teleport);                                                                                                         
}  

A Transform is a representation of a position Vector3d and rotation Vector3f which works in the following way:

Transform transform = new Transform(
    new Vector3d(x, y, z),      // Position
    new Rotation(yaw, pitch, 0) // Rotation, last value seems to always be 0
);
Teleport teleport = Teleport.createForPlayer(targetWorld, transform);
store.addComponent(ref, Teleport.getComponentType(), teleport);