/// <summary> /// Called ~10 times per second by the protocol handler /// </summary> public void OnUpdate() { timer++; foreach (var bot in bots.ToArray()) { try { bot.Update(); bot.ProcessQueuedText(); } catch (Exception e) { if (!(e is ThreadAbortException)) { ConsoleIO.WriteLineFormatted("§8Update: Got error from " + bot.ToString() + ": " + e.ToString()); } else { throw; //ThreadAbortException should not be caught } } } if (Settings.TerrainAndMovements && locationReceived) { lock (locationLock) { for (int i = 0; i < 2; i++) //Needs to run at 20 tps; MCC runs at 10 tps { if (yawpitch == null) { if (steps != null && steps.Count > 0) { location = steps.Dequeue(); } else if (path != null && path.Count > 0) { steps = Movement.Move2Steps(location, path.Dequeue(), ref motionY); } else { location = Movement.HandleGravity(world, location, ref motionY); } } handler.SendLocationUpdate(location, Movement.IsOnGround(world, location), yawpitch); } yawpitch = null; //First 2 updates must be player position AND look, and player must not move (to conform with vanilla) } } else if (Settings.ItemPickup && timer > 15 && locationReceived) { timer = 0; for (int i = 0; i < 2; i++) { location = Movement.HandleGravity(world, location, ref motionY); handler.SendLocationUpdate(location, Movement.IsOnGround(world, location), yawpitch); } yawpitch = null; } }
/// <summary> /// Called ~10 times per second by the protocol handler /// </summary> public void OnUpdate() { foreach (var bot in bots.ToArray()) { try { bot.Update(); bot.ProcessQueuedText(); } catch (Exception e) { if (!(e is ThreadAbortException)) { ConsoleIO.WriteLineFormatted("§8Update: Got error from " + bot.ToString() + ": " + e.ToString()); } else { throw; //ThreadAbortException should not be caught } } } if (terrainAndMovementsEnabled && locationReceived) { lock (locationLock) { for (int i = 0; i < 2; i++) //Needs to run at 20 tps; MCC runs at 10 tps { if (yaw == null || pitch == null) { if (steps != null && steps.Count > 0) { location = steps.Dequeue(); } else if (path != null && path.Count > 0) { Location next = path.Dequeue(); steps = Movement.Move2Steps(location, next, ref motionY); UpdateLocation(location, next + new Location(0, 1, 0)); // Update yaw and pitch to look at next step } else { location = Movement.HandleGravity(world, location, ref motionY); } } handler.SendLocationUpdate(location, Movement.IsOnGround(world, location), yaw, pitch); } // First 2 updates must be player position AND look, and player must not move (to conform with vanilla) // Once yaw and pitch have been sent, switch back to location-only updates (without yaw and pitch) yaw = null; pitch = null; } } }
/// <summary> /// Called ~10 times per second by the protocol handler /// </summary> public void OnUpdate() { foreach (var bot in bots.ToArray()) { try { bot.Update(); bot.ProcessQueuedText(); } catch (Exception e) { if (!(e is ThreadAbortException)) { ConsoleIO.WriteLineFormatted("§8Update: Got error from " + bot.ToString() + ": " + e.ToString()); } else { throw; //ThreadAbortException should not be caught } } } if (Settings.TerrainAndMovements && locationReceived) { lock (locationLock) { for (int i = 0; i < 2; i++) //Needs to run at 20 tps; MCC runs at 10 tps { if (steps != null && steps.Count > 0) { location = steps.Dequeue(); } else if (path != null && path.Count > 0) { steps = Movement.Move2Steps(location, path.Dequeue()); } else { location = Movement.HandleGravity(world, location); } handler.SendLocationUpdate(location, Movement.IsOnGround(world, location)); } } } }
/// <summary> /// Move to the specified location /// </summary> /// <param name="location">Location to reach</param> /// <param name="allowUnsafe">Allow possible but unsafe locations</param> /// <returns>True if a path has been found</returns> public void OnUpdate() { UpdateLocation(); handler.SendLocationUpdate(location, false, null, null); }