From 1da130ab0717cffc39ffb35fee597586b25836b0 Mon Sep 17 00:00:00 2001 From: Heath123 Date: Mon, 8 Jun 2020 13:13:25 +0100 Subject: [PATCH] Fix initial movement speed (#751) Bedrock clients move very fast by default until they get an attribute packet correcting the speed. --- .../network/session/GeyserSession.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 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 db4d6aea3..a694cb517 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 @@ -46,10 +46,7 @@ import com.nukkitx.math.TrigMath; import com.nukkitx.math.vector.*; import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockServerSession; -import com.nukkitx.protocol.bedrock.data.ContainerId; -import com.nukkitx.protocol.bedrock.data.GamePublishSetting; -import com.nukkitx.protocol.bedrock.data.GameRuleData; -import com.nukkitx.protocol.bedrock.data.PlayerPermission; +import com.nukkitx.protocol.bedrock.data.*; import com.nukkitx.protocol.bedrock.packet.*; import it.unimi.dsi.fastutil.objects.Object2LongMap; import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; @@ -61,6 +58,7 @@ import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.command.CommandSender; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.PlayerEntity; +import org.geysermc.connector.entity.attribute.AttributeType; import org.geysermc.connector.inventory.PlayerInventory; import org.geysermc.connector.network.remote.RemoteServer; import org.geysermc.connector.network.session.auth.AuthData; @@ -82,6 +80,8 @@ import java.net.InetSocketAddress; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; import java.security.spec.InvalidKeySpecException; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; @@ -220,6 +220,15 @@ public class GeyserSession implements CommandSender { PlayStatusPacket playStatusPacket = new PlayStatusPacket(); playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN); upstream.sendPacket(playStatusPacket); + + UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); + attributesPacket.setRuntimeEntityId(getPlayerEntity().getGeyserId()); + List attributes = new ArrayList<>(); + // Default move speed + // Bedrock clients move very fast by default until they get an attribute packet correcting the speed + attributes.add(new Attribute("minecraft:movement", 0.0f, 1024f, 0.1f, 0.1f)); + attributesPacket.setAttributes(attributes); + upstream.sendPacket(attributesPacket); } public void fetchOurSkin(PlayerListPacket.Entry entry) {