Start on Teleportation

This commit is contained in:
SD 2020-12-12 12:45:08 +05:30
parent 38857cd25b
commit fe36440d58
No known key found for this signature in database
GPG key ID: E36B57EE08544BC5

View file

@ -7,8 +7,11 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
public final class TeleportUtil { public final class TeleportUtil {
public static void teleport(Entity entity, World world, BlockPos pos, int yawOffset) { public static void teleport(Entity entity, World world, BlockPos pos, int yawOffset) {
if (world.isClient) { if (world.isClient) {
@ -23,15 +26,7 @@ public final class TeleportUtil {
throw new UnsupportedOperationException("Only supported on ServerWorld"); throw new UnsupportedOperationException("Only supported on ServerWorld");
} }
if (entity instanceof ServerPlayerEntity) { FabricDimensions.teleport(entity, (ServerWorld) world, new TeleportTarget(pos, entity.getVelocity(), entity.getYaw(1.0F) + yawOffset, entity.getPitch(1.0F)));
((ServerPlayerEntity) entity).teleport((ServerWorld) world, pos.x, pos.y, pos.z, entity.getYaw(1.0F) + yawOffset, entity.getPitch(1.0F));
} else if (entity.world.getRegistryKey().equals(world.getRegistryKey())) {
entity.setPos(pos.x, pos.y, pos.z);
entity.setYaw(entity.yaw + yawOffset);
} else {
EntityUtils.prepareTeleportation(entity, pos, yawOffset);
entity.moveToWorld((ServerWorld) world);
}
} }
public static void teleport(ServerPlayerEntity player, Location location) { public static void teleport(ServerPlayerEntity player, Location location) {