From 67d49173dc61f76ce57fa44622e0d23c8e15b593 Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Sun, 19 May 2024 16:19:49 -0600 Subject: [PATCH 1/2] Don't conserve momentum --- src/main/java/crazypants/enderio/teleport/TravelController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java index c80f0883..ba6b9133 100644 --- a/src/main/java/crazypants/enderio/teleport/TravelController.java +++ b/src/main/java/crazypants/enderio/teleport/TravelController.java @@ -339,7 +339,7 @@ public class TravelController { public boolean doTeleport(EntityPlayer player) { Optional destinationOptional = findTeleportDestination(player); if (destinationOptional.isPresent()) { - return travelToLocation(player, TravelSource.TELEPORT_STAFF_BLINK, destinationOptional.get(), true); + return travelToLocation(player, TravelSource.TELEPORT_STAFF_BLINK, destinationOptional.get(), false); } return false; } From c6be6cf6000ef24916e5e46510c61a73204883e0 Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Mon, 27 May 2024 12:53:58 -0600 Subject: [PATCH 2/2] Address review comments --- .../crazypants/enderio/config/Config.java | 40 +--- .../enderio/teleport/ItemTeleportStaff.java | 48 ++--- .../enderio/teleport/TravelController.java | 204 +++++++++--------- .../teleport/anchor/TileTravelAnchor.java | 3 + 4 files changed, 135 insertions(+), 160 deletions(-) diff --git a/src/main/java/crazypants/enderio/config/Config.java b/src/main/java/crazypants/enderio/config/Config.java index eb8c2c4d..86b14863 100644 --- a/src/main/java/crazypants/enderio/config/Config.java +++ b/src/main/java/crazypants/enderio/config/Config.java @@ -174,8 +174,6 @@ public final class Config { * The distance travelled when no block is found within {@link #teleportStaffMaxBlinkDistance}. */ public static int teleportStaffFailedBlinkDistance = 64; - /** If true, use the original staff of teleportation controls. */ - public static boolean teleportStaffOriginalControls = false; /** * Sets the teleport staff right-click action. @@ -188,9 +186,6 @@ public final class Config { *
  • 2: Teleport to anchor *
  • 3: Teleport to anchor, or to look if no anchor (default) * - * - *

    - * Overridden if {@link #teleportStaffOriginalControls} is true. */ public static int teleportStaffAction = 3; @@ -205,9 +200,6 @@ public final class Config { *

  • 2: Teleport to anchor *
  • 3: Teleport to anchor, or to look if no anchor * - * - *

    - * Overridden if {@link #teleportStaffOriginalControls} is true. */ public static int teleportStaffSneakAction = 1; @@ -1305,35 +1297,25 @@ public final class Config { "Number of blocks teleported when no block is being looked at.") .getInt(teleportStaffFailedBlinkDistance); - teleportStaffOriginalControls = config.get( - sectionPersonal.name, - "teleportStaffOriginalControls", - teleportStaffOriginalControls, - "If true, the staff of teleportation will use its original controls: R-Click for teleport to look, Shift R-Click for teleport to anchor.") - .getBoolean(teleportStaffOriginalControls); - teleportStaffAction = config.get( - sectionPersonal.name, + sectionStaff.name, "teleportStaffAction", teleportStaffAction, "Sets the action for right-click with the staff of teleportation. Values:\n" + " 0: Do nothing\n" + " 1: Teleport to look\n" + " 2: Teleport to anchor\n" - + " 3: Teleport to anchor, or look if no anchor (default)\n" - + "Overridden if teleportStaffOriginalControls is true.") + + " 3: Teleport to anchor, or look if no anchor (default)") .getInt(teleportStaffAction); - teleportStaffSneakAction = config - .get( - sectionPersonal.name, - "teleportStaffSneakAction", - teleportStaffSneakAction, - "Sets the action for sneak right-click with the staff of teleportation. Values:\n" - + " 0: Do nothing\n" - + " 1: Teleport to look (default)\n" - + " 2: Teleport to anchor\n" - + " 3: Teleport to anchor, or look if no anchor\n" - + "Overridden if teleportStaffOriginalControls is true.") + teleportStaffSneakAction = config.get( + sectionStaff.name, + "teleportStaffSneakAction", + teleportStaffSneakAction, + "Sets the action for sneak right-click with the staff of teleportation. Values:\n" + + " 0: Do nothing\n" + + " 1: Teleport to look (default)\n" + + " 2: Teleport to anchor\n" + + " 3: Teleport to anchor, or look if no anchor") .getInt(teleportStaffSneakAction); enderIoRange = config.get( diff --git a/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java b/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java index aca83f03..0331bcc6 100644 --- a/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java +++ b/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java @@ -57,38 +57,28 @@ public class ItemTeleportStaff extends ItemTravelStaff { @Override public ItemStack onItemRightClick(ItemStack equipped, World world, EntityPlayer player) { if (world.isRemote) { - if (Config.teleportStaffOriginalControls) { - if (player.isSneaking()) { + int action = player.isSneaking() ? Config.teleportStaffSneakAction : Config.teleportStaffAction; + switch (action) { + case 0: + // Do nothing. + break; + + case 1: + TravelController.instance.doTeleport(player); + player.swingItem(); + break; + + case 2: TravelController.instance .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF); - } else { - TravelController.instance.doTeleport(player); - } - player.swingItem(); - } else { - int action = player.isSneaking() ? Config.teleportStaffSneakAction : Config.teleportStaffAction; - switch (action) { - case 0: - // Do nothing. - break; + player.swingItem(); + break; - case 1: - TravelController.instance.doTeleport(player); - player.swingItem(); - break; - - case 2: - TravelController.instance - .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF); - player.swingItem(); - break; - - case 3: - TravelController.instance - .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF, true); - player.swingItem(); - break; - } + case 3: + TravelController.instance + .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF, true); + player.swingItem(); + break; } } return equipped; diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java index ba6b9133..9c97d960 100644 --- a/src/main/java/crazypants/enderio/teleport/TravelController.java +++ b/src/main/java/crazypants/enderio/teleport/TravelController.java @@ -344,106 +344,6 @@ public class TravelController { return false; } - /** Finds the destination for the teleport staff super-teleport, or returns empty optional if unsuccessful. */ - public Optional findTeleportDestination(EntityPlayer player) { - TravelSource source = TravelSource.TELEPORT_STAFF_BLINK; - - Vector3d eye = Util.getEyePositionEio(player); - Vector3d look = Util.getLookVecEio(player); - - double playerHeight = player.yOffset; - // +2 to compensate for the standard distance decrement of -2 - double teleDistance = Config.teleportStaffFailedBlinkDistance + 2; - Vec3 eye3 = Vec3.createVectorHelper(eye.x, eye.y, eye.z); - - // rayTraceBlocks has a limit of 200 distance. - double maxDistance = Config.teleportStaffMaxBlinkDistance; - double currDistance = 0; - Vec3 pos = eye3; - boolean loop = true; - while (loop) { - double distance = 200; - if (maxDistance - currDistance < 200) { - distance = maxDistance - currDistance; - loop = false; - } - - Vector3d sample = new Vector3d(look); - sample.scale(distance); - sample.add(eye); - Vec3 end = Vec3.createVectorHelper(sample.x, sample.y, sample.z); - - MovingObjectPosition p = player.worldObj - .rayTraceBlocks(pos, end, !Config.travelStaffBlinkThroughClearBlocksEnabled); - if (p != null) { - teleDistance = VecmathUtil.distance(eye, new Vector3d(p.blockX + 0.5, p.blockY + 0.5, p.blockZ + 0.5)); - break; - } - - pos = end; - currDistance += distance; - } - - Vector3d sample = new Vector3d(look); - sample.scale(Config.teleportStaffMaxBlinkDistance); - sample.add(eye); - Vec3 end = Vec3.createVectorHelper(sample.x, sample.y, sample.z); - MovingObjectPosition p = player.worldObj - .rayTraceBlocks(eye3, end, !Config.travelStaffBlinkThroughClearBlocksEnabled); - if (p != null) { - teleDistance = VecmathUtil.distance(eye, new Vector3d(p.blockX + 0.5, p.blockY + 0.5, p.blockZ + 0.5)); - } - - double distanceIncrement = -2; - int maxIter = Math.min(8, (int) teleDistance / 2); - // Special case: if the targeted block is too close, we'll try to teleport through it. - if (teleDistance < 4) { - distanceIncrement = 0.5; - maxIter = 32; - } - - for (int i = 0; i < maxIter; i++) { - teleDistance += distanceIncrement; - - sample.set(look); - sample.scale(teleDistance); - sample.add(eye); - // we test against our feets location - sample.y -= playerHeight; - - Optional destinationOptional = findNearbyDestination(player, source, sample); - if (destinationOptional.isPresent()) { - return destinationOptional; - } - } - return Optional.empty(); - } - - /** Finds a long-distance travel anchor, or returns empty optional if unsuccessful. */ - public Optional findTravelDestination(EntityPlayer player, TravelSource source) { - double maxDistance = source.getMaxDistanceTravelled(); - double maxMessageDistance = 1.25 * maxDistance; - // Find possible destinations within about 5 degrees. - RowSortedTable possibleDestinations = findBlocksWithinAngle( - player, - travelDestinations.get(player.worldObj.provider.dimensionId), - 0.087, - maxMessageDistance); - - for (Table.Cell cell : possibleDestinations.cellSet()) { - if (cell.getColumnKey() <= maxDistance) { - return Optional.of(cell.getValue()); - } - } - - if (!possibleDestinations.isEmpty()) { - // We found at least one block within maxMessageDistance, but no blocks within maxDistance. - showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange")); - } - - return Optional.empty(); - } - private boolean isBlackListedBlock(EntityPlayer player, MovingObjectPosition pos, Block hitBlock) { UniqueIdentifier ui = GameRegistry.findUniqueIdentifierFor(hitBlock); if (ui == null) { @@ -624,9 +524,9 @@ public class TravelController { return getTravelItemTravelSource(ep, checkInventoryAndBaubles) != null; } + /** Currently, we only hide travel targets for the teleport staff, in certain action modes. */ public boolean shouldHideTargets(EntityPlayer ep) { - if (getTravelItemTravelSource(ep, false) != TravelSource.TELEPORT_STAFF - || Config.teleportStaffOriginalControls) { + if (getTravelItemTravelSource(ep, false) != TravelSource.TELEPORT_STAFF) { return false; } @@ -728,6 +628,106 @@ public class TravelController { return travelItemSlot; } + /** Finds the destination for the teleport staff super-teleport, or returns empty optional if unsuccessful. */ + public Optional findTeleportDestination(EntityPlayer player) { + TravelSource source = TravelSource.TELEPORT_STAFF_BLINK; + + Vector3d eye = Util.getEyePositionEio(player); + Vector3d look = Util.getLookVecEio(player); + + double playerHeight = player.yOffset; + // +2 to compensate for the standard distance decrement of -2 + double teleDistance = Config.teleportStaffFailedBlinkDistance + 2; + Vec3 eye3 = Vec3.createVectorHelper(eye.x, eye.y, eye.z); + + // rayTraceBlocks has a limit of 200 distance. + double maxDistance = Config.teleportStaffMaxBlinkDistance; + double currDistance = 0; + Vec3 pos = eye3; + boolean loop = true; + while (loop) { + double distance = 200; + if (maxDistance - currDistance < 200) { + distance = maxDistance - currDistance; + loop = false; + } + + Vector3d sample = new Vector3d(look); + sample.scale(distance); + sample.add(eye); + Vec3 end = Vec3.createVectorHelper(sample.x, sample.y, sample.z); + + MovingObjectPosition p = player.worldObj + .rayTraceBlocks(pos, end, !Config.travelStaffBlinkThroughClearBlocksEnabled); + if (p != null) { + teleDistance = VecmathUtil.distance(eye, new Vector3d(p.blockX + 0.5, p.blockY + 0.5, p.blockZ + 0.5)); + break; + } + + pos = end; + currDistance += distance; + } + + Vector3d sample = new Vector3d(look); + sample.scale(Config.teleportStaffMaxBlinkDistance); + sample.add(eye); + Vec3 end = Vec3.createVectorHelper(sample.x, sample.y, sample.z); + MovingObjectPosition p = player.worldObj + .rayTraceBlocks(eye3, end, !Config.travelStaffBlinkThroughClearBlocksEnabled); + if (p != null) { + teleDistance = VecmathUtil.distance(eye, new Vector3d(p.blockX + 0.5, p.blockY + 0.5, p.blockZ + 0.5)); + } + + double distanceIncrement = -2; + int maxIter = Math.min(8, (int) teleDistance / 2); + // Special case: if the targeted block is too close, we'll try to teleport through it. + if (teleDistance < 4) { + distanceIncrement = 0.5; + maxIter = 32; + } + + for (int i = 0; i < maxIter; i++) { + teleDistance += distanceIncrement; + + sample.set(look); + sample.scale(teleDistance); + sample.add(eye); + // we test against our feets location + sample.y -= playerHeight; + + Optional destinationOptional = findNearbyDestination(player, source, sample); + if (destinationOptional.isPresent()) { + return destinationOptional; + } + } + return Optional.empty(); + } + + /** Finds a long-distance travel anchor, or returns empty optional if unsuccessful. */ + public Optional findTravelDestination(EntityPlayer player, TravelSource source) { + double maxDistance = source.getMaxDistanceTravelled(); + double maxMessageDistance = 1.25 * maxDistance; + // Find possible destinations within about 5 degrees. + RowSortedTable possibleDestinations = findBlocksWithinAngle( + player, + travelDestinations.get(player.worldObj.provider.dimensionId), + 0.087, + maxMessageDistance); + + for (Table.Cell cell : possibleDestinations.cellSet()) { + if (cell.getColumnKey() <= maxDistance) { + return Optional.of(cell.getValue()); + } + } + + if (!possibleDestinations.isEmpty()) { + // We found at least one block within maxMessageDistance, but no blocks within maxDistance. + showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange")); + } + + return Optional.empty(); + } + /** Finds a valid destination near the provided vector, or returns empty optional if unsuccessful. */ private Optional findNearbyDestination(EntityPlayer player, TravelSource source, Vector3d sample) { Optional destinationOptional = findValidDestination( diff --git a/src/main/java/crazypants/enderio/teleport/anchor/TileTravelAnchor.java b/src/main/java/crazypants/enderio/teleport/anchor/TileTravelAnchor.java index b8db51a8..f34e2d71 100644 --- a/src/main/java/crazypants/enderio/teleport/anchor/TileTravelAnchor.java +++ b/src/main/java/crazypants/enderio/teleport/anchor/TileTravelAnchor.java @@ -337,6 +337,9 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable public void validate() { super.validate(); if (isTravelSource()) { + // Note: travelDestinations is a SetMultimap, which does not allow duplicate entries. + // So it's okay if this gets called multiple times with the same BlockCoord. + // Though, I think that it's not currently getting called multiple times, anyway. TravelController.instance.travelDestinations.put(worldObj.provider.dimensionId, getLocation()); } }