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 5da206992..612a8e3d2 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -33,6 +33,7 @@ import com.nukkitx.protocol.bedrock.data.EntityFlag; import com.nukkitx.protocol.bedrock.data.EntityFlags; import com.nukkitx.protocol.bedrock.packet.AddEntityPacket; import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket; +import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket; import lombok.Getter; import lombok.Setter; @@ -136,7 +137,6 @@ public class Entity { this.movePending = true; } - public EntityDataDictionary getMetadata() { EntityFlags flags = new EntityFlags(); flags.setFlag(EntityFlag.HAS_GRAVITY, true); @@ -169,6 +169,11 @@ public class Entity { updateAttributesPacket.setRuntimeEntityId(geyserId); updateAttributesPacket.setAttributes(attributes); session.getUpstream().sendPacket(updateAttributesPacket); + + SetEntityDataPacket entityDataPacket = new SetEntityDataPacket(); + entityDataPacket.setRuntimeEntityId(geyserId); + entityDataPacket.getMetadata().putAll(getMetadata()); + session.getUpstream().sendPacket(entityDataPacket); } // To be used at a later date diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index 5525fb0e9..b0f62d62b 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -79,7 +79,8 @@ public enum EntityType { AGENT(56, 0f), VINDICATOR(57, 1.8f, 0.6f, 0.6f, 1.62f), PILLAGER(114, 1.8f, 0.6f, 0.6f, 1.62f), - WANDERING_VILLAGER(118, 1.8f, 0.6f, 0.6f, 1.62f), + WANDERING_TRADER(118, 1.8f, 0.6f, 0.6f, 1.62f), + PHANTOM(58, 0.5f, 0.9f, 0.9f, 0.6f), RAVAGER(59, 1.9f, 1.2f), ARMOR_STAND(61, 0f), 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 8c031f932..f1dfc2105 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 @@ -25,9 +25,11 @@ package org.geysermc.connector.network.translators.bedrock; +import com.flowpowered.math.vector.Vector3f; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket; import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; +import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; @@ -42,6 +44,15 @@ public class BedrockMovePlayerTranslator extends PacketTranslator 10 || yRange > 10 || zRange > 10) { + session.getConnector().getLogger().warning(session.getName() + " moved too quickly." + + " current position: " + currentPosition + ", new position: " + newPosition); + + return false; + } + + return true; + } + + public void recalculatePosition(GeyserSession session, Entity entity, Vector3f currentPosition) { + // Gravity might need to be reset... + SetEntityDataPacket entityDataPacket = new SetEntityDataPacket(); + entityDataPacket.setRuntimeEntityId(entity.getGeyserId()); + entityDataPacket.getMetadata().putAll(entity.getMetadata()); + session.getUpstream().sendPacket(entityDataPacket); + + MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); + movePlayerPacket.setRuntimeEntityId(entity.getGeyserId()); + movePlayerPacket.setPosition(entity.getPosition()); + movePlayerPacket.setRotation(entity.getRotation()); + movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL); + movePlayerPacket.setOnGround(true); + entity.setMovePending(false); + session.getUpstream().sendPacket(movePlayerPacket); + } } 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 2a6ef2fc9..025f0b516 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 @@ -30,7 +30,13 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket; import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; +import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; +import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket; +import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket; +import org.geysermc.connector.console.GeyserLogger; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.TranslatorsInit; @@ -43,11 +49,6 @@ public class JavaJoinGameTranslator extends PacketTranslator> 4; int chunkZ = pos.getFloorZ() >> 4; @@ -64,6 +65,25 @@ public class JavaJoinGameTranslator extends PacketTranslator