forked from GeyserMC/Geyser
Fix dimension switching; add static references to new Java dimensions
This commit is contained in:
parent
e4d990329d
commit
71aada1df3
2 changed files with 10 additions and 16 deletions
|
@ -70,7 +70,7 @@ public class JavaRespawnTranslator extends PacketTranslator<ServerRespawnPacket>
|
||||||
DimensionUtils.switchDimension(session, packet.getDimension());
|
DimensionUtils.switchDimension(session, packet.getDimension());
|
||||||
} else {
|
} else {
|
||||||
if (session.isManyDimPackets()) { //reloading world
|
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, fakeDim);
|
||||||
DimensionUtils.switchDimension(session, packet.getDimension());
|
DimensionUtils.switchDimension(session, packet.getDimension());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -36,10 +36,15 @@ public class DimensionUtils {
|
||||||
// Changes if the above-bedrock Nether building workaround is applied
|
// Changes if the above-bedrock Nether building workaround is applied
|
||||||
private static int BEDROCK_NETHER_ID = 1;
|
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) {
|
public static void switchDimension(GeyserSession session, String javaDimension) {
|
||||||
int bedrockDimension = javaToBedrock(javaDimension);
|
int bedrockDimension = javaToBedrock(javaDimension);
|
||||||
Entity player = session.getPlayerEntity();
|
Entity player = session.getPlayerEntity();
|
||||||
if (bedrockToJava(bedrockDimension) == player.getDimension())
|
if (javaDimension.equals(player.getDimension()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
session.getEntityCache().removeAllEntities();
|
session.getEntityCache().removeAllEntities();
|
||||||
|
@ -55,7 +60,7 @@ public class DimensionUtils {
|
||||||
changeDimensionPacket.setRespawn(true);
|
changeDimensionPacket.setRespawn(true);
|
||||||
changeDimensionPacket.setPosition(pos.toFloat());
|
changeDimensionPacket.setPosition(pos.toFloat());
|
||||||
session.sendUpstreamPacket(changeDimensionPacket);
|
session.sendUpstreamPacket(changeDimensionPacket);
|
||||||
player.setDimension(bedrockToJava(bedrockDimension));
|
player.setDimension(javaDimension);
|
||||||
player.setPosition(pos.toFloat());
|
player.setPosition(pos.toFloat());
|
||||||
session.setSpawned(false);
|
session.setSpawned(false);
|
||||||
session.setLastChunkPosition(null);
|
session.setLastChunkPosition(null);
|
||||||
|
@ -85,26 +90,15 @@ public class DimensionUtils {
|
||||||
*/
|
*/
|
||||||
public static int javaToBedrock(String javaDimension) {
|
public static int javaToBedrock(String javaDimension) {
|
||||||
switch (javaDimension) {
|
switch (javaDimension) {
|
||||||
case "minecraft:nether":
|
case NETHER:
|
||||||
return BEDROCK_NETHER_ID;
|
return BEDROCK_NETHER_ID;
|
||||||
case "minecraft:the_end":
|
case THE_END:
|
||||||
return 2;
|
return 2;
|
||||||
default:
|
default:
|
||||||
return 0;
|
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() {
|
public static void changeBedrockNetherId() {
|
||||||
// Change dimension ID to the End to allow for building above Bedrock
|
// Change dimension ID to the End to allow for building above Bedrock
|
||||||
BEDROCK_NETHER_ID = 2;
|
BEDROCK_NETHER_ID = 2;
|
||||||
|
|
Loading…
Reference in a new issue