Interface ITeleporter

All Known Implementing Classes:
PortalForcer

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 PortalForcer class, which has been patched to implement this interface, for a vanilla example.

  • Method Details

    • placeEntity

      default Entity placeEntity(Entity entity, ServerLevel currentWorld, ServerLevel 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.

      Parameters:
      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.
      Returns:
      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 Players! Move the player and update its state, see ServerPlayer.changeDimension(ServerLevel, ITeleporter)
    • getPortalInfo

      @Nullable default PortalInfo getPortalInfo(Entity entity, ServerLevel destWorld, Function<ServerLevel,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.

      Parameters:
      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
      Returns:
      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(ServerPlayer player, ServerLevel sourceWorld, ServerLevel destWorld)
      Called when vanilla wants to play the portal sound after teleporting. Return true to play the vanilla sound.
      Parameters:
      player - the player
      sourceWorld - the source world
      destWorld - the target world
      Returns:
      true to play the vanilla sound