From 4f461bf3744081bb16b7356d9e894dd34be89d9e Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Wed, 5 Feb 2020 18:55:34 -0600 Subject: [PATCH 01/12] 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: Fri, 14 Feb 2020 17:27:08 -0600 Subject: [PATCH 02/12] 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 03/12] 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 04/12] 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 05/12] 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 06/12] 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 07/12] 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 08/12] 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 b41d66dd194f160be482ee9ceecceaf72d44f6a7 Mon Sep 17 00:00:00 2001 From: Redned Date: Sun, 23 Feb 2020 18:02:54 -0600 Subject: [PATCH 09/12] 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 10/12] 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 11/12] 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 12/12] 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