From 71aada1df395c9ff04bbf0192a2afd71cd916b92 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Wed, 24 Jun 2020 20:27:10 -0400 Subject: [PATCH] Fix dimension switching; add static references to new Java dimensions --- .../java/JavaRespawnTranslator.java | 2 +- .../connector/utils/DimensionUtils.java | 24 +++++++------------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java index 0d80f4af..288389fa 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java @@ -70,7 +70,7 @@ public class JavaRespawnTranslator extends PacketTranslator DimensionUtils.switchDimension(session, packet.getDimension()); } else { if (session.isManyDimPackets()) { //reloading world - String fakeDim = entity.getDimension().equals("minecraft:overworld") ? "minecraft:nether" : "minecraft:overworld"; + String fakeDim = entity.getDimension().equals(DimensionUtils.OVERWORLD) ? DimensionUtils.NETHER : DimensionUtils.OVERWORLD; DimensionUtils.switchDimension(session, fakeDim); DimensionUtils.switchDimension(session, packet.getDimension()); } else { diff --git a/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java b/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java index b78a28ff..74db16bb 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java @@ -36,10 +36,15 @@ public class DimensionUtils { // Changes if the above-bedrock Nether building workaround is applied private static int BEDROCK_NETHER_ID = 1; + // Static references to all vanilla dimensions + public static final String OVERWORLD = "minecraft:overworld"; + public static final String NETHER = "minecraft:the_nether"; + public static final String THE_END = "minecraft:the_end"; + public static void switchDimension(GeyserSession session, String javaDimension) { int bedrockDimension = javaToBedrock(javaDimension); Entity player = session.getPlayerEntity(); - if (bedrockToJava(bedrockDimension) == player.getDimension()) + if (javaDimension.equals(player.getDimension())) return; session.getEntityCache().removeAllEntities(); @@ -55,7 +60,7 @@ public class DimensionUtils { changeDimensionPacket.setRespawn(true); changeDimensionPacket.setPosition(pos.toFloat()); session.sendUpstreamPacket(changeDimensionPacket); - player.setDimension(bedrockToJava(bedrockDimension)); + player.setDimension(javaDimension); player.setPosition(pos.toFloat()); session.setSpawned(false); session.setLastChunkPosition(null); @@ -85,26 +90,15 @@ public class DimensionUtils { */ public static int javaToBedrock(String javaDimension) { switch (javaDimension) { - case "minecraft:nether": + case NETHER: return BEDROCK_NETHER_ID; - case "minecraft:the_end": + case THE_END: return 2; default: return 0; } } - public static String bedrockToJava(int bedrockDimension) { - switch (bedrockDimension) { - case 1: - return "minecraft:nether"; - case 2: - return "minecraft:the_end"; - default: - return "minecraft:overworld"; - } - } - public static void changeBedrockNetherId() { // Change dimension ID to the End to allow for building above Bedrock BEDROCK_NETHER_ID = 2;