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);
}
}
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());
}
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);
}
}
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());
}
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.");
}
}
Aggregations