From 4153e981342bbc42c7138d7cc7f720c4d41c5573 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Sat, 28 Dec 2019 23:20:48 -0900 Subject: [PATCH] Change lighting fix method --- .../java/JavaJoinGameTranslator.java | 2 +- .../java/JavaRespawnTranslator.java | 22 +++++-------------- .../connector/utils/DimensionUtils.java | 6 ++++- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java index 4167fb34..3cdc149d 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java @@ -67,7 +67,7 @@ public class JavaJoinGameTranslator extends PacketTranslator { @@ -44,7 +42,8 @@ public class JavaRespawnTranslator extends PacketTranslator return; float maxHealth = entity.getAttributes().containsKey(AttributeType.MAX_HEALTH) ? entity.getAttributes().get(AttributeType.MAX_HEALTH).getValue() : 20f; - entity.getAttributes().put(AttributeType.HEALTH, AttributeType.HEALTH.getAttribute(maxHealth)); + // Max health must be divisible by two in bedrock + entity.getAttributes().put(AttributeType.HEALTH, AttributeType.HEALTH.getAttribute(maxHealth, (maxHealth % 2 == 1 ? maxHealth + 1 : maxHealth))); SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket(); playerGameTypePacket.setGamemode(packet.getGamemode().ordinal()); @@ -52,23 +51,14 @@ public class JavaRespawnTranslator extends PacketTranslator session.setGameMode(packet.getGamemode()); if (entity.getDimension() != DimensionUtils.javaToBedrock(packet.getDimension())) { - DimensionUtils.switchDimension(session, packet.getDimension()); + DimensionUtils.switchDimension(session, packet.getDimension(), false); } else { // Handled in JavaPlayerPositionRotationTranslator session.setSpawned(false); if (session.isManyDimPackets()) { //reloading world - session.getEntityCache().removeAllEntities(); - //lighting fix - ChunkUtils.sendEmptyChunks(session, entity.getPosition().toInt(), session.getRenderDistance(), false); - Vector3f tempPos = Vector3f.from(entity.getPosition().getX() > 0 ? -5000 : 5000, 0, 0); - MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); - movePlayerPacket.setRuntimeEntityId(entity.getGeyserId()); - movePlayerPacket.setPosition(tempPos); - movePlayerPacket.setRotation(Vector3f.ZERO); - movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL); - movePlayerPacket.setOnGround(true); - session.getUpstream().sendPacket(movePlayerPacket); - ChunkUtils.sendEmptyChunks(session, tempPos.toInt(), 5, true); + int fakeDim = entity.getDimension() == 0 ? -1 : 0; + DimensionUtils.switchDimension(session, fakeDim, true); + DimensionUtils.switchDimension(session, packet.getDimension(), false); } } } 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 f0a0ed58..ace1c682 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java @@ -6,7 +6,7 @@ import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; public class DimensionUtils { - public static void switchDimension(GeyserSession session, int javaDimension) { + public static void switchDimension(GeyserSession session, int javaDimension, boolean fake) { int bedrockDimension = javaToBedrock(javaDimension); Entity player = session.getPlayerEntity(); if (bedrockDimension == player.getDimension()) @@ -28,6 +28,10 @@ public class DimensionUtils { stopSoundPacket.setSoundName(""); session.getUpstream().sendPacket(stopSoundPacket); + if (fake) { + ChunkUtils.sendEmptyChunks(session, pos, 2, true); + } + session.setSpawned(false); session.setSwitchingDimension(true); }