From d90c7dae1b4c2d3ad7c3d83a5520d0ad4971e401 Mon Sep 17 00:00:00 2001
From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com>
Date: Sat, 13 Apr 2024 09:06:16 -0600
Subject: [PATCH 01/14] Tweak teleport staff controls
---
.../java/crazypants/enderio/config/Config.java | 10 ++++++++++
.../enderio/teleport/ItemTeleportStaff.java | 14 +++++++++++---
.../enderio/teleport/TravelController.java | 9 +++++++--
3 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/src/main/java/crazypants/enderio/config/Config.java b/src/main/java/crazypants/enderio/config/Config.java
index a377ea0f..75c93ee4 100644
--- a/src/main/java/crazypants/enderio/config/Config.java
+++ b/src/main/java/crazypants/enderio/config/Config.java
@@ -174,6 +174,8 @@ public final class Config {
* The distance travelled when no block is found within {@link #teleportStaffMaxBlinkDistance}.
*/
public static int teleportStaffFailedBlinkDistance = 64;
+ /** If true, don't invert the staff of teleportation controls. */
+ public static boolean teleportStaffOriginalControls = false;
public static int enderIoRange = 8;
public static boolean enderIoMeAccessEnabled = true;
@@ -1269,6 +1271,14 @@ 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);
+
enderIoRange = config.get(
sectionEfficiency.name,
"enderIoRange",
diff --git a/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java b/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java
index a0d50c98..4723766c 100644
--- a/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java
+++ b/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java
@@ -2,6 +2,7 @@ package crazypants.enderio.teleport;
import java.util.List;
+import crazypants.enderio.config.Config;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@@ -56,10 +57,17 @@ public class ItemTeleportStaff extends ItemTravelStaff {
@Override
public ItemStack onItemRightClick(ItemStack equipped, World world, EntityPlayer player) {
if (world.isRemote) {
- if (player.isSneaking()) {
- TravelController.instance
+ if (Config.teleportStaffOriginalControls) {
+ if (player.isSneaking()) {
+ TravelController.instance
.activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF);
- } else {
+ } else {
+ TravelController.instance.doTeleport(player);
+ }
+ } else if (
+ player.isSneaking()
+ || !TravelController.instance
+ .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF)) {
TravelController.instance.doTeleport(player);
}
}
diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java
index 866e1449..9c054185 100644
--- a/src/main/java/crazypants/enderio/teleport/TravelController.java
+++ b/src/main/java/crazypants/enderio/teleport/TravelController.java
@@ -358,7 +358,7 @@ public class TravelController {
double distanceIncrement = -2;
// Special case: if the targeted block is too close, we'll try to teleport through it.
- if (teleDistance < 3) {
+ if (teleDistance < 4) {
distanceIncrement = 2;
}
@@ -527,7 +527,7 @@ public class TravelController {
}
onBlockCoord = getActiveTravelBlock(player);
boolean onBlock = onBlockCoord != null;
- showTargets = onBlock || isTravelItemActive(player, false);
+ showTargets = onBlock || (isTravelItemActive(player, false) && !shouldHideTargets(player));
if (showTargets) {
updateSelectedTarget(player);
} else {
@@ -619,6 +619,11 @@ public class TravelController {
return getTravelItemTravelSource(ep, checkInventoryAndBaubles) != null;
}
+ public boolean shouldHideTargets(EntityPlayer ep) {
+ return getTravelItemTravelSource(ep, false) != TravelSource.TELEPORT_STAFF
+ || (!Config.teleportStaffOriginalControls && ep.isSneaking());
+ }
+
/** Returns null if no travel item is in inventory/baubles. */
@Nullable
public TravelSource getTravelItemTravelSource(EntityPlayer ep, boolean checkInventoryAndBaubles) {
From edbd5621c310b613ec2f242b8e4e5954cc696bde Mon Sep 17 00:00:00 2001
From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com>
Date: Sat, 13 Apr 2024 09:10:10 -0600
Subject: [PATCH 02/14] Fix comment
---
src/main/java/crazypants/enderio/config/Config.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/crazypants/enderio/config/Config.java b/src/main/java/crazypants/enderio/config/Config.java
index 75c93ee4..11a22abd 100644
--- a/src/main/java/crazypants/enderio/config/Config.java
+++ b/src/main/java/crazypants/enderio/config/Config.java
@@ -174,7 +174,7 @@ public final class Config {
* The distance travelled when no block is found within {@link #teleportStaffMaxBlinkDistance}.
*/
public static int teleportStaffFailedBlinkDistance = 64;
- /** If true, don't invert the staff of teleportation controls. */
+ /** If true, use the original staff of teleportation controls. */
public static boolean teleportStaffOriginalControls = false;
public static int enderIoRange = 8;
From dd739ba58e21a64a3159dc6132132b075814ee07 Mon Sep 17 00:00:00 2001
From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com>
Date: Sat, 13 Apr 2024 09:11:50 -0600
Subject: [PATCH 03/14] Fix logic
---
.../java/crazypants/enderio/teleport/TravelController.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java
index 9c054185..70c2aad6 100644
--- a/src/main/java/crazypants/enderio/teleport/TravelController.java
+++ b/src/main/java/crazypants/enderio/teleport/TravelController.java
@@ -620,8 +620,8 @@ public class TravelController {
}
public boolean shouldHideTargets(EntityPlayer ep) {
- return getTravelItemTravelSource(ep, false) != TravelSource.TELEPORT_STAFF
- || (!Config.teleportStaffOriginalControls && ep.isSneaking());
+ return getTravelItemTravelSource(ep, false) == TravelSource.TELEPORT_STAFF
+ && !Config.teleportStaffOriginalControls && ep.isSneaking();
}
/** Returns null if no travel item is in inventory/baubles. */
From 3b0025500e33605324801d1c913be039394b70ae Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
<41898282+github-actions[bot]@users.noreply.github.com>
Date: Sat, 13 Apr 2024 17:36:56 +0200
Subject: [PATCH 04/14] spotlessApply (#159)
Co-authored-by: GitHub GTNH Actions <>
---
.../java/crazypants/enderio/config/Config.java | 11 +++++------
.../enderio/teleport/ItemTeleportStaff.java | 14 ++++++--------
.../enderio/teleport/TravelController.java | 3 ++-
3 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/src/main/java/crazypants/enderio/config/Config.java b/src/main/java/crazypants/enderio/config/Config.java
index 11a22abd..7aeecaa1 100644
--- a/src/main/java/crazypants/enderio/config/Config.java
+++ b/src/main/java/crazypants/enderio/config/Config.java
@@ -1271,12 +1271,11 @@ 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.")
+ 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);
enderIoRange = config.get(
diff --git a/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java b/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java
index 4723766c..1ac92c52 100644
--- a/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java
+++ b/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java
@@ -2,7 +2,6 @@ package crazypants.enderio.teleport;
import java.util.List;
-import crazypants.enderio.config.Config;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@@ -16,6 +15,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.EnderIO;
import crazypants.enderio.ModObject;
import crazypants.enderio.api.teleport.TravelSource;
+import crazypants.enderio.config.Config;
import crazypants.enderio.machine.power.PowerDisplayUtil;
public class ItemTeleportStaff extends ItemTravelStaff {
@@ -60,16 +60,14 @@ public class ItemTeleportStaff extends ItemTravelStaff {
if (Config.teleportStaffOriginalControls) {
if (player.isSneaking()) {
TravelController.instance
- .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF);
+ .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF);
} else {
TravelController.instance.doTeleport(player);
}
- } else if (
- player.isSneaking()
- || !TravelController.instance
- .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF)) {
- TravelController.instance.doTeleport(player);
- }
+ } else if (player.isSneaking() || !TravelController.instance
+ .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF)) {
+ TravelController.instance.doTeleport(player);
+ }
}
player.swingItem();
return equipped;
diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java
index 70c2aad6..81fb9462 100644
--- a/src/main/java/crazypants/enderio/teleport/TravelController.java
+++ b/src/main/java/crazypants/enderio/teleport/TravelController.java
@@ -621,7 +621,8 @@ public class TravelController {
public boolean shouldHideTargets(EntityPlayer ep) {
return getTravelItemTravelSource(ep, false) == TravelSource.TELEPORT_STAFF
- && !Config.teleportStaffOriginalControls && ep.isSneaking();
+ && !Config.teleportStaffOriginalControls
+ && ep.isSneaking();
}
/** Returns null if no travel item is in inventory/baubles. */
From 9422337282c00f754882cbe1a822828ca9a6af8f Mon Sep 17 00:00:00 2001
From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com>
Date: Sat, 13 Apr 2024 14:44:43 -0600
Subject: [PATCH 05/14] Add configs for teleport staff actions
---
.../crazypants/enderio/config/Config.java | 58 +++++++++++++++++++
.../enderio/teleport/ItemTeleportStaff.java | 31 ++++++++--
.../enderio/teleport/TravelController.java | 10 +++-
3 files changed, 92 insertions(+), 7 deletions(-)
diff --git a/src/main/java/crazypants/enderio/config/Config.java b/src/main/java/crazypants/enderio/config/Config.java
index 7aeecaa1..eb8c2c4d 100644
--- a/src/main/java/crazypants/enderio/config/Config.java
+++ b/src/main/java/crazypants/enderio/config/Config.java
@@ -177,6 +177,40 @@ public final class Config {
/** If true, use the original staff of teleportation controls. */
public static boolean teleportStaffOriginalControls = false;
+ /**
+ * Sets the teleport staff right-click action.
+ *
+ *
+ * Values:
+ *
+ * - 0: Do nothing
+ *
- 1: Teleport to look
+ *
- 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;
+
+ /**
+ * Sets the teleport staff sneak right-click action.
+ *
+ *
+ * Values:
+ *
+ * - 0: Do nothing
+ *
- 1: Teleport to look (default)
+ *
- 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;
+
public static int enderIoRange = 8;
public static boolean enderIoMeAccessEnabled = true;
@@ -1278,6 +1312,30 @@ public final class Config {
"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,
+ "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.")
+ .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.")
+ .getInt(teleportStaffSneakAction);
+
enderIoRange = config.get(
sectionEfficiency.name,
"enderIoRange",
diff --git a/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java b/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java
index 1ac92c52..6315d244 100644
--- a/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java
+++ b/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java
@@ -64,12 +64,35 @@ public class ItemTeleportStaff extends ItemTravelStaff {
} else {
TravelController.instance.doTeleport(player);
}
- } else if (player.isSneaking() || !TravelController.instance
- .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF)) {
+ player.swingItem();
+ } else {
+ 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);
+ player.swingItem();
+ break;
+
+ case 3:
+ if (!TravelController.instance
+ .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF)) {
+ TravelController.instance.doTeleport(player);
+ }
+ player.swingItem();
+ break;
+ }
+ }
}
- player.swingItem();
return equipped;
}
diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java
index 81fb9462..ce34682f 100644
--- a/src/main/java/crazypants/enderio/teleport/TravelController.java
+++ b/src/main/java/crazypants/enderio/teleport/TravelController.java
@@ -620,9 +620,13 @@ public class TravelController {
}
public boolean shouldHideTargets(EntityPlayer ep) {
- return getTravelItemTravelSource(ep, false) == TravelSource.TELEPORT_STAFF
- && !Config.teleportStaffOriginalControls
- && ep.isSneaking();
+ if (getTravelItemTravelSource(ep, false) != TravelSource.TELEPORT_STAFF
+ || Config.teleportStaffOriginalControls) {
+ return false;
+ }
+
+ int action = ep.isSneaking() ? Config.teleportStaffSneakAction : Config.teleportStaffAction;
+ return action < 2;
}
/** Returns null if no travel item is in inventory/baubles. */
From 745b6ed5280a182e119b85b86fb62d2981ccf871 Mon Sep 17 00:00:00 2001
From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com>
Date: Sat, 13 Apr 2024 14:46:20 -0600
Subject: [PATCH 06/14] Various TP fixes
* Allow TP to unloaded anchor
* Improve TP through wall by checking every 0.5 instead of 2 distance
* Fix blink placing player one block too high
* Fix anchor being incorrectly selected sometimes by constraining to visual angle
---
.../enderio/teleport/TravelController.java | 168 ++++++++++--------
.../teleport/anchor/TileTravelAnchor.java | 6 -
.../packet/PacketLongDistanceTravelEvent.java | 7 +-
.../teleport/packet/PacketTravelEvent.java | 2 +-
4 files changed, 95 insertions(+), 88 deletions(-)
diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java
index ce34682f..6b14f79f 100644
--- a/src/main/java/crazypants/enderio/teleport/TravelController.java
+++ b/src/main/java/crazypants/enderio/teleport/TravelController.java
@@ -3,10 +3,8 @@ package crazypants.enderio.teleport;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
import java.util.Random;
-import java.util.TreeMap;
import javax.annotation.Nullable;
@@ -41,7 +39,10 @@ import com.enderio.core.common.vecmath.VecmathUtil;
import com.enderio.core.common.vecmath.Vector2d;
import com.enderio.core.common.vecmath.Vector3d;
import com.google.common.collect.MultimapBuilder;
+import com.google.common.collect.RowSortedTable;
import com.google.common.collect.SetMultimap;
+import com.google.common.collect.Table;
+import com.google.common.collect.TreeBasedTable;
import com.gtnewhorizon.gtnhlib.GTNHLib;
import cpw.mods.fml.common.Loader;
@@ -132,8 +133,14 @@ public class TravelController {
BlockCoord target = new BlockCoord(x, y, z);
double dist = getDistanceSquared(toTp, target);
+ // Due to a quirk of how the teleport staff works, it can try to blink and do a long-distance
+ // teleport at the same time. If both succeed, we can end up seeing an overly long blink, so
+ // allow it.
+ double maxDist = source == TravelSource.TELEPORT_STAFF_BLINK
+ ? TravelSource.TELEPORT_STAFF.getMaxDistanceTravelledSq()
+ : source.getMaxDistanceTravelledSq();
// allow 15% overshoot to account for rounding
- if (dist * 100 > source.getMaxDistanceTravelledSq() * 115) return "dist check fail";
+ if (dist * 100 > maxDist * 115) return "dist check fail";
// allow 4 blocks of c/s player pos desync
if (getPower(toTp, source, target, -4F) > powerUse) return "power use too little";
ItemStack equippedItem = toTp.getCurrentEquippedItem();
@@ -148,8 +155,9 @@ public class TravelController {
// target must be a valid selectedCoord
// selectedCoord can either be a block right above/below when the player is on anchor...
if (on.x == x && on.z == z) return null;
- // or another anchor
- TileEntity maybeAnchor = target.getTileEntity(toTp.worldObj);
+ // or another anchor. We need to look one block below because TP goes above the anchor.
+ BlockCoord belowTarget = target.getLocation(ForgeDirection.DOWN);
+ TileEntity maybeAnchor = belowTarget.getTileEntity(toTp.worldObj);
if (!(maybeAnchor instanceof ITravelAccessable)) return "not anchor";
ITravelAccessable anchor = (ITravelAccessable) maybeAnchor;
if (!isValidTarget(toTp, target, TravelSource.BLOCK)) {
@@ -359,10 +367,10 @@ public class TravelController {
double distanceIncrement = -2;
// Special case: if the targeted block is too close, we'll try to teleport through it.
if (teleDistance < 4) {
- distanceIncrement = 2;
+ distanceIncrement = 0.5;
}
- for (int i = 0; i < 8; i++) {
+ for (int i = 0; i < 32; i++) {
teleDistance += distanceIncrement;
sample.set(look);
@@ -380,40 +388,27 @@ public class TravelController {
/** Returns empty optional if no travel destination was found. */
public Optional findTravelDestination(EntityPlayer player, TravelSource source) {
- Vector3d eye = Util.getEyePositionEio(player);
- Vector3d look = Util.getLookVecEio(player);
+ 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);
- // Map of distance to coordinate for eligible travel destinations (within angle).
- Map distanceMap = new TreeMap<>();
- // 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.get(player.worldObj.provider.dimensionId)) {
- 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 > maxMessageDistance) {
- continue;
- }
- block.normalize();
-
- double angle = Math.acos(look.dot(block));
- // Roughly 5 degrees
- if (angle < 0.087) {
- if (distance > source.getMaxDistanceTravelled()) {
- displayOutOfRangeMessage = true;
- } else {
- distanceMap.put(distance, p);
- }
+ for (Table.Cell cell : possibleDestinations.cellSet()) {
+ if (cell.getColumnKey() <= maxDistance) {
+ return Optional.of(cell.getValue());
}
}
- if (displayOutOfRangeMessage && distanceMap.isEmpty()) {
+ if (!possibleDestinations.isEmpty()) {
+ // We found at least one block within maxMessageDistance, but no blocks within maxDistance.
showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
}
- return distanceMap.values().stream().findFirst();
+ return Optional.empty();
}
private boolean isBlackListedBlock(EntityPlayer player, MovingObjectPosition pos, Block hitBlock) {
@@ -729,8 +724,11 @@ public class TravelController {
public boolean travelToLocation(EntityPlayer player, TravelSource source, BlockCoord coord,
boolean conserveMomentum) {
+ // Are we trying to travel to a block (anchor or telepad)?
+ boolean travelToBlock = source != TravelSource.STAFF_BLINK && source != TravelSource.TELEPORT_STAFF_BLINK;
- if (source != TravelSource.STAFF_BLINK && source != TravelSource.TELEPORT_STAFF_BLINK) {
+ BlockCoord destination = coord;
+ if (travelToBlock) {
TileEntity te = player.worldObj.getTileEntity(coord.x, coord.y, coord.z);
if (te instanceof ITravelAccessable) {
ITravelAccessable ta = (ITravelAccessable) te;
@@ -739,27 +737,30 @@ public class TravelController {
return false;
}
}
+
+ // We actually want to go on top of the block.
+ destination = coord.getLocation(ForgeDirection.UP);
}
int requiredPower = 0;
- requiredPower = getRequiredPower(player, source, coord);
+ requiredPower = getRequiredPower(player, source, destination);
if (requiredPower < 0) {
return false;
}
- if (!isInRangeTarget(player, coord, source.getMaxDistanceTravelledSq())) {
- if (source != TravelSource.STAFF_BLINK && source != TravelSource.TELEPORT_STAFF_BLINK) {
+ if (!isInRangeTarget(player, destination, source.getMaxDistanceTravelledSq())) {
+ if (travelToBlock) {
showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
}
return false;
}
- if (!isValidTarget(player, coord, source)) {
- if (source != TravelSource.STAFF_BLINK && source != TravelSource.TELEPORT_STAFF_BLINK) {
+ if (!isValidTarget(player, destination, source)) {
+ if (travelToBlock) {
showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.invalidTarget"));
}
return false;
}
- if (doClientTeleport(player, coord, source, requiredPower, conserveMomentum)) {
+ if (doClientTeleport(player, destination, source, requiredPower, conserveMomentum)) {
for (int i = 0; i < 6; ++i) {
player.worldObj.spawnParticle(
"portal",
@@ -824,10 +825,6 @@ public class TravelController {
}
World w = player.worldObj;
BlockCoord baseLoc = bc;
- if (source != TravelSource.STAFF_BLINK && source != TravelSource.TELEPORT_STAFF_BLINK) {
- // targeting a block so go one up
- baseLoc = bc.getLocation(ForgeDirection.UP);
- }
return canTeleportTo(player, source, baseLoc, w)
&& canTeleportTo(player, source, baseLoc.getLocation(ForgeDirection.UP), w);
@@ -914,6 +911,7 @@ public class TravelController {
if (selectedBlock instanceof ITravelAccessable) {
ITravelAccessable travelBlock = (ITravelAccessable) selectedBlock;
BlockCoord targetBlock = new BlockCoord(currentBlock.x, y, currentBlock.z);
+ BlockCoord destination = targetBlock.getLocation(ForgeDirection.UP);
if (Config.travelAnchorSkipWarning) {
if (travelBlock.getRequiresPassword(player)) {
@@ -924,55 +922,67 @@ public class TravelController {
&& !travelBlock.canUiBeAccessed(player)) {
showMessage(player, new ChatComponentTranslation("enderio.gui.travelAccessable.skipPrivate"));
}
- if (!isValidTarget(player, targetBlock, TravelSource.BLOCK)) {
+ if (!isValidTarget(player, destination, TravelSource.BLOCK)) {
showMessage(player, new ChatComponentTranslation("enderio.gui.travelAccessable.skipObstructed"));
}
}
- if (travelBlock.canBlockBeAccessed(player) && isValidTarget(player, targetBlock, TravelSource.BLOCK)) {
+ if (travelBlock.canBlockBeAccessed(player) && isValidTarget(player, destination, TravelSource.BLOCK)) {
return targetBlock;
}
}
return null;
}
+ /**
+ * Returns a row-sorted table with angle in radians as the row, distance as the column, and block coordinate as the
+ * value, holding all blocks which lie within the specified viewing angle and distance.
+ *
+ *
+ * The table is sorted by angle ascending, so the smallest angle will be first.
+ *
+ * @param player The player to search from.
+ * @param blocks The blocks to search through.
+ * @param maxAngle The maximum allowed angle, in radians.
+ * @param maxDistance The maximum allowed distance.
+ */
+ private RowSortedTable findBlocksWithinAngle(EntityPlayer player,
+ Iterable blocks, double maxAngle, double maxDistance) {
+ Vector3d eye = Util.getEyePositionEio(player);
+ Vector3d look = Util.getLookVecEio(player);
+
+ // Table of angle, distance, and block coordinate holding found blocks.
+ // Angle is the row, so this table will automatically be sorted by angle ascending.
+ RowSortedTable foundBlocks = TreeBasedTable.create();
+
+ for (BlockCoord p : blocks) {
+ 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 > maxDistance) {
+ continue;
+ }
+ block.normalize();
+
+ double angle = Math.acos(look.dot(block));
+ if (angle <= maxAngle) {
+ foundBlocks.put(angle, distance, p);
+ }
+ }
+
+ return foundBlocks;
+ }
+
@SideOnly(Side.CLIENT)
private void updateSelectedTarget(EntityPlayer player) {
- selectedCoord = null;
if (candidates.isEmpty()) {
+ selectedCoord = null;
return;
}
- double closestDistance = Double.MAX_VALUE;
- for (BlockCoord bc : candidates.keySet()) {
- if (!bc.equals(onBlockCoord)) {
-
- double d = addRatio(bc);
- if (d < closestDistance) {
- selectedCoord = bc;
- closestDistance = d;
- }
- }
- }
-
- if (selectedCoord != null) {
-
- Vector3d blockCenter = new Vector3d(selectedCoord.x + 0.5, selectedCoord.y + 0.5, selectedCoord.z + 0.5);
- Vector2d blockCenterPixel = currentView.getScreenPoint(blockCenter);
-
- Vector2d screenMidPixel = new Vector2d(
- Minecraft.getMinecraft().displayWidth,
- Minecraft.getMinecraft().displayHeight);
- screenMidPixel.scale(0.5);
-
- double pixDist = blockCenterPixel.distance(screenMidPixel);
- double rat = pixDist / Minecraft.getMinecraft().displayHeight;
- if (rat != rat) {
- rat = 0;
- }
- if (rat > 0.07) {
- selectedCoord = null;
- }
- }
+ // Find the nearest travel anchor within roughly 10 degrees.
+ Optional selectedBlock = findBlocksWithinAngle(player, candidates.keySet(), 0.175, Double.MAX_VALUE)
+ .values().stream().findFirst();
+ selectedCoord = selectedBlock.orElse(null);
}
@SideOnly(Side.CLIENT)
diff --git a/src/main/java/crazypants/enderio/teleport/anchor/TileTravelAnchor.java b/src/main/java/crazypants/enderio/teleport/anchor/TileTravelAnchor.java
index 6cc1e8f1..b8db51a8 100644
--- a/src/main/java/crazypants/enderio/teleport/anchor/TileTravelAnchor.java
+++ b/src/main/java/crazypants/enderio/teleport/anchor/TileTravelAnchor.java
@@ -346,10 +346,4 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
super.invalidate();
TravelController.instance.travelDestinations.remove(worldObj.provider.dimensionId, getLocation());
}
-
- @Override
- public void onChunkUnload() {
- super.onChunkUnload();
- TravelController.instance.travelDestinations.remove(worldObj.provider.dimensionId, getLocation());
- }
}
diff --git a/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java b/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
index 0beb1a9e..7e72a6d7 100644
--- a/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
+++ b/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
@@ -8,6 +8,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.S12PacketEntityVelocity;
import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.common.util.ForgeDirection;
import com.enderio.core.common.util.BlockCoord;
import com.enderio.core.common.util.Util;
@@ -105,7 +106,9 @@ public class PacketLongDistanceTravelEvent
if (!travelDestination.isPresent()) {
return false;
}
- BlockCoord destination = travelDestination.get();
+
+ // We're teleporting to a block, so go one above.
+ BlockCoord destination = travelDestination.get().getLocation(ForgeDirection.UP);
int x = destination.x;
int y = destination.y;
int z = destination.z;
@@ -135,7 +138,7 @@ public class PacketLongDistanceTravelEvent
toTp.playSound(source.sound, 1.0F, 1.0F);
if (player != null) {
- player.setPositionAndUpdate(x + 0.5, y + 1.1, z + 0.5);
+ player.setPositionAndUpdate(x + 0.5, y + 0.1, z + 0.5);
} else {
toTp.setPosition(x, y, z);
}
diff --git a/src/main/java/crazypants/enderio/teleport/packet/PacketTravelEvent.java b/src/main/java/crazypants/enderio/teleport/packet/PacketTravelEvent.java
index cb31e488..82230b17 100644
--- a/src/main/java/crazypants/enderio/teleport/packet/PacketTravelEvent.java
+++ b/src/main/java/crazypants/enderio/teleport/packet/PacketTravelEvent.java
@@ -118,7 +118,7 @@ public class PacketTravelEvent implements IMessage, IMessageHandler
Date: Sat, 13 Apr 2024 15:35:08 -0600
Subject: [PATCH 07/14] Add server-side handling for two-in-one teleport action
---
.../enderio/teleport/ItemTeleportStaff.java | 8 ++--
.../enderio/teleport/TravelController.java | 37 +++++++++----------
.../packet/PacketLongDistanceTravelEvent.java | 21 ++++++++---
3 files changed, 37 insertions(+), 29 deletions(-)
diff --git a/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java b/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java
index 6315d244..aca83f03 100644
--- a/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java
+++ b/src/main/java/crazypants/enderio/teleport/ItemTeleportStaff.java
@@ -79,15 +79,13 @@ public class ItemTeleportStaff extends ItemTravelStaff {
case 2:
TravelController.instance
- .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF);
+ .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF);
player.swingItem();
break;
case 3:
- if (!TravelController.instance
- .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF)) {
- TravelController.instance.doTeleport(player);
- }
+ TravelController.instance
+ .activateTravelAccessable(equipped, world, player, TravelSource.TELEPORT_STAFF, true);
player.swingItem();
break;
}
diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java
index 6b14f79f..25a0fab6 100644
--- a/src/main/java/crazypants/enderio/teleport/TravelController.java
+++ b/src/main/java/crazypants/enderio/teleport/TravelController.java
@@ -133,14 +133,8 @@ public class TravelController {
BlockCoord target = new BlockCoord(x, y, z);
double dist = getDistanceSquared(toTp, target);
- // Due to a quirk of how the teleport staff works, it can try to blink and do a long-distance
- // teleport at the same time. If both succeed, we can end up seeing an overly long blink, so
- // allow it.
- double maxDist = source == TravelSource.TELEPORT_STAFF_BLINK
- ? TravelSource.TELEPORT_STAFF.getMaxDistanceTravelledSq()
- : source.getMaxDistanceTravelledSq();
// allow 15% overshoot to account for rounding
- if (dist * 100 > maxDist * 115) return "dist check fail";
+ if (dist * 100 > source.getMaxDistanceTravelledSq() * 115) return "dist check fail";
// allow 4 blocks of c/s player pos desync
if (getPower(toTp, source, target, -4F) > powerUse) return "power use too little";
ItemStack equippedItem = toTp.getCurrentEquippedItem();
@@ -198,8 +192,13 @@ public class TravelController {
}
public boolean activateTravelAccessable(ItemStack equipped, World world, EntityPlayer player, TravelSource source) {
+ return activateTravelAccessable(equipped, world, player, source, false);
+ }
+
+ public boolean activateTravelAccessable(ItemStack equipped, World world, EntityPlayer player, TravelSource source,
+ boolean alsoDoTeleport) {
if (!hasTarget()) {
- PacketLongDistanceTravelEvent p = new PacketLongDistanceTravelEvent(player, false, source);
+ PacketLongDistanceTravelEvent p = new PacketLongDistanceTravelEvent(player, false, source, alsoDoTeleport);
PacketHandler.INSTANCE.sendToServer(p);
// We have no way of knowing if it will succeed, so just return false.
return false;
@@ -775,6 +774,17 @@ public class TravelController {
return true;
}
+ public boolean isValidTarget(EntityPlayer player, BlockCoord bc, TravelSource source) {
+ if (bc == null) {
+ return false;
+ }
+ World w = player.worldObj;
+ BlockCoord baseLoc = bc;
+
+ return canTeleportTo(player, source, baseLoc, w)
+ && canTeleportTo(player, source, baseLoc.getLocation(ForgeDirection.UP), w);
+ }
+
public int getRequiredPower(EntityPlayer player, TravelSource source, BlockCoord coord) {
if (!isTravelItemActive(player, true)) {
return 0;
@@ -819,17 +829,6 @@ public class TravelController {
return Math.sqrt(getDistanceSquared(player, coord));
}
- private boolean isValidTarget(EntityPlayer player, BlockCoord bc, TravelSource source) {
- if (bc == null) {
- return false;
- }
- World w = player.worldObj;
- BlockCoord baseLoc = bc;
-
- return canTeleportTo(player, source, baseLoc, w)
- && canTeleportTo(player, source, baseLoc.getLocation(ForgeDirection.UP), w);
- }
-
private boolean canTeleportTo(EntityPlayer player, TravelSource source, BlockCoord bc, World w) {
if (bc.y < 1) {
return false;
diff --git a/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java b/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
index 7e72a6d7..5c9ea5f4 100644
--- a/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
+++ b/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
@@ -31,13 +31,16 @@ public class PacketLongDistanceTravelEvent
boolean conserveMotion;
int entityId;
int source;
+ boolean alsoDoTeleport;
public PacketLongDistanceTravelEvent() {}
- public PacketLongDistanceTravelEvent(Entity entity, boolean conserveMotion, TravelSource source) {
+ public PacketLongDistanceTravelEvent(Entity entity, boolean conserveMotion, TravelSource source,
+ boolean alsoDoTeleport) {
this.conserveMotion = conserveMotion;
this.entityId = entity instanceof EntityPlayer ? -1 : entity.getEntityId();
this.source = source.ordinal();
+ this.alsoDoTeleport = alsoDoTeleport;
}
@Override
@@ -45,6 +48,7 @@ public class PacketLongDistanceTravelEvent
buf.writeBoolean(conserveMotion);
buf.writeInt(entityId);
buf.writeInt(source);
+ buf.writeBoolean(alsoDoTeleport);
}
@Override
@@ -52,6 +56,7 @@ public class PacketLongDistanceTravelEvent
conserveMotion = buf.readBoolean();
entityId = buf.readInt();
source = buf.readInt();
+ alsoDoTeleport = buf.readBoolean();
}
@Override
@@ -70,7 +75,7 @@ public class PacketLongDistanceTravelEvent
TravelSource source = TravelSource.values()[message.source];
- if (!validate(toTp, source)) {
+ if (!validate(toTp, source, message.alsoDoTeleport)) {
Log.LOGGER.warn(
Log.securityMarker,
"Player {} tried to tp without valid prereq.",
@@ -78,15 +83,17 @@ public class PacketLongDistanceTravelEvent
return null;
}
- doServerTeleport(toTp, message.conserveMotion, source);
+ doServerTeleport(toTp, message.conserveMotion, source, message.alsoDoTeleport);
return null;
}
- private static boolean validate(EntityPlayerMP toTp, TravelSource source) {
+ private static boolean validate(EntityPlayerMP toTp, TravelSource source, boolean alsoDoTeleport) {
ItemStack equippedItem = toTp.getCurrentEquippedItem();
switch (source) {
case STAFF:
+ // Not allowed to do teleport staff teleport with regular staff.
+ if (alsoDoTeleport) return false;
return equippedItem != null && equippedItem.getItem() instanceof IItemOfTravel
&& ((IItemOfTravel) equippedItem.getItem()).isActive(toTp, equippedItem);
case TELEPORT_STAFF:
@@ -100,10 +107,14 @@ public class PacketLongDistanceTravelEvent
}
}
- public static boolean doServerTeleport(Entity toTp, boolean conserveMotion, TravelSource source) {
+ public static boolean doServerTeleport(Entity toTp, boolean conserveMotion, TravelSource source,
+ boolean alsoDoTeleport) {
EntityPlayer player = toTp instanceof EntityPlayer ? (EntityPlayer) toTp : null;
Optional travelDestination = TravelController.instance.findTravelDestination(player, source);
if (!travelDestination.isPresent()) {
+ if (alsoDoTeleport) {
+ return TravelController.instance.doTeleport(player);
+ }
return false;
}
From 1b2c38cf0a8a44b45804e5f6958584d6ab9ce606 Mon Sep 17 00:00:00 2001
From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com>
Date: Sat, 13 Apr 2024 15:35:26 -0600
Subject: [PATCH 08/14] Clear stored anchors on world load
---
.../crazypants/enderio/teleport/TravelController.java | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java
index 25a0fab6..15c5c1aa 100644
--- a/src/main/java/crazypants/enderio/teleport/TravelController.java
+++ b/src/main/java/crazypants/enderio/teleport/TravelController.java
@@ -30,6 +30,7 @@ import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
+import net.minecraftforge.event.world.WorldEvent;
import com.enderio.core.common.util.BlockCoord;
import com.enderio.core.common.util.Util;
@@ -486,6 +487,13 @@ public class TravelController {
.getBlock(selectedCoord.x, selectedCoord.y, selectedCoord.z) == EnderIO.blockEnderIo;
}
+ @SubscribeEvent
+ public void onWorldLoad(WorldEvent.Load e) {
+ if (!e.world.isRemote) {
+ travelDestinations.removeAll(e.world.provider.dimensionId);
+ }
+ }
+
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onRender(RenderWorldLastEvent event) {
From b0f7c8600ad861e724eecc8fae87826e0ff4b436 Mon Sep 17 00:00:00 2001
From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com>
Date: Sat, 13 Apr 2024 15:35:40 -0600
Subject: [PATCH 09/14] Check for obstructed anchor on long-distance teleport
---
.../teleport/packet/PacketLongDistanceTravelEvent.java | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java b/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
index 5c9ea5f4..be20d173 100644
--- a/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
+++ b/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
@@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.S12PacketEntityVelocity;
+import net.minecraft.util.ChatComponentTranslation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
@@ -120,6 +121,12 @@ public class PacketLongDistanceTravelEvent
// We're teleporting to a block, so go one above.
BlockCoord destination = travelDestination.get().getLocation(ForgeDirection.UP);
+ if (!TravelController.instance.isValidTarget(player, destination, source)) {
+ TravelController
+ .showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.invalidTarget"));
+ return false;
+ }
+
int x = destination.x;
int y = destination.y;
int z = destination.z;
From 5bd58bd981195bf6cf41a1b41f9e52e15b9a22a4 Mon Sep 17 00:00:00 2001
From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com>
Date: Sat, 13 Apr 2024 16:14:25 -0600
Subject: [PATCH 10/14] Check anchor accessibility and require `player != null`
---
.../packet/PacketLongDistanceTravelEvent.java | 65 +++++++++++--------
1 file changed, 38 insertions(+), 27 deletions(-)
diff --git a/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java b/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
index be20d173..f4054a35 100644
--- a/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
+++ b/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
@@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.S12PacketEntityVelocity;
+import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
@@ -20,6 +21,7 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import crazypants.enderio.Log;
import crazypants.enderio.api.teleport.IItemOfTravel;
+import crazypants.enderio.api.teleport.ITravelAccessable;
import crazypants.enderio.api.teleport.TeleportEntityEvent;
import crazypants.enderio.api.teleport.TravelSource;
import crazypants.enderio.teleport.ItemTeleportStaff;
@@ -110,7 +112,11 @@ public class PacketLongDistanceTravelEvent
public static boolean doServerTeleport(Entity toTp, boolean conserveMotion, TravelSource source,
boolean alsoDoTeleport) {
- EntityPlayer player = toTp instanceof EntityPlayer ? (EntityPlayer) toTp : null;
+ if (!(toTp instanceof EntityPlayer)) {
+ return false;
+ }
+ EntityPlayer player = (EntityPlayer) toTp;
+
Optional travelDestination = TravelController.instance.findTravelDestination(player, source);
if (!travelDestination.isPresent()) {
if (alsoDoTeleport) {
@@ -119,8 +125,19 @@ public class PacketLongDistanceTravelEvent
return false;
}
+ BlockCoord targetBlock = travelDestination.get();
+ TileEntity te = player.worldObj.getTileEntity(targetBlock.x, targetBlock.y, targetBlock.z);
+ if (te instanceof ITravelAccessable) {
+ ITravelAccessable ta = (ITravelAccessable) te;
+ if (!ta.canBlockBeAccessed(player)) {
+ TravelController
+ .showMessage(player, new ChatComponentTranslation("enderio.gui.travelAccessable.unauthorised"));
+ return false;
+ }
+ }
+
// We're teleporting to a block, so go one above.
- BlockCoord destination = travelDestination.get().getLocation(ForgeDirection.UP);
+ BlockCoord destination = targetBlock.getLocation(ForgeDirection.UP);
if (!TravelController.instance.isValidTarget(player, destination, source)) {
TravelController
.showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.invalidTarget"));
@@ -134,7 +151,7 @@ public class PacketLongDistanceTravelEvent
if (powerUse < 0) {
return false;
}
- if (player != null && player.getCurrentEquippedItem() != null
+ if (player.getCurrentEquippedItem() != null
&& player.getCurrentEquippedItem().getItem() instanceof IItemOfTravel) {
int used = ((IItemOfTravel) player.getCurrentEquippedItem().getItem())
.canExtractInternal(player.getCurrentEquippedItem(), powerUse);
@@ -155,32 +172,26 @@ public class PacketLongDistanceTravelEvent
toTp.playSound(source.sound, 1.0F, 1.0F);
- if (player != null) {
- player.setPositionAndUpdate(x + 0.5, y + 0.1, z + 0.5);
- } else {
- toTp.setPosition(x, y, z);
+ player.setPositionAndUpdate(x + 0.5, y + 0.1, z + 0.5);
+
+ player.worldObj.playSoundEffect(x, y, z, source.sound, 1.0F, 1.0F);
+ player.fallDistance = 0;
+
+ if (conserveMotion) {
+ Vector3d velocityVex = Util.getLookVecEio(player);
+ S12PacketEntityVelocity p = new S12PacketEntityVelocity(
+ toTp.getEntityId(),
+ velocityVex.x,
+ velocityVex.y,
+ velocityVex.z);
+ ((EntityPlayerMP) player).playerNetServerHandler.sendPacket(p);
}
- toTp.worldObj.playSoundEffect(x, y, z, source.sound, 1.0F, 1.0F);
- toTp.fallDistance = 0;
-
- if (player != null) {
- if (conserveMotion) {
- Vector3d velocityVex = Util.getLookVecEio(player);
- S12PacketEntityVelocity p = new S12PacketEntityVelocity(
- toTp.getEntityId(),
- velocityVex.x,
- velocityVex.y,
- velocityVex.z);
- ((EntityPlayerMP) player).playerNetServerHandler.sendPacket(p);
- }
-
- if (powerUse > 0 && player.getCurrentEquippedItem() != null
- && player.getCurrentEquippedItem().getItem() instanceof IItemOfTravel) {
- ItemStack item = player.getCurrentEquippedItem().copy();
- ((IItemOfTravel) item.getItem()).extractInternal(item, powerUse);
- toTp.setCurrentItemOrArmor(0, item);
- }
+ if (powerUse > 0 && player.getCurrentEquippedItem() != null
+ && player.getCurrentEquippedItem().getItem() instanceof IItemOfTravel) {
+ ItemStack item = player.getCurrentEquippedItem().copy();
+ ((IItemOfTravel) item.getItem()).extractInternal(item, powerUse);
+ toTp.setCurrentItemOrArmor(0, item);
}
return true;
From f1978a6a15d1856b7d30783904b175f2e4a18cff Mon Sep 17 00:00:00 2001
From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com>
Date: Sat, 13 Apr 2024 16:14:42 -0600
Subject: [PATCH 11/14] Handle server-side `travelToLocation`
---
.../enderio/teleport/TravelController.java | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java
index 15c5c1aa..42ece134 100644
--- a/src/main/java/crazypants/enderio/teleport/TravelController.java
+++ b/src/main/java/crazypants/enderio/teleport/TravelController.java
@@ -767,7 +767,22 @@ public class TravelController {
}
return false;
}
- if (doClientTeleport(player, destination, source, requiredPower, conserveMomentum)) {
+
+ boolean teleportSuccessful;
+ if (player.worldObj.isRemote) {
+ teleportSuccessful = doClientTeleport(player, destination, source, requiredPower, conserveMomentum);
+ } else {
+ teleportSuccessful = PacketTravelEvent.doServerTeleport(
+ player,
+ destination.x,
+ destination.y,
+ destination.z,
+ requiredPower,
+ conserveMomentum,
+ source);
+ }
+
+ if (teleportSuccessful) {
for (int i = 0; i < 6; ++i) {
player.worldObj.spawnParticle(
"portal",
From 58e8bf712c2d6c745e15995d93851876eae2eb72 Mon Sep 17 00:00:00 2001
From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com>
Date: Sun, 14 Apr 2024 13:01:17 -0600
Subject: [PATCH 12/14] Limit backwards teleport check
---
.../java/crazypants/enderio/teleport/TravelController.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java
index 42ece134..2fdf4a1b 100644
--- a/src/main/java/crazypants/enderio/teleport/TravelController.java
+++ b/src/main/java/crazypants/enderio/teleport/TravelController.java
@@ -365,12 +365,14 @@ public class TravelController {
}
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 < 32; i++) {
+ for (int i = 0; i < maxIter; i++) {
teleDistance += distanceIncrement;
sample.set(look);
From b237c6cb4d88b7970f7b1c0deffadbbd9cfeb774 Mon Sep 17 00:00:00 2001
From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com>
Date: Tue, 23 Apr 2024 18:59:06 -0600
Subject: [PATCH 13/14] 2-in-1 TP: find destination client-side
---
.../enderio/teleport/TravelController.java | 179 +++++++++++-------
.../packet/PacketLongDistanceTravelEvent.java | 56 +++++-
2 files changed, 157 insertions(+), 78 deletions(-)
diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java
index 2fdf4a1b..1f590d58 100644
--- a/src/main/java/crazypants/enderio/teleport/TravelController.java
+++ b/src/main/java/crazypants/enderio/teleport/TravelController.java
@@ -199,7 +199,21 @@ public class TravelController {
public boolean activateTravelAccessable(ItemStack equipped, World world, EntityPlayer player, TravelSource source,
boolean alsoDoTeleport) {
if (!hasTarget()) {
- PacketLongDistanceTravelEvent p = new PacketLongDistanceTravelEvent(player, false, source, alsoDoTeleport);
+ PacketLongDistanceTravelEvent p = new PacketLongDistanceTravelEvent(player, false, source);
+ if (alsoDoTeleport) {
+ Optional destinationOptional = findTeleportDestination(player);
+ if (destinationOptional.isPresent()) {
+ BlockCoord destination = destinationOptional.get();
+ p = new PacketLongDistanceTravelEvent(
+ player,
+ false,
+ source,
+ true,
+ destination.x,
+ destination.y,
+ destination.z);
+ }
+ }
PacketHandler.INSTANCE.sendToServer(p);
// We have no way of knowing if it will succeed, so just return false.
return false;
@@ -251,7 +265,10 @@ public class TravelController {
sample.add(eye);
// we test against our feets location
sample.y -= playerHeight;
- if (doBlinkAround(player, source, sample, true)) {
+
+ Optional destinationOptional = findNearbyDestination(player, source, sample);
+ if (destinationOptional.isPresent()
+ && travelToLocation(player, source, destinationOptional.get(), true)) {
return true;
}
}
@@ -288,7 +305,9 @@ public class TravelController {
// we test against our feets location
sample.y -= playerHeight;
- if (doBlinkAround(player, source, sample, false)) {
+ Optional destinationOptional = findNearbyDestination(player, source, sample);
+ if (destinationOptional.isPresent()
+ && travelToLocation(player, source, destinationOptional.get(), false)) {
return true;
}
teleDistance++;
@@ -304,7 +323,9 @@ public class TravelController {
// we test against our feets location
sample.y -= playerHeight;
- if (doBlinkAround(player, source, sample, false)) {
+ Optional destinationOptional = findNearbyDestination(player, source, sample);
+ if (destinationOptional.isPresent()
+ && travelToLocation(player, source, destinationOptional.get(), false)) {
return true;
}
sampleDistance--;
@@ -316,6 +337,15 @@ public class TravelController {
/** This is the teleport staff super-teleport. */
public boolean doTeleport(EntityPlayer player) {
+ Optional destinationOptional = findTeleportDestination(player);
+ if (destinationOptional.isPresent()) {
+ return travelToLocation(player, TravelSource.TELEPORT_STAFF_BLINK, destinationOptional.get(), true);
+ }
+ 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);
@@ -381,14 +411,15 @@ public class TravelController {
// we test against our feets location
sample.y -= playerHeight;
- if (doBlinkAround(player, source, sample, false)) {
- return true;
+ Optional destinationOptional = findNearbyDestination(player, source, sample);
+ if (destinationOptional.isPresent()) {
+ return destinationOptional;
}
}
- return false;
+ return Optional.empty();
}
- /** Returns empty optional if no travel destination was found. */
+ /** 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;
@@ -423,36 +454,6 @@ public class TravelController {
|| !Config.travelStaffBlinkThroughUnbreakableBlocksEnabled);
}
- private boolean doBlinkAround(EntityPlayer player, TravelSource source, Vector3d sample, boolean conserveMomentum) {
- if (travelToLocation(
- player,
- source,
- new BlockCoord((int) Math.floor(sample.x), (int) Math.floor(sample.y), (int) Math.floor(sample.z)),
- conserveMomentum)) {
- return true;
- }
- if (travelToLocation(
- player,
- source,
- new BlockCoord((int) Math.floor(sample.x), (int) Math.floor(sample.y) + 1, (int) Math.floor(sample.z)),
- conserveMomentum)) {
- return true;
- }
- if (!Config.travelStaffSearchOptimize) {
- if (travelToLocation(
- player,
- source,
- new BlockCoord(
- (int) Math.floor(sample.x),
- (int) Math.floor(sample.y) - 1,
- (int) Math.floor(sample.z)),
- conserveMomentum)) {
- return true;
- }
- }
- return false;
- }
-
public boolean showTargets() {
return showTargets && selectionEnabled;
}
@@ -727,12 +728,47 @@ public class TravelController {
return travelItemSlot;
}
- public boolean travelToSelectedTarget(EntityPlayer player, TravelSource source, boolean conserveMomentum) {
- return travelToLocation(player, source, selectedCoord, conserveMomentum);
+ /** 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(
+ player,
+ source,
+ new BlockCoord((int) Math.floor(sample.x), (int) Math.floor(sample.y), (int) Math.floor(sample.z)));
+ if (destinationOptional.isPresent()) {
+ return destinationOptional;
+ }
+
+ destinationOptional = findValidDestination(
+ player,
+ source,
+ new BlockCoord((int) Math.floor(sample.x), (int) Math.floor(sample.y) + 1, (int) Math.floor(sample.z)));
+ if (destinationOptional.isPresent()) {
+ return destinationOptional;
+ }
+
+ if (!Config.travelStaffSearchOptimize) {
+ destinationOptional = findValidDestination(
+ player,
+ source,
+ new BlockCoord(
+ (int) Math.floor(sample.x),
+ (int) Math.floor(sample.y) - 1,
+ (int) Math.floor(sample.z)));
+ if (destinationOptional.isPresent()) {
+ return destinationOptional;
+ }
+ }
+
+ return Optional.empty();
}
- public boolean travelToLocation(EntityPlayer player, TravelSource source, BlockCoord coord,
- boolean conserveMomentum) {
+ /**
+ * Returns the provided position if it's valid, or returns empty optional if unsuccessful.
+ *
+ * To be precise: if the destination is a travel anchor or other block, then the returned
+ * coordinates will be one block higher, to place the player on top of the block.
+ */
+ public Optional findValidDestination(EntityPlayer player, TravelSource source, BlockCoord coord) {
// Are we trying to travel to a block (anchor or telepad)?
boolean travelToBlock = source != TravelSource.STAFF_BLINK && source != TravelSource.TELEPORT_STAFF_BLINK;
@@ -743,7 +779,7 @@ public class TravelController {
ITravelAccessable ta = (ITravelAccessable) te;
if (!ta.canBlockBeAccessed(player)) {
showMessage(player, new ChatComponentTranslation("enderio.gui.travelAccessable.unauthorised"));
- return false;
+ return Optional.empty();
}
}
@@ -751,40 +787,41 @@ public class TravelController {
destination = coord.getLocation(ForgeDirection.UP);
}
+ if (!isInRangeTarget(player, destination, source.getMaxDistanceTravelledSq())) {
+ if (travelToBlock) {
+ showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
+ }
+ return Optional.empty();
+ }
+ if (!isValidTarget(player, destination, source)) {
+ if (travelToBlock) {
+ showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.invalidTarget"));
+ }
+ return Optional.empty();
+ }
+
+ return Optional.of(destination);
+ }
+
+ public boolean travelToSelectedTarget(EntityPlayer player, TravelSource source, boolean conserveMomentum) {
+ return travelToLocation(player, source, selectedCoord, conserveMomentum);
+ }
+
+ public boolean travelToLocation(EntityPlayer player, TravelSource source, BlockCoord coord,
+ boolean conserveMomentum) {
+ Optional destinationOptional = findValidDestination(player, source, coord);
+ if (!destinationOptional.isPresent()) {
+ return false;
+ }
+ BlockCoord destination = destinationOptional.get();
+
int requiredPower = 0;
requiredPower = getRequiredPower(player, source, destination);
if (requiredPower < 0) {
return false;
}
- if (!isInRangeTarget(player, destination, source.getMaxDistanceTravelledSq())) {
- if (travelToBlock) {
- showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
- }
- return false;
- }
- if (!isValidTarget(player, destination, source)) {
- if (travelToBlock) {
- showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.invalidTarget"));
- }
- return false;
- }
-
- boolean teleportSuccessful;
- if (player.worldObj.isRemote) {
- teleportSuccessful = doClientTeleport(player, destination, source, requiredPower, conserveMomentum);
- } else {
- teleportSuccessful = PacketTravelEvent.doServerTeleport(
- player,
- destination.x,
- destination.y,
- destination.z,
- requiredPower,
- conserveMomentum,
- source);
- }
-
- if (teleportSuccessful) {
+ if (doClientTeleport(player, destinationOptional.get(), source, requiredPower, conserveMomentum)) {
for (int i = 0; i < 6; ++i) {
player.worldObj.spawnParticle(
"portal",
diff --git a/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java b/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
index f4054a35..a8ef8f13 100644
--- a/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
+++ b/src/main/java/crazypants/enderio/teleport/packet/PacketLongDistanceTravelEvent.java
@@ -34,16 +34,27 @@ public class PacketLongDistanceTravelEvent
boolean conserveMotion;
int entityId;
int source;
+ // Below values are for also attempting a regular blink if the long-distance anchor check fails.
boolean alsoDoTeleport;
+ int tpX;
+ int tpY;
+ int tpZ;
public PacketLongDistanceTravelEvent() {}
+ public PacketLongDistanceTravelEvent(Entity entity, boolean conserveMotion, TravelSource source) {
+ this(entity, conserveMotion, source, false, 0, 0, 0);
+ }
+
public PacketLongDistanceTravelEvent(Entity entity, boolean conserveMotion, TravelSource source,
- boolean alsoDoTeleport) {
+ boolean alsoDoTeleport, int tpX, int tpY, int tpZ) {
this.conserveMotion = conserveMotion;
this.entityId = entity instanceof EntityPlayer ? -1 : entity.getEntityId();
this.source = source.ordinal();
this.alsoDoTeleport = alsoDoTeleport;
+ this.tpX = tpX;
+ this.tpY = tpY;
+ this.tpZ = tpZ;
}
@Override
@@ -52,6 +63,9 @@ public class PacketLongDistanceTravelEvent
buf.writeInt(entityId);
buf.writeInt(source);
buf.writeBoolean(alsoDoTeleport);
+ buf.writeInt(tpX);
+ buf.writeInt(tpY);
+ buf.writeInt(tpZ);
}
@Override
@@ -60,6 +74,9 @@ public class PacketLongDistanceTravelEvent
entityId = buf.readInt();
source = buf.readInt();
alsoDoTeleport = buf.readBoolean();
+ tpX = buf.readInt();
+ tpY = buf.readInt();
+ tpZ = buf.readInt();
}
@Override
@@ -78,7 +95,14 @@ public class PacketLongDistanceTravelEvent
TravelSource source = TravelSource.values()[message.source];
- if (!validate(toTp, source, message.alsoDoTeleport)) {
+ if (!validate(
+ toTp,
+ source,
+ message.conserveMotion,
+ message.alsoDoTeleport,
+ message.tpX,
+ message.tpY,
+ message.tpZ)) {
Log.LOGGER.warn(
Log.securityMarker,
"Player {} tried to tp without valid prereq.",
@@ -86,24 +110,42 @@ public class PacketLongDistanceTravelEvent
return null;
}
- doServerTeleport(toTp, message.conserveMotion, source, message.alsoDoTeleport);
+ doServerTeleport(
+ toTp,
+ message.conserveMotion,
+ source,
+ message.alsoDoTeleport,
+ message.tpX,
+ message.tpY,
+ message.tpZ);
return null;
}
- private static boolean validate(EntityPlayerMP toTp, TravelSource source, boolean alsoDoTeleport) {
+ private static boolean validate(EntityPlayerMP toTp, TravelSource source, boolean conserveMotion,
+ boolean alsoDoTeleport, int tpX, int tpY, int tpZ) {
ItemStack equippedItem = toTp.getCurrentEquippedItem();
switch (source) {
case STAFF:
// Not allowed to do teleport staff teleport with regular staff.
- if (alsoDoTeleport) return false;
+ if (alsoDoTeleport) {
+ return false;
+ }
return equippedItem != null && equippedItem.getItem() instanceof IItemOfTravel
&& ((IItemOfTravel) equippedItem.getItem()).isActive(toTp, equippedItem);
case TELEPORT_STAFF:
// tp staff is creative version of traveling staff
// no energy check or anything else needed
// but the player must actually be equipped with one of these
+ if (alsoDoTeleport) {
+ String error = TravelController.instance
+ .validatePacketTravelEvent(toTp, tpX, tpY, tpZ, 0, conserveMotion, source);
+ if (error != null) {
+ return false;
+ }
+ }
return equippedItem != null && equippedItem.getItem() instanceof ItemTeleportStaff;
+
default:
// all other types are not allowed
return false;
@@ -111,7 +153,7 @@ public class PacketLongDistanceTravelEvent
}
public static boolean doServerTeleport(Entity toTp, boolean conserveMotion, TravelSource source,
- boolean alsoDoTeleport) {
+ boolean alsoDoTeleport, int tpX, int tpY, int tpZ) {
if (!(toTp instanceof EntityPlayer)) {
return false;
}
@@ -120,7 +162,7 @@ public class PacketLongDistanceTravelEvent
Optional travelDestination = TravelController.instance.findTravelDestination(player, source);
if (!travelDestination.isPresent()) {
if (alsoDoTeleport) {
- return TravelController.instance.doTeleport(player);
+ return PacketTravelEvent.doServerTeleport(toTp, tpX, tpY, tpZ, 0, conserveMotion, source);
}
return false;
}
From 32c251d805c7455683d3c5ea6af9daa6bdb2c372 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
<41898282+github-actions[bot]@users.noreply.github.com>
Date: Tue, 23 Apr 2024 19:03:07 -0600
Subject: [PATCH 14/14] spotlessApply (#161)
Co-authored-by: GitHub GTNH Actions <>
---
.../java/crazypants/enderio/teleport/TravelController.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/main/java/crazypants/enderio/teleport/TravelController.java b/src/main/java/crazypants/enderio/teleport/TravelController.java
index 1f590d58..c80f0883 100644
--- a/src/main/java/crazypants/enderio/teleport/TravelController.java
+++ b/src/main/java/crazypants/enderio/teleport/TravelController.java
@@ -765,8 +765,9 @@ public class TravelController {
/**
* Returns the provided position if it's valid, or returns empty optional if unsuccessful.
*
- * To be precise: if the destination is a travel anchor or other block, then the returned
- * coordinates will be one block higher, to place the player on top of the block.
+ *
+ * To be precise: if the destination is a travel anchor or other block, then the returned coordinates will be one
+ * block higher, to place the player on top of the block.
*/
public Optional findValidDestination(EntityPlayer player, TravelSource source, BlockCoord coord) {
// Are we trying to travel to a block (anchor or telepad)?