Skip to content

Commit

Permalink
Lessen isTeleportPositionClear restrictions
Browse files Browse the repository at this point in the history
Since players can crawl let them teleport to
1-high gaps if they want to.
Additionally: Fix checkstyle errors.
  • Loading branch information
DoctorNefario committed Oct 19, 2023
1 parent cdc9c02 commit 1c55f72
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/main/java/com/enderio/base/common/handler/TravelHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ public static Optional<Vec3> teleportPosition(Level level, Player player) {
BlockPos newTarget = BlockGetter.traverseBlocks(traverseFrom, toPos, clipCtx, (traverseCtx, traversePos) -> {
// check underneath first, since that's more likely to be where the player wants to teleport
BlockPos checkBelow = traversalCheck(level, traversePos.below());
if (checkBelow != null)
if (checkBelow != null) {
return checkBelow;
}

return traversalCheck(level, traversePos);
}, (failCtx) -> failPosition);
Expand Down Expand Up @@ -172,8 +173,9 @@ public static Optional<Vec3> teleportPosition(Level level, Player player) {
private static BlockPos traversalCheck(Level level, BlockPos traversePos) {
BlockState blockState = level.getBlockState(traversePos);
var collision = blockState.getCollisionShape(level, traversePos);
if (collision.isEmpty() && isTeleportPositionClear(level, traversePos.below()).isPresent())
if (collision.isEmpty() && isTeleportPositionClear(level, traversePos.below()).isPresent()) {
return traversePos;
}
return null;
}

Expand Down Expand Up @@ -209,16 +211,16 @@ private static Optional<Double> isTeleportPositionClear(BlockGetter level, Block
return Optional.empty();
}

if (!level.getBlockState(target.above(2)).canOcclude()) {
BlockPos above = target.above();
double height = level.getBlockState(above).getCollisionShape(level, above).max(Direction.Axis.Y);
if (height > 0.2d && !level.getBlockState(target.above(3)).canOcclude() || height <=0.2d) {
if (height == Double.NEGATIVE_INFINITY) {
height = 0;
}
BlockPos above = target.above();
double height = level.getBlockState(above).getCollisionShape(level, above).max(Direction.Axis.Y);
if (height <= 0.2d) {
return Optional.of(Math.max(height, 0));
}

return Optional.of(height);
}
above = above.above();
boolean noCollisionAbove = level.getBlockState(above).getCollisionShape(level, above).isEmpty();
if (noCollisionAbove) {
return Optional.of(Math.max(height, 0));
}

return Optional.empty();
Expand Down

0 comments on commit 1c55f72

Please sign in to comment.