Exemplo n.º 1
0
        void HandleMovement(byte[] buffer, int offset)
        {
            if (!loggedIn || trainGrab || following.Length > 0)
            {
                CheckBlocks(Pos); return;
            }
            if (Supports(CpeExt.HeldBlock))
            {
                RawHeldBlock = ExtBlock.FromRaw(buffer[offset + 1]);
            }

            int x, y, z;

            if (hasExtPositions)
            {
                x       = NetUtils.ReadI32(buffer, offset + 2);
                y       = NetUtils.ReadI32(buffer, offset + 6);
                z       = NetUtils.ReadI32(buffer, offset + 10);
                offset += 6; // for yaw/pitch offset below
            }
            else
            {
                x = NetUtils.ReadI16(buffer, offset + 2);
                y = NetUtils.ReadI16(buffer, offset + 4);
                z = NetUtils.ReadI16(buffer, offset + 6);
            }

            byte     yaw = buffer[offset + 8], pitch = buffer[offset + 9];
            Position next = new Position(x, y, z);

            CheckBlocks(next);

            OnPlayerMoveEvent.Call(this, next, yaw, pitch);
            if (cancelmove)
            {
                cancelmove = false; return;
            }

            Pos = next;
            SetYawPitch(yaw, pitch);
            if (!Moved() || Loading)
            {
                return;
            }
            if (DateTime.UtcNow < AFKCooldown)
            {
                return;
            }

            LastAction = DateTime.UtcNow;
            if (IsAfk)
            {
                CmdAfk.ToggleAfk(this, "");
            }
        }
Exemplo n.º 2
0
        public void ProcessMovement(int x, int y, int z, byte yaw, byte pitch, int held)
        {
            if (held >= 0)
            {
                ClientHeldBlock = (BlockID)held;
            }

            if (trainGrab || following.Length > 0)
            {
                CheckBlocks(Pos, Pos); return;
            }
            Position next = new Position(x, y, z);

            CheckBlocks(Pos, next);

            bool cancel = false;

            OnPlayerMoveEvent.Call(this, next, yaw, pitch, ref cancel);
            if (cancel)
            {
                cancel = false; return;
            }

            Pos = next;
            SetYawPitch(yaw, pitch);
            CheckZones(next);

            if (!Moved() || Loading)
            {
                return;
            }
            if (DateTime.UtcNow < AFKCooldown)
            {
                return;
            }

            LastAction = DateTime.UtcNow;
            if (IsAfk)
            {
                CmdAfk.ToggleAfk(this, "");
            }
        }