Fix wood farming and block breaking stalls

This commit is contained in:
Tanner committed 2026-11-15 15:18:12 +00:00
1 parent 8ada31a918
commit 99bb5c98de
4 files changed
+70 -3

No files matched your search

+62
View File
@@ -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()
+1 -1
View File
@@ -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):