From 4f461bf3744081bb16b7356d9e894dd34be89d9e Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Wed, 5 Feb 2020 18:55:34 -0600 Subject: [PATCH 01/21] Start on converting to the new NukkitX protocol library updates --- connector/pom.xml | 2 +- .../org/geysermc/connector/entity/Entity.java | 4 +- .../connector/entity/PlayerEntity.java | 13 +++--- .../network/session/GeyserSession.java | 3 +- .../network/translators/TranslatorsInit.java | 3 +- .../bedrock/BedrockInteractTranslator.java | 4 +- .../java/JavaBossBarTranslator.java | 8 ++-- .../java/JavaJoinGameTranslator.java | 3 +- .../player/JavaPlayerAbilitiesTranslator.java | 30 +++++++------- .../player/JavaPlayerListEntryTranslator.java | 2 +- .../world/JavaNotifyClientTranslator.java | 40 ++++++++++--------- .../geysermc/connector/utils/SkinUtils.java | 4 +- 12 files changed, 58 insertions(+), 58 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index 9de1e3e75..cb0f2686e 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -67,7 +67,7 @@ com.nukkitx.protocol bedrock-v389 - 2.4.4 + 2.4.6-SNAPSHOT compile diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index 47b398748..e49a66888 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -30,7 +30,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType; import com.github.steveice10.mc.protocol.data.message.TextMessage; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.EntityData; -import com.nukkitx.protocol.bedrock.data.EntityDataDictionary; +import com.nukkitx.protocol.bedrock.data.EntityDataMap; import com.nukkitx.protocol.bedrock.data.EntityFlag; import com.nukkitx.protocol.bedrock.data.EntityFlags; import com.nukkitx.protocol.bedrock.packet.*; @@ -73,7 +73,7 @@ public class Entity { protected LongSet passengers = new LongOpenHashSet(); protected Map attributes = new HashMap<>(); - protected EntityDataDictionary metadata = new EntityDataDictionary(); + protected EntityDataMap metadata = new EntityDataMap(); public Entity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { this.entityId = entityId; diff --git a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java index 67dc08941..ffe69cda5 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java @@ -27,6 +27,8 @@ package org.geysermc.connector.entity; import com.github.steveice10.mc.auth.data.GameProfile; import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.CommandPermission; +import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket; import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; import lombok.Getter; @@ -74,11 +76,8 @@ public class PlayerEntity extends LivingEntity { addPlayerPacket.setRotation(getBedrockRotation()); addPlayerPacket.setMotion(motion); addPlayerPacket.setHand(hand); - addPlayerPacket.setPlayerFlags(0); - addPlayerPacket.setCommandPermission(0); - addPlayerPacket.setWorldFlags(0); - addPlayerPacket.setPlayerPermission(0); - addPlayerPacket.setCustomFlags(0); + addPlayerPacket.getAdventureSettings().setCommandPermission(CommandPermission.NORMAL); + addPlayerPacket.getAdventureSettings().setPlayerPermission(PlayerPermission.VISITOR); addPlayerPacket.setDeviceId(""); addPlayerPacket.setPlatformChatId(""); addPlayerPacket.getMetadata().putAll(getMetadata()); @@ -91,7 +90,7 @@ public class PlayerEntity extends LivingEntity { if (getLastSkinUpdate() == -1) { if (playerList) { PlayerListPacket playerList = new PlayerListPacket(); - playerList.setType(PlayerListPacket.Type.ADD); + playerList.setAction(PlayerListPacket.Action.ADD); playerList.getEntries().add(SkinUtils.buildDefaultEntry(profile, geyserId)); session.getUpstream().sendPacket(playerList); } @@ -107,7 +106,7 @@ public class PlayerEntity extends LivingEntity { // remove from playerlist if player isn't on playerlist Geyser.getGeneralThreadPool().execute(() -> { PlayerListPacket playerList = new PlayerListPacket(); - playerList.setType(PlayerListPacket.Type.REMOVE); + playerList.setAction(PlayerListPacket.Action.REMOVE); playerList.getEntries().add(new PlayerListPacket.Entry(uuid)); session.getUpstream().sendPacket(playerList); }); 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 53fecf79c..7b8a93983 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 @@ -45,6 +45,7 @@ import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.protocol.bedrock.BedrockServerSession; import com.nukkitx.protocol.bedrock.data.GamePublishSetting; import com.nukkitx.protocol.bedrock.data.GameRule; +import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.packet.*; import lombok.Getter; import lombok.Setter; @@ -304,7 +305,7 @@ public class GeyserSession implements Player { startGamePacket.setBonusChestEnabled(false); startGamePacket.setStartingWithMap(false); startGamePacket.setTrustingPlayers(true); - startGamePacket.setDefaultPlayerPermission(1); + startGamePacket.setDefaultPlayerPermission(PlayerPermission.OPERATOR); startGamePacket.setServerChunkTickRange(4); startGamePacket.setBehaviorPackLocked(false); startGamePacket.setResourcePackLocked(false); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java index bc14ba5d4..e6a2c2ed2 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java @@ -129,8 +129,7 @@ public class TranslatorsInit { Registry.registerJava(ServerPlayerHealthPacket.class, new JavaPlayerHealthTranslator()); Registry.registerJava(ServerPlayerActionAckPacket.class, new JavaPlayerActionAckTranslator()); - // FIXME: This translator messes with allowing flight in creative mode. Will need to be addressed later - // Registry.registerJava(ServerPlayerAbilitiesPacket.class, new JavaPlayerAbilitiesTranslator()); + Registry.registerJava(ServerPlayerAbilitiesPacket.class, new JavaPlayerAbilitiesTranslator()); Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator()); Registry.registerJava(ServerChunkDataPacket.class, new JavaChunkDataTranslator()); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java index 67d398f6f..cfac373ca 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java @@ -44,12 +44,12 @@ public class BedrockInteractTranslator extends PacketTranslator return; switch (packet.getAction()) { - case 1: + case NONE: ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(), InteractAction.INTERACT, Hand.MAIN_HAND); session.getDownstream().getSession().send(interactPacket); break; - case 2: + case UNKNOWN_1: ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(), InteractAction.ATTACK, Hand.MAIN_HAND); session.getDownstream().getSession().send(attackPacket); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java index c918c0d5b..bfde6f74c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java @@ -46,7 +46,7 @@ public class JavaBossBarTranslator extends PacketTranslator long entityId = session.getEntityCache().addBossBar(packet.getUuid()); addBossEntity(session, entityId); - bossEventPacket.setType(BossEventPacket.Type.SHOW); + bossEventPacket.setAction(BossEventPacket.Action.SHOW); bossEventPacket.setBossUniqueEntityId(entityId); bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle())); bossEventPacket.setHealthPercentage(packet.getHealth()); @@ -55,15 +55,15 @@ public class JavaBossBarTranslator extends PacketTranslator bossEventPacket.setDarkenSky(0); break; case UPDATE_TITLE: - bossEventPacket.setType(BossEventPacket.Type.TITLE); + bossEventPacket.setAction(BossEventPacket.Action.TITLE); bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle())); break; case UPDATE_HEALTH: - bossEventPacket.setType(BossEventPacket.Type.HEALTH_PERCENTAGE); + bossEventPacket.setAction(BossEventPacket.Action.HEALTH_PERCENTAGE); bossEventPacket.setHealthPercentage(packet.getHealth()); break; case REMOVE: - bossEventPacket.setType(BossEventPacket.Type.HIDE); + bossEventPacket.setAction(BossEventPacket.Action.HIDE); removeBossEntity(session, session.getEntityCache().removeBossBar(packet.getUuid())); break; case UPDATE_STYLE: 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 97cf35e5c..f7f75bf7b 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 @@ -27,6 +27,7 @@ package org.geysermc.connector.network.translators.java; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; +import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.packet.*; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; @@ -42,7 +43,7 @@ public class JavaJoinGameTranslator extends PacketTranslator { @Override @@ -42,7 +46,7 @@ public class JavaPlayerAbilitiesTranslator extends PacketTranslator playerFlags = new HashSet<>(); + playerFlags.add(AdventureSettingsPacket.Flag.AUTO_JUMP); + if (packet.isCanFly()) + playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY); - playerFlags = setPlayerFlag(0x20, true, playerFlags); // auto jump - playerFlags = setPlayerFlag(0x40, packet.isCanFly(), playerFlags); // can fly - playerFlags = setPlayerFlag(0x200, packet.isFlying(), playerFlags); // is flying + if (packet.isFlying()) + playerFlags.add(AdventureSettingsPacket.Flag.FLYING); AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket(); - adventureSettingsPacket.setPlayerPermission(1); + adventureSettingsPacket.setPlayerPermission(PlayerPermission.OPERATOR); adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId()); - adventureSettingsPacket.setPlayerFlags(playerFlags); + adventureSettingsPacket.getFlags().addAll(playerFlags); session.getUpstream().sendPacket(adventureSettingsPacket); } - - private int setPlayerFlag(int flag, boolean value, int playerFlags) { - if (value) { - return playerFlags | flag; - } else { - return playerFlags & ~flag; - } - } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java index c39a95dbf..48f20dbdd 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerListEntryTranslator.java @@ -41,7 +41,7 @@ public class JavaPlayerListEntryTranslator extends PacketTranslator { @@ -64,14 +67,21 @@ public class JavaNotifyClientTranslator extends PacketTranslator playerFlags = new HashSet<>(); GameMode gameMode = (GameMode) packet.getValue(); - playerFlags = setPlayerFlag(0x01, gameMode == GameMode.ADVENTURE, playerFlags); // world immutable - playerFlags = setPlayerFlag(0x20, true, playerFlags); // auto jump - playerFlags = setPlayerFlag(0x40, gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR, playerFlags); // can fly - playerFlags = setPlayerFlag(0x80, gameMode == GameMode.SPECTATOR, playerFlags); // no clip - playerFlags = setPlayerFlag(0x200, gameMode == GameMode.SPECTATOR, playerFlags); // is flying + if (gameMode == GameMode.ADVENTURE) + playerFlags.add(AdventureSettingsPacket.Flag.IMMUTABLE_WORLD); + + if (gameMode == GameMode.CREATIVE) + playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY); + + if (gameMode == GameMode.SPECTATOR) { + playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY); + playerFlags.add(AdventureSettingsPacket.Flag.NO_CLIP); + playerFlags.add(AdventureSettingsPacket.Flag.FLYING); + } + + playerFlags.add(AdventureSettingsPacket.Flag.AUTO_JUMP); SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket(); playerGameTypePacket.setGamemode(gameMode.ordinal()); @@ -79,12 +89,12 @@ public class JavaNotifyClientTranslator extends PacketTranslator Date: Wed, 5 Feb 2020 19:21:09 -0900 Subject: [PATCH 02/21] Fix bugs when rapidly switching dimensions --- .../network/session/GeyserSession.java | 8 ++++++-- .../bedrock/BedrockActionTranslator.java | 13 +++++++------ .../bedrock/BedrockMovePlayerTranslator.java | 2 +- .../BedrockPlayerInitializedTranslator.java | 5 ----- .../java/JavaJoinGameTranslator.java | 4 +++- .../translators/java/JavaRespawnTranslator.java | 11 ++++++----- .../connector/utils/DimensionUtils.java | 17 ++++++++--------- 7 files changed, 31 insertions(+), 29 deletions(-) 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 53fecf79c..25eacdf5a 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 @@ -62,6 +62,7 @@ import org.geysermc.connector.utils.Toolbox; import java.net.InetSocketAddress; import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; @Getter public class GeyserSession implements Player { @@ -98,8 +99,7 @@ public class GeyserSession implements Player { @Setter private GameMode gameMode = GameMode.SURVIVAL; - @Setter - private boolean switchingDimension = false; + private final AtomicInteger pendingDimSwitches = new AtomicInteger(0); private boolean manyDimPackets = false; private ServerRespawnPacket lastDimPacket = null; @@ -127,6 +127,10 @@ public class GeyserSession implements Player { public void connect(RemoteServer remoteServer) { startGame(); this.remoteServer = remoteServer; + if (!(connector.getConfig().getRemote().getAuthType().hashCode() == "online".hashCode())) { + connector.getLogger().info("Attempting to login using offline mode... authentication is disabled."); + authenticate(authenticationData.getName()); + } ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false); 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 56e573c69..7392edc1d 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 @@ -107,12 +107,13 @@ public class BedrockActionTranslator extends PacketTranslator 0) return; if (!session.getUpstream().isInitialized()) { MoveEntityAbsolutePacket moveEntityBack = new MoveEntityAbsolutePacket(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java index e30ef2d77..201049db0 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java @@ -38,11 +38,6 @@ public class BedrockPlayerInitializedTranslator extends PacketTranslator { @@ -67,7 +68,8 @@ public class JavaJoinGameTranslator extends PacketTranslator session.setGameMode(packet.getGamemode()); if (entity.getDimension() != DimensionUtils.javaToBedrock(packet.getDimension())) { - DimensionUtils.switchDimension(session, packet.getDimension(), false); + DimensionUtils.switchDimension(session, packet.getDimension()); } else { - // Handled in JavaPlayerPositionRotationTranslator - session.setSpawned(false); if (session.isManyDimPackets()) { //reloading world int fakeDim = entity.getDimension() == 0 ? -1 : 0; - DimensionUtils.switchDimension(session, fakeDim, true); - DimensionUtils.switchDimension(session, packet.getDimension(), false); + DimensionUtils.switchDimension(session, fakeDim); + DimensionUtils.switchDimension(session, packet.getDimension()); + } else { + // Handled in JavaPlayerPositionRotationTranslator + session.setSpawned(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 81f528238..c7ecaafb4 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java @@ -31,14 +31,18 @@ import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; public class DimensionUtils { - public static void switchDimension(GeyserSession session, int javaDimension, boolean fake) { + public static void switchDimension(GeyserSession session, int javaDimension) { int bedrockDimension = javaToBedrock(javaDimension); Entity player = session.getPlayerEntity(); if (bedrockDimension == player.getDimension()) return; - Vector3i pos = Vector3i.from(0, Short.MAX_VALUE, 0); session.getEntityCache().removeAllEntities(); + if (session.getPendingDimSwitches().getAndIncrement() > 0) { + ChunkUtils.sendEmptyChunks(session, player.getPosition().toInt(), 3, true); + } + + Vector3i pos = Vector3i.from(0, Short.MAX_VALUE, 0); ChangeDimensionPacket changeDimensionPacket = new ChangeDimensionPacket(); changeDimensionPacket.setDimension(bedrockDimension); @@ -46,19 +50,14 @@ public class DimensionUtils { changeDimensionPacket.setPosition(pos.toFloat()); session.getUpstream().sendPacket(changeDimensionPacket); player.setDimension(bedrockDimension); + player.setPosition(pos.toFloat()); + session.setSpawned(false); //let java server handle portal travel sound StopSoundPacket stopSoundPacket = new StopSoundPacket(); stopSoundPacket.setStoppingAllSound(true); stopSoundPacket.setSoundName(""); session.getUpstream().sendPacket(stopSoundPacket); - - if (fake) { - ChunkUtils.sendEmptyChunks(session, pos, 2, true); - } - - session.setSpawned(false); - session.setSwitchingDimension(true); } public static int javaToBedrock(int javaDimension) { From e0a1435d51e8e1472a5f8cad90851cc10c999a7a Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Wed, 5 Feb 2020 19:23:08 -0900 Subject: [PATCH 03/21] Send confirmation packet when spawning Fixes some chunk bugs --- .../entity/player/JavaPlayerPositionRotationTranslator.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java index d5b843136..a5d203334 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java @@ -51,7 +51,7 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator Date: Wed, 5 Feb 2020 19:32:33 -0900 Subject: [PATCH 04/21] Chunk fixes --- .../network/session/GeyserSession.java | 16 +++- .../network/translators/TranslatorsInit.java | 3 + .../translators/block/BlockTranslator.java | 8 +- .../java/JavaJoinGameTranslator.java | 7 +- .../java/world/JavaChunkDataTranslator.java | 96 ++++++++++--------- .../JavaUpdateViewDistanceTranslator.java | 38 ++++++++ .../JavaUpdateViewPositionTranslator.java | 43 +++++++++ .../geysermc/connector/utils/ChunkUtils.java | 18 ++-- .../org/geysermc/connector/utils/Toolbox.java | 2 + 9 files changed, 161 insertions(+), 70 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewDistanceTranslator.java create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java 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 25eacdf5a..dde8cd70e 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 @@ -38,7 +38,6 @@ import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.tcp.TcpSessionFactory; import com.nukkitx.math.vector.Vector2f; -import com.nukkitx.math.vector.Vector2i; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3i; import com.nukkitx.nbt.tag.CompoundTag; @@ -84,10 +83,8 @@ public class GeyserSession implements Player { private DataCache javaPacketCache; - @Setter - private Vector2i lastChunkPosition = null; - @Setter private int renderDistance; + private int chunkPublisherRadius; private boolean loggedIn; private boolean loggingIn; @@ -269,6 +266,17 @@ public class GeyserSession implements Player { windowCache.showWindow(window, id); } + public void setRenderDistance(int renderDistance) { + if (renderDistance > 32) renderDistance = 32; // <3 u ViaVersion but I don't like crashing clients x) + this.renderDistance = renderDistance; + + chunkPublisherRadius = renderDistance * 3/2 << 4; //some chunks are ignored if this isn't increased + + ChunkRadiusUpdatedPacket chunkRadiusUpdatedPacket = new ChunkRadiusUpdatedPacket(); + chunkRadiusUpdatedPacket.setRadius(renderDistance); + upstream.sendPacket(chunkRadiusUpdatedPacket); + } + @Override public InetSocketAddress getSocketAddress() { return this.upstream.getAddress(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java index bc14ba5d4..59f22d4ca 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java @@ -146,6 +146,9 @@ public class TranslatorsInit { Registry.registerJava(ServerMultiBlockChangePacket.class, new JavaMultiBlockChangeTranslator()); Registry.registerJava(ServerUnloadChunkPacket.class, new JavaUnloadChunkTranslator()); + Registry.registerJava(ServerUpdateViewPositionPacket.class, new JavaUpdateViewPositionTranslator()); + Registry.registerJava(ServerUpdateViewDistancePacket.class, new JavaUpdateViewDistanceTranslator()); + Registry.registerJava(ServerOpenWindowPacket.class, new OpenWindowPacketTranslator()); Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator()); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java index bbcf0f5da..e42891714 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java @@ -28,18 +28,12 @@ package org.geysermc.connector.network.translators.block; import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import org.geysermc.connector.utils.Toolbox; -import java.util.HashMap; -import java.util.Map; - public class BlockTranslator { - private final Map javaIdentifierMap = new HashMap<>(); - public BlockEntry getBlockEntry(BlockState state) { return Toolbox.BLOCK_ENTRIES.get(state.getId()); } public BlockEntry getBlockEntry(String javaIdentifier) { - return javaIdentifierMap.computeIfAbsent(javaIdentifier, key -> Toolbox.BLOCK_ENTRIES.values() - .stream().filter(blockEntry -> blockEntry.getJavaIdentifier().equals(key)).findFirst().orElse(null)); + return Toolbox.JAVA_IDENTIFIER_TO_ENTRY.get(javaIdentifier); } } 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 28a4db557..3f11dc8cf 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 @@ -60,12 +60,7 @@ public class JavaJoinGameTranslator extends PacketTranslator 32) session.setRenderDistance(32); // <3 u ViaVersion but I don't like crashing clients x) - - ChunkRadiusUpdatedPacket chunkRadiusPacket = new ChunkRadiusUpdatedPacket(); - chunkRadiusPacket.setRadius(session.getRenderDistance()); - session.getUpstream().sendPacket(chunkRadiusPacket); + session.setRenderDistance(packet.getViewDistance()); if (DimensionUtils.javaToBedrock(packet.getDimension()) != entity.getDimension()) { ChunkUtils.sendEmptyChunks(session, entity.getPosition().toInt(), 3, true); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java index 1a9230e6d..90467b6b8 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java @@ -25,12 +25,12 @@ package org.geysermc.connector.network.translators.java.world; +import com.github.steveice10.mc.protocol.data.game.chunk.Chunk; +import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket; -import com.nukkitx.math.vector.Vector2i; -import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.math.vector.Vector3i; import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; -import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.geysermc.api.Geyser; @@ -45,49 +45,59 @@ public class JavaChunkDataTranslator extends PacketTranslator { - Vector2i chunkPos = session.getLastChunkPosition(); - Vector3f position = session.getPlayerEntity().getPosition(); - Vector2i newChunkPos = Vector2i.from(position.getFloorX() >> 4, position.getFloorZ() >> 4); - - if (chunkPos == null || !chunkPos.equals(newChunkPos)) { - NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket(); - chunkPublisherUpdatePacket.setPosition(position.toInt()); - chunkPublisherUpdatePacket.setRadius(session.getRenderDistance() << 4); - session.getUpstream().sendPacket(chunkPublisherUpdatePacket); - - session.setLastChunkPosition(newChunkPos); - } - try { - ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(packet.getColumn()); - ByteBuf byteBuf = Unpooled.buffer(32); - ChunkSection[] sections = chunkData.sections; + if (packet.getColumn().getBiomeData() != null) { //Full chunk + ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(packet.getColumn()); + ByteBuf byteBuf = Unpooled.buffer(32); + ChunkSection[] sections = chunkData.sections; - int sectionCount = sections.length - 1; - while (sectionCount >= 0 && sections[sectionCount].isEmpty()) { - sectionCount--; + int sectionCount = sections.length - 1; + while (sectionCount >= 0 && sections[sectionCount].isEmpty()) { + sectionCount--; + } + sectionCount++; + + for (int i = 0; i < sectionCount; i++) { + ChunkSection section = chunkData.sections[i]; + section.writeToNetwork(byteBuf); + } + + byteBuf.writeBytes(chunkData.biomes); // Biomes - 256 bytes + byteBuf.writeByte(0); // Border blocks - Edu edition only + VarInts.writeUnsignedInt(byteBuf, 0); // extra data length, 0 for now + + byte[] payload = new byte[byteBuf.writerIndex()]; + byteBuf.readBytes(payload); + + LevelChunkPacket levelChunkPacket = new LevelChunkPacket(); + levelChunkPacket.setSubChunksLength(sectionCount); + levelChunkPacket.setCachingEnabled(false); + levelChunkPacket.setChunkX(packet.getColumn().getX()); + levelChunkPacket.setChunkZ(packet.getColumn().getZ()); + levelChunkPacket.setData(payload); + session.getUpstream().sendPacket(levelChunkPacket); + } else { + Chunk[] chunks = packet.getColumn().getChunks(); + for (int i = 0; i < chunks.length; i++) { + Chunk chunk = chunks[i]; + if (chunk == null) continue; + final int xOffset = packet.getColumn().getX() << 4; + final int yOffset = i * 16; + final int zOffset = packet.getColumn().getZ() << 4; + for (int x = 0; x < 16; x++) { + for (int y = 0; y < 16; y++) { + for (int z = 0; z < 16; z++) { + BlockState blockState = chunk.get(x, y, z); + Vector3i pos = Vector3i.from( + x + xOffset, + y + yOffset, + z + zOffset); + ChunkUtils.updateBlock(session, blockState, pos); + } + } + } + } } - sectionCount++; - - for (int i = 0; i < sectionCount; i++) { - ChunkSection section = chunkData.sections[i]; - section.writeToNetwork(byteBuf); - } - - byteBuf.writeBytes(chunkData.biomes); // Biomes - 256 bytes - byteBuf.writeByte(0); // Border blocks - Edu edition only - VarInts.writeUnsignedInt(byteBuf, 0); // extra data length, 0 for now - - byte[] payload = new byte[byteBuf.writerIndex()]; - byteBuf.readBytes(payload); - - LevelChunkPacket levelChunkPacket = new LevelChunkPacket(); - levelChunkPacket.setSubChunksLength(sectionCount); - levelChunkPacket.setCachingEnabled(false); - levelChunkPacket.setChunkX(packet.getColumn().getX()); - levelChunkPacket.setChunkZ(packet.getColumn().getZ()); - levelChunkPacket.setData(payload); - session.getUpstream().sendPacket(levelChunkPacket); } catch (Exception ex) { ex.printStackTrace(); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewDistanceTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewDistanceTranslator.java new file mode 100644 index 000000000..1b339b1cf --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewDistanceTranslator.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.network.translators.java.world; + +import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewDistancePacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaUpdateViewDistanceTranslator extends PacketTranslator { + + @Override + public void translate(ServerUpdateViewDistancePacket packet, GeyserSession session) { + session.setRenderDistance(packet.getViewDistance()); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java new file mode 100644 index 000000000..6761d2b38 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.network.translators.java.world; + +import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewPositionPacket; +import com.nukkitx.math.vector.Vector3i; +import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaUpdateViewPositionTranslator extends PacketTranslator { + + @Override + public void translate(ServerUpdateViewPositionPacket packet, GeyserSession session) { + NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket(); + chunkPublisherUpdatePacket.setPosition(Vector3i.from(packet.getChunkX() << 4, 0, packet.getChunkZ() << 4)); + chunkPublisherUpdatePacket.setRadius(session.getChunkPublisherRadius()); + session.getUpstream().sendPacket(chunkPublisherUpdatePacket); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java index 2d1e8ee7f..1adf0016b 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java @@ -31,7 +31,6 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.nukkitx.math.vector.Vector3i; import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; -import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket; import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.TranslatorsInit; @@ -76,19 +75,23 @@ public class ChunkUtils { } public static void updateBlock(GeyserSession session, BlockState blockState, Position position) { - BlockEntry blockEntry = TranslatorsInit.getBlockTranslator().getBlockEntry(blockState); Vector3i pos = Vector3i.from(position.getX(), position.getY(), position.getZ()); + updateBlock(session, blockState, pos); + } + + public static void updateBlock(GeyserSession session, BlockState blockState, Vector3i position) { + BlockEntry blockEntry = TranslatorsInit.getBlockTranslator().getBlockEntry(blockState); UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket(); updateBlockPacket.setDataLayer(0); - updateBlockPacket.setBlockPosition(pos); + updateBlockPacket.setBlockPosition(position); updateBlockPacket.setRuntimeId(blockEntry.getBedrockRuntimeId()); updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS); session.getUpstream().sendPacket(updateBlockPacket); UpdateBlockPacket waterPacket = new UpdateBlockPacket(); waterPacket.setDataLayer(1); - waterPacket.setBlockPosition(pos); + waterPacket.setBlockPosition(position); if (blockEntry.isWaterlogged()) { BlockEntry water = TranslatorsInit.getBlockTranslator().getBlockEntry("minecraft:water[level=0]"); waterPacket.setRuntimeId(water.getBedrockRuntimeId()); @@ -101,11 +104,6 @@ public class ChunkUtils { public static void sendEmptyChunks(GeyserSession session, Vector3i position, int radius, boolean forceUpdate) { int chunkX = position.getX() >> 4; int chunkZ = position.getZ() >> 4; - NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket(); - chunkPublisherUpdatePacket.setPosition(position); - chunkPublisherUpdatePacket.setRadius(radius + 1 << 4); - session.getUpstream().sendPacket(chunkPublisherUpdatePacket); - session.setLastChunkPosition(null); for (int x = -radius; x <= radius; x++) { for (int z = -radius; z <= radius; z++) { LevelChunkPacket data = new LevelChunkPacket(); @@ -120,7 +118,7 @@ public class ChunkUtils { Vector3i pos = Vector3i.from(chunkX + x << 4, 80, chunkZ + z << 4); UpdateBlockPacket blockPacket = new UpdateBlockPacket(); blockPacket.setBlockPosition(pos); - blockPacket.setDataLayer(1); + blockPacket.setDataLayer(0); blockPacket.setRuntimeId(1); session.getUpstream().sendPacket(blockPacket); } diff --git a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java index b90aa2352..8d3b96837 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java @@ -50,6 +50,7 @@ public class Toolbox { public static final Int2ObjectMap ITEM_ENTRIES = new Int2ObjectOpenHashMap<>(); public static final Int2ObjectMap BLOCK_ENTRIES = new Int2ObjectOpenHashMap<>(); + public static final Map JAVA_IDENTIFIER_TO_ENTRY = new HashMap<>(); public static void init() { InputStream stream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/runtime_block_states.dat"); @@ -140,6 +141,7 @@ public class Toolbox { } BlockEntry blockEntry = new BlockEntry(javaEntry.getKey(), javaIndex, bedrockIndex); BLOCK_ENTRIES.put(javaIndex, blockEntry); + JAVA_IDENTIFIER_TO_ENTRY.put(javaEntry.getKey(), blockEntry); continue javaLoop; } } From 516fc51162d12da5f4828aabc075b4d80f9683ff Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Wed, 5 Feb 2020 20:23:06 -0900 Subject: [PATCH 05/21] Small changes --- .../connector/network/translators/block/BlockTranslator.java | 2 +- .../translators/java/world/JavaChunkDataTranslator.java | 4 ++-- .../src/main/java/org/geysermc/connector/utils/Toolbox.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java index e42891714..c0a8aa9a8 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java @@ -34,6 +34,6 @@ public class BlockTranslator { } public BlockEntry getBlockEntry(String javaIdentifier) { - return Toolbox.JAVA_IDENTIFIER_TO_ENTRY.get(javaIdentifier); + return Toolbox.JAVA_IDENTIFIER_TO_BLOCK_ENTRY.get(javaIdentifier); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java index 90467b6b8..7dbf92854 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java @@ -77,13 +77,13 @@ public class JavaChunkDataTranslator extends PacketTranslator ITEM_ENTRIES = new Int2ObjectOpenHashMap<>(); public static final Int2ObjectMap BLOCK_ENTRIES = new Int2ObjectOpenHashMap<>(); - public static final Map JAVA_IDENTIFIER_TO_ENTRY = new HashMap<>(); + public static final Map JAVA_IDENTIFIER_TO_BLOCK_ENTRY = new HashMap<>(); public static void init() { InputStream stream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/runtime_block_states.dat"); @@ -141,7 +141,7 @@ public class Toolbox { } BlockEntry blockEntry = new BlockEntry(javaEntry.getKey(), javaIndex, bedrockIndex); BLOCK_ENTRIES.put(javaIndex, blockEntry); - JAVA_IDENTIFIER_TO_ENTRY.put(javaEntry.getKey(), blockEntry); + JAVA_IDENTIFIER_TO_BLOCK_ENTRY.put(javaEntry.getKey(), blockEntry); continue javaLoop; } } From 3615ec2b909aea7c0e651d7c69f1b3a905ccdd48 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Mon, 10 Feb 2020 18:24:09 -0900 Subject: [PATCH 06/21] Fix ChunkPosition --- .../connector/world/chunk/ChunkPosition.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/world/chunk/ChunkPosition.java b/connector/src/main/java/org/geysermc/connector/world/chunk/ChunkPosition.java index 840e2f5d9..cafb7ab04 100644 --- a/connector/src/main/java/org/geysermc/connector/world/chunk/ChunkPosition.java +++ b/connector/src/main/java/org/geysermc/connector/world/chunk/ChunkPosition.java @@ -27,12 +27,14 @@ package org.geysermc.connector.world.chunk; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @Getter @Setter @AllArgsConstructor +@EqualsAndHashCode public class ChunkPosition { private int x; @@ -43,16 +45,9 @@ public class ChunkPosition { } public Position getChunkBlock(int x, int y, int z) { - int chunkX = x % 16; - int chunkY = y % 16; - int chunkZ = z % 16; - - if (chunkX < 0) - chunkX = -chunkX; - if (chunkY < 0) - chunkY = -chunkY; - if (chunkZ < 0) - chunkZ = -chunkZ; + int chunkX = x & 15; + int chunkY = y & 15; + int chunkZ = z & 15; return new Position(chunkX, chunkY, chunkZ); } From 7f194b2d549a061f9bb2c8de9656226939bde59a Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Tue, 11 Feb 2020 13:42:02 -0900 Subject: [PATCH 07/21] Increase render distance instead of chunkpublisher radius --- .../connector/network/session/GeyserSession.java | 10 +++------- .../java/world/JavaUpdateViewPositionTranslator.java | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) 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 271c2b9f3..0165f854e 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 @@ -37,11 +37,11 @@ import com.github.steveice10.packetlib.event.session.PacketReceivedEvent; import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.tcp.TcpSessionFactory; +import com.nukkitx.math.GenericMath; +import com.nukkitx.math.TrigMath; import com.nukkitx.math.vector.Vector2f; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3i; -import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTInputStream; import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.protocol.bedrock.BedrockServerSession; import com.nukkitx.protocol.bedrock.data.GamePublishSetting; @@ -54,7 +54,6 @@ import org.geysermc.api.RemoteServer; import org.geysermc.api.session.AuthData; import org.geysermc.api.window.FormWindow; import org.geysermc.connector.GeyserConnector; -import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.inventory.PlayerInventory; import org.geysermc.connector.network.session.cache.*; @@ -63,7 +62,6 @@ import org.geysermc.connector.network.translators.block.BlockTranslator; import org.geysermc.connector.utils.ChunkUtils; import org.geysermc.connector.utils.Toolbox; -import java.io.InputStream; import java.net.InetSocketAddress; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; @@ -89,7 +87,6 @@ public class GeyserSession implements Player { private DataCache javaPacketCache; private int renderDistance; - private int chunkPublisherRadius; private boolean loggedIn; private boolean loggingIn; @@ -272,11 +269,10 @@ public class GeyserSession implements Player { } public void setRenderDistance(int renderDistance) { + renderDistance = GenericMath.ceil(++renderDistance * TrigMath.SQRT_OF_TWO); //square to circle if (renderDistance > 32) renderDistance = 32; // <3 u ViaVersion but I don't like crashing clients x) this.renderDistance = renderDistance; - chunkPublisherRadius = renderDistance * 3/2 << 4; //some chunks are ignored if this isn't increased - ChunkRadiusUpdatedPacket chunkRadiusUpdatedPacket = new ChunkRadiusUpdatedPacket(); chunkRadiusUpdatedPacket.setRadius(renderDistance); upstream.sendPacket(chunkRadiusUpdatedPacket); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java index 6761d2b38..ebe9062fa 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java @@ -37,7 +37,7 @@ public class JavaUpdateViewPositionTranslator extends PacketTranslator Date: Fri, 14 Feb 2020 17:27:08 -0600 Subject: [PATCH 08/21] Fix interact and attack in interact translator --- .../translators/bedrock/BedrockInteractTranslator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java index cfac373ca..b7f7e5ff7 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java @@ -44,12 +44,12 @@ public class BedrockInteractTranslator extends PacketTranslator return; switch (packet.getAction()) { - case NONE: + case UNKNOWN_1: // interact ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(), InteractAction.INTERACT, Hand.MAIN_HAND); session.getDownstream().getSession().send(interactPacket); break; - case UNKNOWN_1: + case DAMAGE: ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(), InteractAction.ATTACK, Hand.MAIN_HAND); session.getDownstream().getSession().send(attackPacket); From 4186715083eedc54bb1f5730bb1d135951482843 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Fri, 14 Feb 2020 17:39:26 -0600 Subject: [PATCH 09/21] Update to NukkitX Protocol Lib 2.5.0 release --- connector/pom.xml | 2 +- .../network/LoggingPacketHandler.java | 5 --- .../network/session/GeyserSession.java | 4 +-- .../bedrock/BedrockRespawnTranslator.java | 4 +-- .../inventory/GenericInventoryTranslator.java | 4 +-- .../entity/JavaEntityStatusTranslator.java | 31 ++++++++++--------- .../JavaPlayerPositionRotationTranslator.java | 5 +-- .../world/JavaNotifyClientTranslator.java | 5 +-- .../org/geysermc/connector/utils/Toolbox.java | 6 ++-- 9 files changed, 32 insertions(+), 34 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index cb0f2686e..3b13cff75 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -67,7 +67,7 @@ com.nukkitx.protocol bedrock-v389 - 2.4.6-SNAPSHOT + 2.5.0 compile diff --git a/connector/src/main/java/org/geysermc/connector/network/LoggingPacketHandler.java b/connector/src/main/java/org/geysermc/connector/network/LoggingPacketHandler.java index 313e7adcf..91b3ebd40 100644 --- a/connector/src/main/java/org/geysermc/connector/network/LoggingPacketHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/LoggingPacketHandler.java @@ -192,11 +192,6 @@ public class LoggingPacketHandler implements BedrockPacketHandler { return defaultHandler(packet); } - @Override - public boolean handle(LevelSoundEvent3Packet packet) { - return defaultHandler(packet); - } - @Override public boolean handle(MapInfoRequestPacket packet) { return defaultHandler(packet); 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 7b8a93983..887cdd255 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 @@ -44,7 +44,7 @@ import com.nukkitx.math.vector.Vector3i; import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.protocol.bedrock.BedrockServerSession; import com.nukkitx.protocol.bedrock.data.GamePublishSetting; -import com.nukkitx.protocol.bedrock.data.GameRule; +import com.nukkitx.protocol.bedrock.data.GameRuleData; import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.packet.*; import lombok.Getter; @@ -297,7 +297,7 @@ public class GeyserSession implements Player { startGamePacket.setLightningLevel(0); startGamePacket.setMultiplayerGame(true); startGamePacket.setBroadcastingToLan(true); - startGamePacket.getGamerules().add(new GameRule<>("showcoordinates", true)); + startGamePacket.getGamerules().add(new GameRuleData<>("showcoordinates", true)); startGamePacket.setPlatformBroadcastMode(GamePublishSetting.PUBLIC); startGamePacket.setXblBroadcastMode(GamePublishSetting.PUBLIC); startGamePacket.setCommandsEnabled(true); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockRespawnTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockRespawnTranslator.java index 851070571..298914ad4 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockRespawnTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockRespawnTranslator.java @@ -36,11 +36,11 @@ public class BedrockRespawnTranslator extends PacketTranslator { @Override public void translate(RespawnPacket packet, GeyserSession session) { - if (packet.getSpawnState() == RespawnPacket.State.CLIENT_READY) { + if (packet.getState() == RespawnPacket.State.CLIENT_READY) { RespawnPacket respawnPacket = new RespawnPacket(); respawnPacket.setRuntimeEntityId(0); respawnPacket.setPosition(Vector3f.ZERO); - respawnPacket.setSpawnState(RespawnPacket.State.SERVER_SEARCHING); + respawnPacket.setState(RespawnPacket.State.SERVER_SEARCHING); session.getUpstream().sendPacket(respawnPacket); ClientRequestPacket javaRespawnPacket = new ClientRequestPacket(ClientRequest.RESPAWN); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/GenericInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/GenericInventoryTranslator.java index 8f74c4ddd..754d05c67 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/GenericInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/GenericInventoryTranslator.java @@ -67,8 +67,8 @@ public class GenericInventoryTranslator extends InventoryTranslator { public void updateSlot(GeyserSession session, Inventory inventory, int slot) { InventorySlotPacket slotPacket = new InventorySlotPacket(); slotPacket.setContainerId(inventory.getId()); - slotPacket.setSlot(TranslatorsInit.getItemTranslator().translateToBedrock(inventory.getItems()[slot])); - slotPacket.setInventorySlot(slot); + slotPacket.setItem(TranslatorsInit.getItemTranslator().translateToBedrock(inventory.getItems()[slot])); + slotPacket.setSlot(slot); session.getUpstream().sendPacket(slotPacket); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java index 389c21dba..2865b14c7 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java @@ -26,6 +26,7 @@ package org.geysermc.connector.network.translators.java.entity; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket; +import com.nukkitx.protocol.bedrock.data.EntityEventType; import com.nukkitx.protocol.bedrock.packet.EntityEventPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; @@ -47,48 +48,48 @@ public class JavaEntityStatusTranslator extends PacketTranslator> bedrockStates = blockTag.getAsCompound("states").getValue(); + Map> bedrockStates = blockTag.getCompound("states").getValue(); for (Map.Entry stateEntry : wantedStates.entrySet()) { Tag bedrockStateTag = bedrockStates.get(stateEntry.getKey()); if (bedrockStateTag == null) From ee85abf34c18df9ea70e5b45e57fd3b75f798d54 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 15 Feb 2020 17:39:34 -0600 Subject: [PATCH 10/21] Fix player movement not being visible, movement bugs and laggy entities (Addresses #74, #109) --- .../org/geysermc/connector/entity/Entity.java | 44 +++++++++++-------- .../connector/entity/PlayerEntity.java | 35 +++++++++++++++ .../network/session/cache/EntityCache.java | 1 - .../bedrock/BedrockMovePlayerTranslator.java | 9 ++-- .../entity/JavaEntityHeadLookTranslator.java | 23 +++++++--- .../JavaEntityPositionRotationTranslator.java | 14 +----- .../entity/JavaEntityPositionTranslator.java | 16 +------ .../entity/JavaEntityRotationTranslator.java | 14 ++++-- .../entity/JavaEntityTeleportTranslator.java | 16 +------ .../JavaPlayerPositionRotationTranslator.java | 16 +------ 10 files changed, 97 insertions(+), 91 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index 80b477d52..7c72368f0 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -65,7 +65,6 @@ public class Entity { protected Vector3f rotation; protected float scale = 1; - protected boolean movePending; protected EntityType entityType; @@ -79,14 +78,14 @@ public class Entity { this.entityId = entityId; this.geyserId = geyserId; this.entityType = entityType; - this.position = position; this.motion = motion; this.rotation = rotation; this.valid = false; - this.movePending = false; this.dimension = 0; + setPosition(position); + metadata.put(EntityData.SCALE, 1f); metadata.put(EntityData.MAX_AIR, (short) 400); metadata.put(EntityData.AIR, (short) 0); @@ -132,25 +131,40 @@ public class Entity { return true; } - public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch) { - moveRelative(relX, relY, relZ, Vector3f.from(yaw, pitch, yaw)); + public void moveRelative(GeyserSession session, double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) { + moveRelative(session, relX, relY, relZ, Vector3f.from(yaw, pitch, yaw), isOnGround); } - public void moveRelative(double relX, double relY, double relZ, Vector3f rotation) { + public void moveRelative(GeyserSession session, double relX, double relY, double relZ, Vector3f rotation, boolean isOnGround) { setRotation(rotation); this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ); - this.movePending = true; + + MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket(); + moveEntityPacket.setRuntimeEntityId(geyserId); + moveEntityPacket.setPosition(position); + moveEntityPacket.setRotation(getBedrockRotation()); + moveEntityPacket.setOnGround(isOnGround); + moveEntityPacket.setTeleported(false); + + session.getUpstream().sendPacket(moveEntityPacket); } - public void moveAbsolute(Vector3f position, float yaw, float pitch) { - moveAbsolute(position, Vector3f.from(yaw, pitch, yaw)); + public void moveAbsolute(GeyserSession session, Vector3f position, float yaw, float pitch, boolean isOnGround) { + moveAbsolute(session, position, Vector3f.from(yaw, pitch, yaw), isOnGround); } - public void moveAbsolute(Vector3f position, Vector3f rotation) { + public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround) { setPosition(position); setRotation(rotation); - this.movePending = true; + MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket(); + moveEntityPacket.setRuntimeEntityId(geyserId); + moveEntityPacket.setPosition(position); + moveEntityPacket.setRotation(getBedrockRotation()); + moveEntityPacket.setOnGround(isOnGround); + moveEntityPacket.setTeleported(false); + + session.getUpstream().sendPacket(moveEntityPacket); } public void updateBedrockAttributes(GeyserSession session) { @@ -216,14 +230,6 @@ public class Entity { session.getUpstream().sendPacket(entityDataPacket); } - public void setPosition(Vector3f position) { - if (is(PlayerEntity.class)) { - this.position = position.add(0, entityType.getOffset(), 0); - return; - } - this.position = position; - } - /** * x = Pitch, y = HeadYaw, z = Yaw */ diff --git a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java index 120b49ef7..49af65546 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java @@ -30,6 +30,7 @@ import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.CommandPermission; import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket; +import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; import lombok.Getter; import lombok.Setter; @@ -115,4 +116,38 @@ public class PlayerEntity extends LivingEntity { }); } } + + @Override + public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround) { + setPosition(position); + setRotation(rotation); + + MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); + movePlayerPacket.setRuntimeEntityId(geyserId); + movePlayerPacket.setPosition(this.position); + movePlayerPacket.setRotation(getBedrockRotation()); + movePlayerPacket.setOnGround(isOnGround); + movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL); + + session.getUpstream().sendPacket(movePlayerPacket); + } + + @Override + public void moveRelative(GeyserSession session, double relX, double relY, double relZ, Vector3f rotation, boolean isOnGround) { + setRotation(rotation); + this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ); + + MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); + movePlayerPacket.setRuntimeEntityId(geyserId); + movePlayerPacket.setPosition(position); + movePlayerPacket.setRotation(getBedrockRotation()); + movePlayerPacket.setOnGround(isOnGround); + movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL); + session.getUpstream().sendPacket(movePlayerPacket); + } + + @Override + public void setPosition(Vector3f position) { + this.position = position.add(0, entityType.getOffset(), 0); + } } diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java index 2834cb909..bbd714e2f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java @@ -55,7 +55,6 @@ public class EntityCache { } public void spawnEntity(Entity entity) { - entity.moveAbsolute(entity.getPosition(), entity.getRotation().getX(), entity.getRotation().getY()); cacheEntity(entity); entity.spawnEntity(session); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java index 37b517d30..d89060f6a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java @@ -61,8 +61,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator Date: Sat, 15 Feb 2020 19:06:18 -0600 Subject: [PATCH 11/21] Fix teleportation --- .../java/entity/JavaEntityPositionRotationTranslator.java | 1 - .../java/entity/player/JavaPlayerPositionRotationTranslator.java | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java index 6859c1fd9..7319c5612 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java @@ -26,7 +26,6 @@ package org.geysermc.connector.network.translators.java.entity; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket; -import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java index c54735438..9d81ce797 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java @@ -83,6 +83,7 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator Date: Sun, 16 Feb 2020 12:40:54 -0600 Subject: [PATCH 12/21] Fix movement bugs *and* allow for teleportation --- .../connector/network/session/GeyserSession.java | 6 ++++++ .../bedrock/BedrockActionTranslator.java | 10 ++++++++++ .../JavaPlayerPositionRotationTranslator.java | 13 ++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) 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 c2618275c..ca4a65ca3 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 @@ -100,6 +100,12 @@ public class GeyserSession implements Player { @Setter private GameMode gameMode = GameMode.SURVIVAL; + @Setter + private boolean sprinting; + + @Setter + private boolean jumping; + @Setter private boolean switchingDimension = false; private boolean manyDimPackets = false; 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 56e573c69..981e569bd 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 @@ -40,6 +40,8 @@ import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import java.util.concurrent.TimeUnit; + public class BedrockActionTranslator extends PacketTranslator { @Override @@ -72,10 +74,12 @@ public class BedrockActionTranslator extends PacketTranslator { + session.setJumping(false); + }, 1, TimeUnit.SECONDS); + break; } } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java index 9d81ce797..724cb5e04 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java @@ -30,6 +30,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.Serv import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.EntityEventType; import com.nukkitx.protocol.bedrock.packet.*; + import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.type.EntityType; @@ -83,7 +84,17 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator 1.5 || (yDis < 1.45 || yDis > (session.isJumping() ? 4.3 : (session.isSprinting() ? 2.5 : 1.9))) || zDis > 1.5) { + entity.moveAbsolute(session, Vector3f.from(packet.getX(), packet.getY() + 0.6f, packet.getZ()), packet.getYaw(), packet.getPitch(), true); + } + } ClientTeleportConfirmPacket teleportConfirmPacket = new ClientTeleportConfirmPacket(packet.getTeleportId()); session.getDownstream().getSession().send(teleportConfirmPacket); From f87ff70369b23298a4fdd51c0b22a0592e0d83e3 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 16 Feb 2020 13:07:35 -0600 Subject: [PATCH 13/21] Update to NukkitX Protocol Lib 2.5.1 --- connector/pom.xml | 2 +- .../network/translators/bedrock/BedrockInteractTranslator.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index 3b13cff75..cff4c87a2 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -67,7 +67,7 @@ com.nukkitx.protocol bedrock-v389 - 2.5.0 + 2.5.1 compile diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java index b7f7e5ff7..ab73e9bb1 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java @@ -44,7 +44,7 @@ public class BedrockInteractTranslator extends PacketTranslator return; switch (packet.getAction()) { - case UNKNOWN_1: // interact + case INTERACT: ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(), InteractAction.INTERACT, Hand.MAIN_HAND); session.getDownstream().getSession().send(interactPacket); From 720f69d9136ddc4487ecbc6488a526b16601ec47 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 16 Feb 2020 14:07:40 -0600 Subject: [PATCH 14/21] Set can climb for entity to false --- .../src/main/java/org/geysermc/connector/entity/Entity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index 7c72368f0..9150b0710 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -96,7 +96,7 @@ public class Entity { flags.setFlag(EntityFlag.HAS_GRAVITY, true); flags.setFlag(EntityFlag.HAS_COLLISION, true); flags.setFlag(EntityFlag.CAN_SHOW_NAME, true); - flags.setFlag(EntityFlag.CAN_CLIMB, true); + flags.setFlag(EntityFlag.CAN_CLIMB, false); metadata.putFlags(flags); } From d11199c3585f12d75c752bd4ecdec87646c458fe Mon Sep 17 00:00:00 2001 From: Redned Date: Sun, 16 Feb 2020 18:08:24 -0600 Subject: [PATCH 15/21] Add versions supported onto README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a94914db1..52dfb6533 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ Geyser is a bridge between Minecraft: Bedrock Edition and Minecraft: Java Editio ## What is Geyser? Geyser is a proxy, bridging the gap between Minecraft: Bedrock Edition and Minecraft: Java Edition servers. -The ultimate goal of this project is to allow Minecraft: Bedrock Edition users to join Minecraft: Java Edition servers as seamlessly as possible. +The ultimate goal of this project is to allow Minecraft: Bedrock Edition users to join Minecraft: Java Edition servers as seamlessly as possible. **Please note, this project is still a work in progress and should not be used on production. Expect bugs!** -### Please note, this project is still a work in progress and should not be used on production. Expect bugs! +### Currently supporting Minecraft Bedrock v1.14.X and Minecraft Java v1.15.2. ## Setting Up Please note, Geyser is **not** (currently) a plugin. Watch the video below or take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set it up. From b41d66dd194f160be482ee9ceecceaf72d44f6a7 Mon Sep 17 00:00:00 2001 From: Redned Date: Sun, 23 Feb 2020 18:02:54 -0600 Subject: [PATCH 16/21] Set can climb for entity back to true This has nothing to do with the bug where players can "climb" up blocks, but rather disabling this feature disables the ability to climb up vines and ladders. This commit reverts that. --- .../src/main/java/org/geysermc/connector/entity/Entity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index 9150b0710..7c72368f0 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -96,7 +96,7 @@ public class Entity { flags.setFlag(EntityFlag.HAS_GRAVITY, true); flags.setFlag(EntityFlag.HAS_COLLISION, true); flags.setFlag(EntityFlag.CAN_SHOW_NAME, true); - flags.setFlag(EntityFlag.CAN_CLIMB, false); + flags.setFlag(EntityFlag.CAN_CLIMB, true); metadata.putFlags(flags); } From 1af4d71bd1d6ccab48cd21c8a0167e86326640d1 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Mon, 24 Feb 2020 20:04:18 -0600 Subject: [PATCH 17/21] Remove extra height added to position when server corrects movement This should fix the bug where you can "climb" up blocks. Although this doesn't fix the random spasm the client gets, it should prevent players from climbing up blocks (and getting stuck in them), thus preventing anticheats from going crazy. --- .../entity/player/JavaPlayerPositionRotationTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java index 724cb5e04..c8c6ad47c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java @@ -92,7 +92,7 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator 1.5 || (yDis < 1.45 || yDis > (session.isJumping() ? 4.3 : (session.isSprinting() ? 2.5 : 1.9))) || zDis > 1.5) { - entity.moveAbsolute(session, Vector3f.from(packet.getX(), packet.getY() + 0.6f, packet.getZ()), packet.getYaw(), packet.getPitch(), true); + entity.moveAbsolute(session, Vector3f.from(packet.getX(), packet.getY(), packet.getZ()), packet.getYaw(), packet.getPitch(), true); } } From f0e01ab1c9427d7028ede5574a3a712a4e826710 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Tue, 25 Feb 2020 18:50:09 -0600 Subject: [PATCH 18/21] Fix getting stuck in wall bug Due to java doubles being somewhat more "precise" and bedrock positions being sent in floats instead, this caused bedrock players to get stuck in blocks when jumping or running near them in a certain way, thus causing the server to try and correct their position, potentially flagging anticheats and causing the server to print a "moved wrongly" message in console. See: https://stackoverflow.com/questions/322749/retain-precision-with-double-in-java --- .../translators/bedrock/BedrockMovePlayerTranslator.java | 4 ++-- .../player/JavaPlayerPositionRotationTranslator.java | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java index d89060f6a..12e61de55 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java @@ -26,6 +26,7 @@ package org.geysermc.connector.network.translators.bedrock; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket; +import com.nukkitx.math.GenericMath; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; @@ -63,8 +64,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator 1.5 || (yDis < 1.45 || yDis > (session.isJumping() ? 4.3 : (session.isSprinting() ? 2.5 : 1.9))) || zDis > 1.5) { entity.moveAbsolute(session, Vector3f.from(packet.getX(), packet.getY(), packet.getZ()), packet.getYaw(), packet.getPitch(), true); } From 2c91ce14a276cdcafdde7ac002c9c8ccece212fe Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Tue, 25 Feb 2020 19:09:53 -0600 Subject: [PATCH 19/21] Remove 'Proper Movement' needing implementation from README --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 52dfb6533..ed53e5fe5 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,6 @@ Please note, Geyser is **not** (currently) a plugin. Watch the video below or ta - Block Particles - Block Entities ([`block-entities`](https://github.com/GeyserMC/Geyser/tree/block-entities)) - Some Entity Flags -- Proper Movement - Support to be Ran as a Plugin ([`plugin`](https://github.com/GeyserMC/Geyser/tree/plugin)) ## Compiling From 4c87a13e251d121bb6b80b0d42c20c7474543791 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Tue, 25 Feb 2020 19:36:36 -0600 Subject: [PATCH 20/21] Snap height only if on ground (Original commit 2dc6ab453f931ac2083a6d142e963beb0a101b94) --- .../translators/bedrock/BedrockMovePlayerTranslator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java index 06ac369d3..15374c6d6 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMovePlayerTranslator.java @@ -62,7 +62,8 @@ public class BedrockMovePlayerTranslator extends PacketTranslator Date: Tue, 25 Feb 2020 19:52:27 -0600 Subject: [PATCH 21/21] Make sure scale is not null when setting armor stand as baby If it's null, it's invisible. --- .../org/geysermc/connector/entity/living/ArmorStandEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/ArmorStandEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/ArmorStandEntity.java index 6dd77d739..1beb8ab8f 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/ArmorStandEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/ArmorStandEntity.java @@ -43,7 +43,7 @@ public class ArmorStandEntity extends LivingEntity { public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { if (entityMetadata.getType() == MetadataType.BYTE) { byte xd = (byte) entityMetadata.getValue(); - if((xd & 0x01) == 0x01 && !(metadata.get(EntityData.SCALE).equals(0.0f))) { + if ((xd & 0x01) == 0x01 && (metadata.get(EntityData.SCALE) != null && !metadata.get(EntityData.SCALE).equals(0.0f))) { metadata.put(EntityData.SCALE, .55f); } }