Skip to content

Commit

Permalink
Fixed teleportation angles not calculating correct facing.
Browse files Browse the repository at this point in the history
  • Loading branch information
50ap5ud5 committed Mar 2, 2024
1 parent bec2a83 commit 57460f4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public Direction getEntryRotation() {
return this.getBlockState().getValue(InternalDoorBlock.FACING).getOpposite();
}

@Override
public Direction getDoorRotation() {
return this.getBlockState().getValue(InternalDoorBlock.FACING);
}

@Override
public void onEntityExit(ServerEntity entity) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public interface TardisInternalDoor {
BlockPos getEntryPosition();
Direction getEntryRotation();

/** The true facing of the internal door based off its blockstate*/
Direction getDoorRotation();

void onEntityExit(ServerEntity entity);

void setLocked(boolean locked);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public boolean enterTardis(Entity entity, BlockPos externalShellPos, ServerLevel
if (this.level instanceof ServerLevel targetServerLevel){

BlockPos targetPosition = internalDoor != null ? internalDoor.getEntryPosition() : TardisArchitectureHandler.DESKTOP_CENTER_POS.above();
Direction doorDirection = internalDoor != null ? internalDoor.getEntryRotation() : entity.getDirection();
Direction doorDirection = internalDoor != null ? internalDoor.getDoorRotation() : entity.getDirection();

TardisNavLocation sourceLocation = new TardisNavLocation(externalShellPos, shellDirection, shellLevel);
TardisNavLocation targetLocation = new TardisNavLocation(targetPosition, doorDirection, targetServerLevel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ private static Entity teleportEntityOtherDimension(Entity pEntity, ServerLevel d
newEntity.moveTo(pX, pY, pZ, yRot, xRot);
newEntity.setYHeadRot(yRot);
newEntity.setPortalCooldown();
newEntity.setDeltaMovement(Vec3.ZERO);

pEntity.remove(Entity.RemovalReason.CHANGED_DIMENSION);
destination.addDuringTeleport(newEntity); //DO NOT add the entity to the destination before removing them, else we will teleport them to the coordinates from the source world
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,21 @@ public static boolean teleportEntityTardis(TardisLevelOperator cap, Entity entit

BlockPos destinationPos = destinationLocation.getPosition();
ServerLevel destinationLevel = destinationLocation.getLevel();
Direction destinationDirection = destinationLocation.getDirection();
Direction destinationDirection = destinationLocation.getDirection().getOpposite(); //Use the opposite facing of the destination so that when teleported, the entity faces away from the doorway

Direction sourceDirection = sourceLocation.getDirection();


BlockPos targetTeleportPos = destinationPos;

//Calculate entity motion and rotation, taking into account for the internal door's direction and rotation
float entityYRot = entity.getYRot();
float destinationRotationYaw = destinationDirection.toYRot();
//Calculate the difference between the entity's rotation and the destination direction's rotation. Get the difference and find the final rotation that preserves the entities' rotation but facing the direction at the destination
float diff = LevelHelper.getAdjustedRotation(entityYRot) - LevelHelper.getAdjustedRotation(destinationRotationYaw);
float sourceRotationYaw = sourceDirection.toYRot();
//Calculate the difference between the entity's rotation and the source direction's rotation. Get the difference and find the final rotation that preserves the entities' rotation but facing the direction at the destination
float diff = LevelHelper.getAdjustedRotation(entityYRot) - LevelHelper.getAdjustedRotation(sourceRotationYaw);

float adjustedRotationYaw = LevelHelper.getAngleFromDirection(destinationDirection) + diff;
float adjustedRotationYaw = destinationRotationYaw + diff;

if (entity.getType().getDimensions().width > 1F){
targetTeleportPos = destinationPos.offset(destinationDirection.getNormal());
Expand Down

0 comments on commit 57460f4

Please sign in to comment.