Пример #1
0
        /// <summary>
        /// Send a location update to the server
        /// </summary>
        /// <param name="location">The new location of the player</param>
        /// <param name="onGround">True if the player is on the ground</param>
        /// <param name="yaw">Optional new yaw for updating player look</param>
        /// <param name="pitch">Optional new pitch for updating player look</param>
        /// <returns>True if the location update was successfully sent</returns>
        public bool SendLocationUpdate(Location location, bool onGround, float?yaw = null, float?pitch = null)
        {
            if (handler.GetTerrainEnabled())
            {
                byte[]             yawpitch   = new byte[0];
                PacketOutgoingType packetType = PacketOutgoingType.PlayerPosition;

                if (yaw.HasValue && pitch.HasValue)
                {
                    yawpitch   = dataTypes.ConcatBytes(dataTypes.GetFloat(yaw.Value), dataTypes.GetFloat(pitch.Value));
                    packetType = PacketOutgoingType.PlayerPositionAndLook;
                }

                try
                {
                    SendPacket(packetType, dataTypes.ConcatBytes(
                                   dataTypes.GetDouble(location.X),
                                   dataTypes.GetDouble(location.Y),
                                   protocolversion < MC18Version
                            ? dataTypes.GetDouble(location.Y + 1.62)
                            : new byte[0],
                                   dataTypes.GetDouble(location.Z),
                                   yawpitch,
                                   new byte[] { onGround ? (byte)1 : (byte)0 }));
                    return(true);
                }
                catch (SocketException) { return(false); }
            }
            else
            {
                return(false);
            }
        }