/// <summary> /// Called from the main game loop to update the screen. /// </summary> public override void UpdateScreen() { UpdateCounter++; if (UpdateCounter % 20 == 0) { NetHandler.AddToSendQueue(new Packet0KeepAlive()); } if (NetHandler != null) { NetHandler.ProcessReadPackets(); } }
/// <summary> /// Send updated motion and position information to the server /// </summary> public virtual void SendMotionUpdates() { if (InventoryUpdateTickCounter++ == 20) { InventoryUpdateTickCounter = 0; } bool flag = IsSprinting(); if (flag != WasSneaking) { if (flag) { SendQueue.AddToSendQueue(new Packet19EntityAction(this, 4)); } else { SendQueue.AddToSendQueue(new Packet19EntityAction(this, 5)); } WasSneaking = flag; } bool flag1 = IsSneaking(); if (flag1 != ShouldStopSneaking) { if (flag1) { SendQueue.AddToSendQueue(new Packet19EntityAction(this, 1)); } else { SendQueue.AddToSendQueue(new Packet19EntityAction(this, 2)); } ShouldStopSneaking = flag1; } double d = PosX - OldPosX; double d1 = BoundingBox.MinY - OldMinY; double d2 = PosY - OldPosY; double d3 = PosZ - OldPosZ; double d4 = RotationYaw - OldRotationYaw; double d5 = RotationPitch - OldRotationPitch; bool flag2 = d1 != 0.0F || d2 != 0.0F || d != 0.0F || d3 != 0.0F; bool flag3 = d4 != 0.0F || d5 != 0.0F; if (RidingEntity != null) { if (flag3) { SendQueue.AddToSendQueue(new Packet11PlayerPosition(MotionX, -999D, -999D, MotionZ, OnGround)); } else { SendQueue.AddToSendQueue(new Packet13PlayerLookMove(MotionX, -999D, -999D, MotionZ, RotationYaw, RotationPitch, OnGround)); } flag2 = false; } else if (flag2 && flag3) { SendQueue.AddToSendQueue(new Packet13PlayerLookMove(PosX, BoundingBox.MinY, PosY, PosZ, RotationYaw, RotationPitch, OnGround)); TimeSinceMoved = 0; } else if (flag2) { SendQueue.AddToSendQueue(new Packet11PlayerPosition(PosX, BoundingBox.MinY, PosY, PosZ, OnGround)); TimeSinceMoved = 0; } else if (flag3) { SendQueue.AddToSendQueue(new Packet12PlayerLook(RotationYaw, RotationPitch, OnGround)); TimeSinceMoved = 0; } else { SendQueue.AddToSendQueue(new Packet10Flying(OnGround)); if (WasOnGround != OnGround || TimeSinceMoved > 200) { TimeSinceMoved = 0; } else { TimeSinceMoved++; } } WasOnGround = OnGround; if (flag2) { OldPosX = PosX; OldMinY = BoundingBox.MinY; OldPosY = PosY; OldPosZ = PosZ; } if (flag3) { OldRotationYaw = RotationYaw; OldRotationPitch = RotationPitch; } }