Skip to content

Commit

Permalink
Fix dimension switching; add static references to new Java dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jun 25, 2020
1 parent e4d9903 commit 71aada1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void translate(ServerRespawnPacket packet, GeyserSession session) {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -55,7 +60,7 @@ public static void switchDimension(GeyserSession session, String javaDimension)
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);
Expand Down Expand Up @@ -85,26 +90,15 @@ public static void switchDimension(GeyserSession session, String javaDimension)
*/
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;
Expand Down

0 comments on commit 71aada1

Please sign in to comment.