Interface ITeleporter

All Known Implementing Classes:

public interface ITeleporter
Interface for handling the placement of entities during dimension change.

An implementation of this interface can be used to place the entity in a safe location, or generate a return portal, for instance.

See the Teleporter class, which has been patched to implement this interface, for a vanilla example.

  • Method Details

    • placeEntity

      default Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean,Entity> repositionEntity)
      Called to handle placing the entity in the new world.

      The initial position of the entity will be its position in the origin world, multiplied horizontally by the computed cross-dimensional movement factor.

      Note that the supplied entity has not yet been spawned in the destination world at the time.

      entity - the entity to be placed
      currentWorld - the entity's origin
      destWorld - the entity's destination
      yaw - the suggested yaw value to apply
      repositionEntity - a function to reposition the entity, which returns the new entity in the new dimension. This is the vanilla implementation of the dimension travel logic. If the supplied boolean is true, it is attempted to spawn a new portal.
      the entity in the new World. Vanilla creates for most Entitys a new instance and copy the data. But you are not allowed to create a new instance for PlayerEntitys! Move the player and update its state, see ServerPlayerEntity.changeDimension(, ITeleporter)
    • getPortalInfo

      @Nullable default PortalInfo getPortalInfo(Entity entity, ServerWorld destWorld, Function<ServerWorld,PortalInfo> defaultPortalInfo)
      Gets the PortalInfo. defaultPortalInfo references the vanilla code and should not be used for your purposes. Override this method to handle your own logic.

      Return null to prevent teleporting.

      entity - The entity teleporting before the teleport
      destWorld - The world the entity is teleporting to
      defaultPortalInfo - A reference to the vanilla method for getting portal info. You should implement your own logic instead of using this
      The location, rotation, and motion of the entity in the destWorld after the teleport
    • isVanilla

      default boolean isVanilla()
      Is this teleporter the vanilla instance.
    • playTeleportSound

      default boolean playTeleportSound(ServerPlayerEntity player, ServerWorld sourceWorld, ServerWorld destWorld)
      Called when vanilla wants to play the portal sound after teleporting. Return true to play the vanilla sound.
      player - the player
      sourceWorld - the source world
      destWorld - the target world
      true to play the vanilla sound