From 99bb5c98def1ed21662519b61b3231d8c38f1be8 Mon Sep 17 00:00:00 2001 From: Tanner Date: Sun, 15 Nov 2026 15:18:12 +0000 Subject: [PATCH] Fix wood farming and block breaking stalls --- mosfet/game.py | 5 ++- mosfet/jobs/gather_wood.py | 62 +++++++++++++++++++++++++++++++++++++ mosfet/jobs/grab_sapling.py | 2 +- tests/test_break_time.py | 4 ++- 4 files changed, 70 insertions(+), 3 deletions(-) diff --git a/mosfet/game.py b/mosfet/game.py index f67d90e..0d894c8 100644 --- a/mosfet/game.py +++ b/mosfet/game.py @@ -682,6 +682,7 @@ class LegacyGame: # migrated actions use the 26.3 packet classes imported above. class Game(LegacyGame): ARM_SWING_INTERVAL = 0.1 + BREAK_FINISH_GRACE = 0.2 DOOR_AUTO_OPEN_GRACE = 0.25 DOOR_TURN_DURATION = 0.3 @@ -1045,7 +1046,9 @@ class Game(LegacyGame): self.g.breaking = location self.breaking_state = block_id now = time.monotonic() - self.break_deadline = now + duration + # A server tick and packet delay can otherwise make the client finish + # just before the server has accumulated the full mining progress. + self.break_deadline = now + duration + self.BREAK_FINISH_GRACE self.animate() self.next_swing_at = now + self.ARM_SWING_INTERVAL return True diff --git a/mosfet/jobs/gather_wood.py b/mosfet/jobs/gather_wood.py index 9637462..a892abd 100644 --- a/mosfet/jobs/gather_wood.py +++ b/mosfet/jobs/gather_wood.py @@ -8,6 +8,57 @@ from mosfet.info import items class GatherWoodStates: + NAVIGATION_STALL_TIMEOUT = 8.0 + NAVIGATION_PROGRESS_EPSILON = 0.15 + + def _path_head_distance(self): + if not self.g.path: + return None + waypoint = self.g.path[0] + return utils.hypot( + self.g.pos.x - (waypoint[0] + 0.5), + self.g.pos.z - (waypoint[2] + 0.5)) + + def _begin_navigation(self): + self.navigation_path_head = ( + tuple(self.g.path[0]) if self.g.path else None) + self.navigation_best_distance = self._path_head_distance() + self.navigation_last_progress_at = time.monotonic() + + def _clear_navigation(self): + self.navigation_path_head = None + self.navigation_best_distance = None + self.navigation_last_progress_at = None + + def _navigation_stalled(self): + now = time.monotonic() + path_head = tuple(self.g.path[0]) if self.g.path else None + distance = self._path_head_distance() + if path_head != self.navigation_path_head: + self.navigation_path_head = path_head + self.navigation_best_distance = distance + self.navigation_last_progress_at = now + elif (distance is not None and + (self.navigation_best_distance is None or + distance <= self.navigation_best_distance - + self.NAVIGATION_PROGRESS_EPSILON)): + self.navigation_best_distance = distance + self.navigation_last_progress_at = now + + return (self.navigation_last_progress_at is not None and + now - self.navigation_last_progress_at >= + self.NAVIGATION_STALL_TIMEOUT) + + def _try_next_opening(self, reason): + target = self.openings[0] if self.openings else self.tree + print('{} {}; trying another tree opening'.format(reason, target)) + self.g.path = [] + self.g.look_at = None + self._clear_navigation() + if self.openings: + self.openings.pop(0) + self.state = self.choose_opening + def bair(self, p): return self.g.chunks.get_block_at(*p) in blocks.NON_SOLID_IDS @@ -78,6 +129,7 @@ class GatherWoodStates: if navpath: self.g.path = navpath + self._begin_navigation() self.state = self.going_to_tree else: self.openings.pop(0) @@ -85,8 +137,11 @@ class GatherWoodStates: def going_to_tree(self): if utils.pint(self.g.pos) == self.openings[0]: + self._clear_navigation() self.g.look_at = self.tree self.state = self.clear_leaves + elif self._navigation_stalled(): + self._try_next_opening('No path progress to tree opening') def clear_leaves(self): if not self.g.breaking: @@ -124,6 +179,7 @@ class GatherWoodStates: if navpath: self.g.path = navpath + self._begin_navigation() self.state = self.going_to_trunk_base else: self.openings.pop(0) @@ -132,8 +188,11 @@ class GatherWoodStates: def going_to_trunk_base(self): if utils.pint(self.g.pos) == self.tree: + self._clear_navigation() self.g.look_at = utils.padd(self.tree, path.BLOCK_ABOVE2) self.state = self.clear_trunk + elif self._navigation_stalled(): + self._try_next_opening('No path progress to trunk base') def clear_trunk(self): if not self.g.breaking: @@ -187,6 +246,9 @@ class GatherWoodStates: self.bad_trees = [] self.good_trees = [] self.wait_time = 0 + self.navigation_path_head = None + self.navigation_best_distance = None + self.navigation_last_progress_at = None def run(self): self.state() diff --git a/mosfet/jobs/grab_sapling.py b/mosfet/jobs/grab_sapling.py index 3e229c8..7320f5c 100644 --- a/mosfet/jobs/grab_sapling.py +++ b/mosfet/jobs/grab_sapling.py @@ -18,7 +18,7 @@ from mosfet.info import mobs class GrabSaplingStates: NAVIGATION_TIMEOUT = 30.0 - SAPLING_SKIP_THRESHOLD = 64 + SAPLING_SKIP_THRESHOLD = 48 SAPLING_RESUME_THRESHOLD = 32 def idle(self): diff --git a/tests/test_break_time.py b/tests/test_break_time.py index 3fd1bf3..c6eb0e0 100644 --- a/tests/test_break_time.py +++ b/tests/test_break_time.py @@ -62,7 +62,9 @@ class BlockBreakTimingTests(unittest.TestCase): with patch('mosfet.game.time.monotonic', return_value=100.0): self.assertTrue(game.break_block((0, 64, 0))) - self.assertAlmostEqual(game.break_deadline, 100.3) + self.assertAlmostEqual( + game.break_deadline, + 100.3 + game.BREAK_FINISH_GRACE) if __name__ == '__main__':