From 1d7b7644d1d375c080a5115070c6e5407f5fe959 Mon Sep 17 00:00:00 2001 From: CreepyCre Date: Tue, 16 Feb 2021 11:19:39 +0100 Subject: [PATCH] proper teleportation velocity --- .../block/entity/DetachedRiftBlockEntity.java | 2 +- .../block/entity/EntranceRiftBlockEntity.java | 7 +--- .../dimdoors/command/DimTeleportCommand.java | 2 +- .../dimdoors/rift/targets/EscapeTarget.java | 4 +- .../dimdoors/rift/targets/LimboTarget.java | 2 +- .../dimdoors/rift/targets/VirtualTarget.java | 2 +- .../dimdev/dimdoors/util/TeleportUtil.java | 37 +++++++++---------- 7 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/dimdev/dimdoors/block/entity/DetachedRiftBlockEntity.java b/src/main/java/org/dimdev/dimdoors/block/entity/DetachedRiftBlockEntity.java index 9db6927d..1173d2f4 100644 --- a/src/main/java/org/dimdev/dimdoors/block/entity/DetachedRiftBlockEntity.java +++ b/src/main/java/org/dimdev/dimdoors/block/entity/DetachedRiftBlockEntity.java @@ -122,7 +122,7 @@ public class DetachedRiftBlockEntity extends RiftBlockEntity { @Override public boolean receiveEntity(Entity entity, Vec3d relativePos, EulerAngle relativeAngle, Vec3d velocity) { if (this.world instanceof ServerWorld) - TeleportUtil.teleport(entity, this.world, this.pos, relativeAngle); + TeleportUtil.teleport(entity, this.world, this.pos, relativeAngle, velocity); return true; } diff --git a/src/main/java/org/dimdev/dimdoors/block/entity/EntranceRiftBlockEntity.java b/src/main/java/org/dimdev/dimdoors/block/entity/EntranceRiftBlockEntity.java index 0eab507a..41a79fa7 100644 --- a/src/main/java/org/dimdev/dimdoors/block/entity/EntranceRiftBlockEntity.java +++ b/src/main/java/org/dimdev/dimdoors/block/entity/EntranceRiftBlockEntity.java @@ -56,8 +56,6 @@ public class EntranceRiftBlockEntity extends RiftBlockEntity { if (block instanceof CoordinateTransformerBlock) { CoordinateTransformerBlock transformer = (CoordinateTransformerBlock) block; - System.out.println("{yaw: " + relativeAngle.getYaw() + "; pitch: " + relativeAngle.getPitch() + "; roll: " + relativeAngle.getRoll() + "}"); - if (transformer.isExitFlipped()) { TransformationMatrix3d flipper = TransformationMatrix3d.builder().rotateY(Math.PI).build(); @@ -66,8 +64,6 @@ public class EntranceRiftBlockEntity extends RiftBlockEntity { relativeVelocity = flipper.transform(relativeVelocity); } - System.out.println("{yaw: " + relativeAngle.getYaw() + "; pitch: " + relativeAngle.getPitch() + "; roll: " + relativeAngle.getRoll() + "}"); - relativePos = relativePos.add(new Vec3d(0, 0, 1).multiply(0.6)); // TODO: skip this for Immersive Portals TransformationMatrix3d.TransformationMatrix3dBuilder transformationBuilder = transformer.transformationBuilder(state, this.getPos()); @@ -77,8 +73,7 @@ public class EntranceRiftBlockEntity extends RiftBlockEntity { relativeVelocity = transformer.rotateOut(rotatorBuilder, relativeVelocity); } - TeleportUtil.teleport(entity, this.world, targetPos, relativeAngle); - entity.setVelocity(relativeVelocity); + entity = TeleportUtil.teleport(entity, this.world, targetPos, relativeAngle, relativeVelocity); if (entity instanceof ServerPlayerEntity) { ServerPlayerEntity player = (ServerPlayerEntity) entity; player.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(player)); diff --git a/src/main/java/org/dimdev/dimdoors/command/DimTeleportCommand.java b/src/main/java/org/dimdev/dimdoors/command/DimTeleportCommand.java index 05129d53..7fea8232 100644 --- a/src/main/java/org/dimdev/dimdoors/command/DimTeleportCommand.java +++ b/src/main/java/org/dimdev/dimdoors/command/DimTeleportCommand.java @@ -34,7 +34,7 @@ public class DimTeleportCommand { } private static int teleport(Entity entity, ServerWorld dimension, Vec3d pos) { - TeleportUtil.teleport(entity, dimension, pos, MathUtil.entityEulerAngle(entity)); + TeleportUtil.teleport(entity, dimension, pos, MathUtil.entityEulerAngle(entity), entity.getVelocity()); return Command.SINGLE_SUCCESS; } } diff --git a/src/main/java/org/dimdev/dimdoors/rift/targets/EscapeTarget.java b/src/main/java/org/dimdev/dimdoors/rift/targets/EscapeTarget.java index ee907320..ddf9434e 100644 --- a/src/main/java/org/dimdev/dimdoors/rift/targets/EscapeTarget.java +++ b/src/main/java/org/dimdev/dimdoors/rift/targets/EscapeTarget.java @@ -48,7 +48,7 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD Location destLoc = DimensionalRegistry.getRiftRegistry().getOverworldRift(uuid); if (destLoc != null && destLoc.getBlockEntity() instanceof RiftBlockEntity || this.canEscapeLimbo) { Location location = VirtualLocation.fromLocation(new Location((ServerWorld) entity.world, entity.getBlockPos())).projectToWorld(false); - TeleportUtil.teleport(entity, location.getWorld(), location.getBlockPos(), relativeAngle); + TeleportUtil.teleport(entity, location.getWorld(), location.getBlockPos(), relativeAngle, relativeVelocity); } else { if (destLoc == null) { chat(entity, new TranslatableText("rifts.destinations.escape.did_not_use_rift")); @@ -56,7 +56,7 @@ public class EscapeTarget extends VirtualTarget implements EntityTarget { // TOD chat(entity, new TranslatableText("rifts.destinations.escape.rift_has_closed")); } if (ModDimensions.LIMBO_DIMENSION != null) { - TeleportUtil.teleport(entity, ModDimensions.LIMBO_DIMENSION, new BlockPos(this.location.getX(), this.location.getY(), this.location.getZ()), relativeAngle); + TeleportUtil.teleport(entity, ModDimensions.LIMBO_DIMENSION, new BlockPos(this.location.getX(), this.location.getY(), this.location.getZ()), relativeAngle, relativeVelocity); } } return true; diff --git a/src/main/java/org/dimdev/dimdoors/rift/targets/LimboTarget.java b/src/main/java/org/dimdev/dimdoors/rift/targets/LimboTarget.java index b660542f..ad2296ed 100644 --- a/src/main/java/org/dimdev/dimdoors/rift/targets/LimboTarget.java +++ b/src/main/java/org/dimdev/dimdoors/rift/targets/LimboTarget.java @@ -17,7 +17,7 @@ public class LimboTarget extends VirtualTarget implements EntityTarget { @Override public boolean receiveEntity(Entity entity, Vec3d relativePos, EulerAngle relativeAngle, Vec3d relativeVelocity) { - TeleportUtil.teleport(entity, ModDimensions.LIMBO_DIMENSION, entity.getPos(), relativeAngle); + TeleportUtil.teleport(entity, ModDimensions.LIMBO_DIMENSION, entity.getPos(), relativeAngle, relativeVelocity); return true; } diff --git a/src/main/java/org/dimdev/dimdoors/rift/targets/VirtualTarget.java b/src/main/java/org/dimdev/dimdoors/rift/targets/VirtualTarget.java index 87d14b60..1f53c2b6 100644 --- a/src/main/java/org/dimdev/dimdoors/rift/targets/VirtualTarget.java +++ b/src/main/java/org/dimdev/dimdoors/rift/targets/VirtualTarget.java @@ -93,7 +93,7 @@ public abstract class VirtualTarget implements Target { VirtualTargetType PRIVATE_POCKET_EXIT = register("dimdoors:private_pocket_exit", a -> new PrivatePocketExitTarget(), a -> new CompoundTag(), PrivatePocketExitTarget.COLOR); VirtualTargetType RELATIVE = register("dimdoors:relative", RelativeReference::fromTag, RelativeReference::toTag, VirtualTarget.COLOR); VirtualTargetType ID_MARKER = register("dimdoors:id_marker", IdMarker::fromTag, IdMarker::toTag, VirtualTarget.COLOR); - VirtualTargetType UNSTABLE = register("dimdoors:unstable", tag -> new UnstableTarget(), t -> new CompoundTag(), VirtualTarget.COLOR); + //VirtualTargetType UNSTABLE = register("dimdoors:unstable", tag -> new UnstableTarget(), t -> new CompoundTag(), VirtualTarget.COLOR); VirtualTargetType NONE = register("dimdoors:none", tag -> NoneTarget.INSTANCE, i -> new CompoundTag(), COLOR); T fromTag(CompoundTag tag); diff --git a/src/main/java/org/dimdev/dimdoors/util/TeleportUtil.java b/src/main/java/org/dimdev/dimdoors/util/TeleportUtil.java index 02201542..214a1bf0 100644 --- a/src/main/java/org/dimdev/dimdoors/util/TeleportUtil.java +++ b/src/main/java/org/dimdev/dimdoors/util/TeleportUtil.java @@ -18,49 +18,48 @@ import org.dimdev.dimdoors.util.math.MathUtil; @SuppressWarnings("deprecation") public final class TeleportUtil { - public static void teleport(Entity entity, World world, BlockPos pos, float yaw) { + public static E teleport(E entity, World world, BlockPos pos, float yaw) { if (world.isClient) { throw new UnsupportedOperationException("Only supported on ServerWorld"); } - teleport(entity, world, Vec3d.ofBottomCenter(pos), yaw); + return teleport(entity, world, Vec3d.ofBottomCenter(pos), yaw); } - public static void teleport(Entity entity, World world, Vec3d pos, float yaw) { + public static E teleport(E entity, World world, Vec3d pos, float yaw) { if (world.isClient) { throw new UnsupportedOperationException("Only supported on ServerWorld"); } - FabricDimensions.teleport(entity, (ServerWorld) world, new TeleportTarget(pos, entity.getVelocity(), yaw, entity.getPitch(1.0F))); + return FabricDimensions.teleport(entity, (ServerWorld) world, new TeleportTarget(pos, entity.getVelocity(), yaw, entity.getPitch(1.0F))); } - public static void teleport(Entity entity, World world, Vec3d pos, EulerAngle angle) { + public static E teleport(E entity, World world, Vec3d pos, EulerAngle angle, Vec3d velocity) { if (world.isClient) { throw new UnsupportedOperationException("Only supported on ServerWorld"); } - FabricDimensions.teleport(entity, (ServerWorld) world, new TeleportTarget(pos, entity.getVelocity(), angle.getYaw(), angle.getPitch())); + return FabricDimensions.teleport(entity, (ServerWorld) world, new TeleportTarget(pos, velocity, angle.getYaw(), angle.getPitch())); } - public static void teleport(Entity entity, World world, BlockPos pos, EulerAngle angle) { + public static E teleport(E entity, World world, BlockPos pos, EulerAngle angle, Vec3d velocity) { if (world.isClient) { throw new UnsupportedOperationException("Only supported on ServerWorld"); } - teleport(entity, world, Vec3d.ofBottomCenter(pos), angle); + return teleport(entity, world, Vec3d.ofBottomCenter(pos), angle, velocity); } - public static void teleport(ServerPlayerEntity player, Location location) { - teleport(player, DimensionalDoorsInitializer.getWorld(location.world), location.pos, 0); + public static ServerPlayerEntity teleport(ServerPlayerEntity player, Location location) { + return teleport(player, DimensionalDoorsInitializer.getWorld(location.world), location.pos, 0); } - public static void teleport(ServerPlayerEntity player, RotatedLocation location) { - teleport(player, DimensionalDoorsInitializer.getWorld(location.world), location.pos, (int) location.yaw); + public static ServerPlayerEntity teleport(ServerPlayerEntity player, RotatedLocation location) { + return teleport(player, DimensionalDoorsInitializer.getWorld(location.world), location.pos, (int) location.yaw); } - - public static void teleportRandom(Entity entity, World world, double y) { + public static E teleportRandom(E entity, World world, double y) { double scale = ThreadLocalRandom.current().nextGaussian() * ThreadLocalRandom.current().nextInt(90); - teleport( + return teleport( entity, world, entity.getPos() @@ -71,9 +70,9 @@ public final class TeleportUtil { ); } - public static void teleportUntargeted(Entity entity, World world) { + public static E teleportUntargeted(E entity, World world) { double actualScale = entity.world.getDimension().getCoordinateScale() / world.getDimension().getCoordinateScale(); - teleport( + return teleport( entity, world, entity.getPos().multiply(actualScale, 1, actualScale), @@ -81,9 +80,9 @@ public final class TeleportUtil { ); } - public static void teleportUntargeted(Entity entity, World world, double y) { + public static E teleportUntargeted(E entity, World world, double y) { double actualScale = entity.world.getDimension().getCoordinateScale() / world.getDimension().getCoordinateScale(); - teleport( + return teleport( entity, world, entity.getPos()