Search in sources :

Example 1 with TeleportTarget

use of net.minecraft.world.TeleportTarget in project gobber_fabric-1.17 by kwpugh.

the class RingTeleport method teleport.

public void teleport(PlayerEntity player, World world, ItemStack stack) {
    if (world.isClient)
        return;
    BlockPos pos = getPosition(stack);
    String dim = getDimension(stack);
    ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
    // Build world to test from stored data
    RegistryKey<World> storedKey = RegistryKey.of(Registry.WORLD_KEY, new Identifier(dim));
    ServerWorld storedWorld = ((ServerWorld) world).getServer().getWorld(storedKey);
    if (storedWorld == null || pos == null) {
        serverPlayer.sendMessage(new TranslatableText("item.ring_of_teleport.ring_of_teleport.tip9"), true);
    } else {
        TeleportTarget target = new TeleportTarget(new Vec3d(pos.getX() + 0.5F, pos.getY(), pos.getZ() + 0.5F), new Vec3d(0, 0, 0), serverPlayer.getYaw(), serverPlayer.getPitch());
        doTeleport(serverPlayer, storedWorld, target);
        world.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F);
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) TranslatableText(net.minecraft.text.TranslatableText) TeleportTarget(net.minecraft.world.TeleportTarget) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) World(net.minecraft.world.World) ServerWorld(net.minecraft.server.world.ServerWorld) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with TeleportTarget

use of net.minecraft.world.TeleportTarget in project Interdimensional by QuiltServerTools.

the class CustomTeleporter method buildTPTargetInDestPortal.

public static TeleportTarget buildTPTargetInDestPortal(BlockLocating.Rectangle portalRect, Direction.Axis portalAxis, Vec3d offset, Entity entity) {
    EntityDimensions entityDimensions = entity.getDimensions(entity.getPose());
    double width = portalRect.width - entityDimensions.width;
    double height = portalRect.height - entityDimensions.height;
    double x = MathHelper.lerp(offset.x, portalRect.lowerLeft.getX(), portalRect.lowerLeft.getX() + width);
    double y = MathHelper.lerp(offset.y, portalRect.lowerLeft.getY(), portalRect.lowerLeft.getY() + height);
    double z = MathHelper.lerp(offset.z, portalRect.lowerLeft.getZ(), portalRect.lowerLeft.getZ() + width);
    if (portalAxis == Direction.Axis.X)
        z = portalRect.lowerLeft.getZ() + 0.5D;
    else if (portalAxis == Direction.Axis.Z)
        x = portalRect.lowerLeft.getX() + .5D;
    return new TeleportTarget(new Vec3d(x, y, z), entity.getVelocity(), entity.getYaw(), entity.getPitch());
}
Also used : EntityDimensions(net.minecraft.entity.EntityDimensions) TeleportTarget(net.minecraft.world.TeleportTarget) Vec3d(net.minecraft.util.math.Vec3d)

Example 3 with TeleportTarget

use of net.minecraft.world.TeleportTarget in project Interdimensional by QuiltServerTools.

the class CustomTeleporter method TPToDim.

public static void TPToDim(World world, Entity entity, Block portalBase, BlockPos portalPos) {
    PortalLink link = CustomPortalApiRegistry.getPortalLinkFromBase(portalBase);
    if (link == null)
        return;
    if (link.executeBeforeTPEvent(entity) == SHOULDTP.CANCEL_TP)
        return;
    RegistryKey<World> destKey = world.getRegistryKey() == InterdimensionalPortals.dims.get(link.dimID) ? InterdimensionalPortals.dims.get(link.returnDimID) : InterdimensionalPortals.dims.get(link.dimID);
    ServerWorld destination = ((ServerWorld) world).getServer().getWorld(destKey);
    if (destination == null)
        return;
    TeleportTarget target = customTPTarget(destination, entity, portalPos, portalBase, link.getFrameTester());
    ((CustomTeleportingEntity) entity).setCustomTeleportTarget(target);
    entity = entity.moveToWorld(destination);
    if (entity != null) {
        entity.setYaw(target.yaw);
        entity.setPitch(target.pitch);
        if (entity instanceof ServerPlayerEntity)
            entity.refreshPositionAfterTeleport(target.position);
        link.executePostTPEvent(entity);
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) TeleportTarget(net.minecraft.world.TeleportTarget) CustomTeleportingEntity(net.quiltservertools.interdimensional.portals.interfaces.CustomTeleportingEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) World(net.minecraft.world.World) ServerWorld(net.minecraft.server.world.ServerWorld)

Example 4 with TeleportTarget

use of net.minecraft.world.TeleportTarget in project Interdimensional by QuiltServerTools.

the class CustomTeleporter method idkWhereToPutYou.

protected static TeleportTarget idkWhereToPutYou(ServerWorld world, Entity entity, BlockPos pos) {
    InterdimensionalPortals.logError("Unable to find find tp location, forced to place on top of world");
    BlockPos destinationPos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, pos);
    return new TeleportTarget(new Vec3d(destinationPos.getX() + .5, destinationPos.getY(), destinationPos.getZ() + .5), entity.getVelocity(), entity.getYaw(), entity.getPitch());
}
Also used : TeleportTarget(net.minecraft.world.TeleportTarget) DimensionalBlockPos(net.quiltservertools.interdimensional.portals.portal.linking.DimensionalBlockPos) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 5 with TeleportTarget

use of net.minecraft.world.TeleportTarget in project quilt-standard-libraries by QuiltMC.

the class QuiltDimensionTest method readyServer.

@Override
public void readyServer(MinecraftServer server) {
    ServerWorld overworld = server.getWorld(World.OVERWORLD);
    ServerWorld targetWorld = server.getWorld(WORLD_KEY);
    if (targetWorld == null) {
        throw new AssertionError("Test world somehow doesn't exist.");
    }
    CowEntity cow = EntityType.COW.create(overworld);
    if (!cow.world.getRegistryKey().equals(World.OVERWORLD)) {
        throw new AssertionError("Cow was spawned but isn't in the overworld.");
    }
    var target = new TeleportTarget(Vec3d.ZERO, new Vec3d(1, 1, 1), 45f, 60f);
    CowEntity teleportedEntity = QuiltDimensions.teleport(cow, targetWorld, target);
    if (teleportedEntity == null || !teleportedEntity.world.getRegistryKey().equals(WORLD_KEY)) {
        throw new AssertionError("Cow was not teleported correctly.");
    }
    if (!teleportedEntity.getPos().equals(target.position)) {
        throw new AssertionError("Cow was moved to different world, but not to the correct location.");
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) TeleportTarget(net.minecraft.world.TeleportTarget) CowEntity(net.minecraft.entity.passive.CowEntity) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

TeleportTarget (net.minecraft.world.TeleportTarget)6 Vec3d (net.minecraft.util.math.Vec3d)5 ServerWorld (net.minecraft.server.world.ServerWorld)4 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)3 BlockPos (net.minecraft.util.math.BlockPos)3 World (net.minecraft.world.World)2 CommandException (net.minecraft.command.CommandException)1 EntityDimensions (net.minecraft.entity.EntityDimensions)1 CowEntity (net.minecraft.entity.passive.CowEntity)1 TranslatableText (net.minecraft.text.TranslatableText)1 CustomTeleportingEntity (net.quiltservertools.interdimensional.portals.interfaces.CustomTeleportingEntity)1 DimensionalBlockPos (net.quiltservertools.interdimensional.portals.portal.linking.DimensionalBlockPos)1