Skip to content

Commit

Permalink
Add distance limit for out-of-range message (#91)
Browse files Browse the repository at this point in the history
Also fix the check so that we only display the message for travel anchors within the angle limit.
  • Loading branch information
D-Cysteine authored Jan 28, 2023
1 parent 0902a89 commit 8612980
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/java/crazypants/enderio/teleport/TravelController.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,25 +309,31 @@ public Optional<BlockCoord> findTravelDestination(EntityPlayer player, TravelSou

// Map of distance to coordinate for eligible travel destinations (within angle).
Map<Double, BlockCoord> distanceMap = new TreeMap<>();
boolean outOfRange = false;
// Limit the max distance at which we'll display an out of range message.
// Otherwise, you could trigger the message for any travel anchor on the entire server.
double maxMessageDistance = 1.25 * source.getMaxDistanceTravelled();
boolean displayOutOfRangeMessage = false;
for (BlockCoord p : travelDestinations) {
Vector3d block = new Vector3d(p.x + 0.5, p.y + 0.5, p.z + 0.5);
block.sub(eye);
double distance = block.length();
if (distance > source.getMaxDistanceTravelled()) {
outOfRange = true;
if (distance > maxMessageDistance) {
continue;
}
block.normalize();

double angle = Math.acos(look.dot(block));
// Roughly 5 degrees
if (angle < 0.087) {
distanceMap.put(distance, p);
if (distance > source.getMaxDistanceTravelled()) {
displayOutOfRangeMessage = true;
} else {
distanceMap.put(distance, p);
}
}
}

if (outOfRange && distanceMap.isEmpty()) {
if (displayOutOfRangeMessage && distanceMap.isEmpty()) {
player.addChatComponentMessage(new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
}

Expand Down

0 comments on commit 8612980

Please sign in to comment.