diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index a4f57c08e6d..c3af7cd4d0c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -28,6 +28,7 @@ import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.auth.exception.request.RequestException; import com.github.steveice10.mc.protocol.MinecraftProtocol; +import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace; import com.github.steveice10.packetlib.Client; import com.github.steveice10.packetlib.event.session.ConnectedEvent; @@ -95,9 +96,7 @@ public class GeyserSession implements Player { private boolean closed; @Setter - private Vector3i blockDiggingPos = Vector3i.ZERO; - @Setter - private BlockFace blockDiggingFace = BlockFace.DOWN; + private GameMode gameMode = GameMode.SURVIVAL; public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession) { this.connector = connector; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java index 0b5ad4ad1c4..334679346c1 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java @@ -93,12 +93,9 @@ public void translate(PlayerActionPacket packet, GeyserSession session) { case START_BREAK: ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(packet.getBlockPosition().getX(), packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()), BlockFace.values()[packet.getFace()]); - session.setBlockDiggingPos(packet.getBlockPosition()); - session.setBlockDiggingFace(BlockFace.values()[packet.getFace()]); session.getDownstream().getSession().send(startBreakingPacket); break; case CONTINUE_BREAK: - session.setBlockDiggingFace(BlockFace.values()[packet.getFace()]); break; case ABORT_BREAK: ClientPlayerActionPacket abortBreakingPacket = new ClientPlayerActionPacket(PlayerAction.CANCEL_DIGGING, new Position(packet.getBlockPosition().getX(), @@ -106,10 +103,7 @@ public void translate(PlayerActionPacket packet, GeyserSession session) { session.getDownstream().getSession().send(abortBreakingPacket); break; case STOP_BREAK: - Vector3i pos = session.getBlockDiggingPos(); - ClientPlayerActionPacket stopBreakingPacket = new ClientPlayerActionPacket(PlayerAction.FINISH_DIGGING, new Position(pos.getX(), - pos.getY(), pos.getZ()), session.getBlockDiggingFace()); - session.getDownstream().getSession().send(stopBreakingPacket); + // Handled in BedrockInventoryTransactionTranslator break; } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java index 1e6b44a9ef4..bf1ae11cce8 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java @@ -26,6 +26,7 @@ package org.geysermc.connector.network.translators.bedrock; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; +import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction; import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction; @@ -36,7 +37,6 @@ import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket; import org.geysermc.connector.entity.Entity; -import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -49,6 +49,11 @@ public void translate(InventoryTransactionPacket packet, GeyserSession session) if (packet.getActionType() == 1) { ClientPlayerUseItemPacket useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND); session.getDownstream().getSession().send(useItemPacket); + } else if (packet.getActionType() == 2) { + PlayerAction action = session.getGameMode() == GameMode.CREATIVE ? PlayerAction.START_DIGGING : PlayerAction.FINISH_DIGGING; + Position pos = new Position(packet.getBlockPosition().getX(), packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()); + ClientPlayerActionPacket breakPacket = new ClientPlayerActionPacket(action, pos, BlockFace.values()[packet.getFace()]); + session.getDownstream().getSession().send(breakPacket); } break; case ITEM_RELEASE: 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 32057c1692d..3c5a45bfc3e 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 @@ -52,6 +52,7 @@ public void translate(ServerJoinGamePacket packet, GeyserSession session) { SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket(); playerGameTypePacket.setGamemode(packet.getGameMode().ordinal()); session.getUpstream().sendPacket(playerGameTypePacket); + session.setGameMode(packet.getGameMode()); SetEntityDataPacket entityDataPacket = new SetEntityDataPacket(); entityDataPacket.setRuntimeEntityId(entity.getGeyserId()); 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 f5f86e19b7b..c1618f1525e 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 @@ -55,6 +55,7 @@ public void translate(ServerRespawnPacket packet, GeyserSession session) { SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket(); playerGameTypePacket.setGamemode(packet.getGamemode().ordinal()); session.getUpstream().sendPacket(playerGameTypePacket); + session.setGameMode(packet.getGamemode()); PlayStatusPacket playStatusPacket = new PlayStatusPacket(); playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java index e32d27187c9..6c1b51aeed8 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java @@ -57,10 +57,11 @@ public void translate(ServerNotifyClientPacket packet, GeyserSession session) { session.getUpstream().sendPacket(stopRainPacket); break; case CHANGE_GAMEMODE: - int gamemode = ((GameMode) packet.getValue()).ordinal(); + GameMode gameMode = (GameMode) packet.getValue(); SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket(); - playerGameTypePacket.setGamemode(gamemode); + playerGameTypePacket.setGamemode(gameMode.ordinal()); session.getUpstream().sendPacket(playerGameTypePacket); + session.setGameMode(gameMode); break; case ENTER_CREDITS: Entity entity = session.getPlayerEntity();