Package net.minecraftforge.common.util
Interface ITeleporter
- All Known Implementing Classes:
Teleporter
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 Summary
Modifier and TypeMethodDescriptiondefault PortalInfo
getPortalInfo
(Entity entity, ServerWorld destWorld, Function<ServerWorld, PortalInfo> defaultPortalInfo) Gets the PortalInfo.default boolean
Is this teleporter the vanilla instance.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.default boolean
playTeleportSound
(ServerPlayerEntity player, ServerWorld sourceWorld, ServerWorld destWorld) Called when vanilla wants to play the portal sound after teleporting.
-
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.
- Parameters:
entity
- the entity to be placedcurrentWorld
- the entity's origindestWorld
- the entity's destinationyaw
- the suggested yaw value to applyrepositionEntity
- 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
Entity
s a new instance and copy the data. But you are not allowed to create a new instance forPlayerEntity
s! Move the player and update its state, seeServerPlayerEntity.changeDimension(net.minecraft.world.server.ServerWorld, 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.- Parameters:
entity
- The entity teleporting before the teleportdestWorld
- The world the entity is teleporting todefaultPortalInfo
- 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(ServerPlayerEntity player, ServerWorld sourceWorld, ServerWorld destWorld) Called when vanilla wants to play the portal sound after teleporting. Return true to play the vanilla sound.- Parameters:
player
- the playersourceWorld
- the source worlddestWorld
- the target world- Returns:
- true to play the vanilla sound
-