Fix wood farming and block breaking stalls
This commit is contained in:
1 parent
8ada31a918
commit
99bb5c98de
4 files changed
+70
-3
No files matched your search
+4
-1
@@ -682,6 +682,7 @@ class LegacyGame:
|
|||||||
# migrated actions use the 26.3 packet classes imported above.
|
# migrated actions use the 26.3 packet classes imported above.
|
||||||
class Game(LegacyGame):
|
class Game(LegacyGame):
|
||||||
ARM_SWING_INTERVAL = 0.1
|
ARM_SWING_INTERVAL = 0.1
|
||||||
|
BREAK_FINISH_GRACE = 0.2
|
||||||
DOOR_AUTO_OPEN_GRACE = 0.25
|
DOOR_AUTO_OPEN_GRACE = 0.25
|
||||||
DOOR_TURN_DURATION = 0.3
|
DOOR_TURN_DURATION = 0.3
|
||||||
|
|
||||||
@@ -1045,7 +1046,9 @@ class Game(LegacyGame):
|
|||||||
self.g.breaking = location
|
self.g.breaking = location
|
||||||
self.breaking_state = block_id
|
self.breaking_state = block_id
|
||||||
now = time.monotonic()
|
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.animate()
|
||||||
self.next_swing_at = now + self.ARM_SWING_INTERVAL
|
self.next_swing_at = now + self.ARM_SWING_INTERVAL
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -8,6 +8,57 @@ from mosfet.info import items
|
|||||||
|
|
||||||
|
|
||||||
class GatherWoodStates:
|
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):
|
def bair(self, p):
|
||||||
return self.g.chunks.get_block_at(*p) in blocks.NON_SOLID_IDS
|
return self.g.chunks.get_block_at(*p) in blocks.NON_SOLID_IDS
|
||||||
|
|
||||||
@@ -78,6 +129,7 @@ class GatherWoodStates:
|
|||||||
|
|
||||||
if navpath:
|
if navpath:
|
||||||
self.g.path = navpath
|
self.g.path = navpath
|
||||||
|
self._begin_navigation()
|
||||||
self.state = self.going_to_tree
|
self.state = self.going_to_tree
|
||||||
else:
|
else:
|
||||||
self.openings.pop(0)
|
self.openings.pop(0)
|
||||||
@@ -85,8 +137,11 @@ class GatherWoodStates:
|
|||||||
|
|
||||||
def going_to_tree(self):
|
def going_to_tree(self):
|
||||||
if utils.pint(self.g.pos) == self.openings[0]:
|
if utils.pint(self.g.pos) == self.openings[0]:
|
||||||
|
self._clear_navigation()
|
||||||
self.g.look_at = self.tree
|
self.g.look_at = self.tree
|
||||||
self.state = self.clear_leaves
|
self.state = self.clear_leaves
|
||||||
|
elif self._navigation_stalled():
|
||||||
|
self._try_next_opening('No path progress to tree opening')
|
||||||
|
|
||||||
def clear_leaves(self):
|
def clear_leaves(self):
|
||||||
if not self.g.breaking:
|
if not self.g.breaking:
|
||||||
@@ -124,6 +179,7 @@ class GatherWoodStates:
|
|||||||
|
|
||||||
if navpath:
|
if navpath:
|
||||||
self.g.path = navpath
|
self.g.path = navpath
|
||||||
|
self._begin_navigation()
|
||||||
self.state = self.going_to_trunk_base
|
self.state = self.going_to_trunk_base
|
||||||
else:
|
else:
|
||||||
self.openings.pop(0)
|
self.openings.pop(0)
|
||||||
@@ -132,8 +188,11 @@ class GatherWoodStates:
|
|||||||
|
|
||||||
def going_to_trunk_base(self):
|
def going_to_trunk_base(self):
|
||||||
if utils.pint(self.g.pos) == self.tree:
|
if utils.pint(self.g.pos) == self.tree:
|
||||||
|
self._clear_navigation()
|
||||||
self.g.look_at = utils.padd(self.tree, path.BLOCK_ABOVE2)
|
self.g.look_at = utils.padd(self.tree, path.BLOCK_ABOVE2)
|
||||||
self.state = self.clear_trunk
|
self.state = self.clear_trunk
|
||||||
|
elif self._navigation_stalled():
|
||||||
|
self._try_next_opening('No path progress to trunk base')
|
||||||
|
|
||||||
def clear_trunk(self):
|
def clear_trunk(self):
|
||||||
if not self.g.breaking:
|
if not self.g.breaking:
|
||||||
@@ -187,6 +246,9 @@ class GatherWoodStates:
|
|||||||
self.bad_trees = []
|
self.bad_trees = []
|
||||||
self.good_trees = []
|
self.good_trees = []
|
||||||
self.wait_time = 0
|
self.wait_time = 0
|
||||||
|
self.navigation_path_head = None
|
||||||
|
self.navigation_best_distance = None
|
||||||
|
self.navigation_last_progress_at = None
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.state()
|
self.state()
|
||||||
@@ -18,7 +18,7 @@ from mosfet.info import mobs
|
|||||||
|
|
||||||
class GrabSaplingStates:
|
class GrabSaplingStates:
|
||||||
NAVIGATION_TIMEOUT = 30.0
|
NAVIGATION_TIMEOUT = 30.0
|
||||||
SAPLING_SKIP_THRESHOLD = 64
|
SAPLING_SKIP_THRESHOLD = 48
|
||||||
SAPLING_RESUME_THRESHOLD = 32
|
SAPLING_RESUME_THRESHOLD = 32
|
||||||
|
|
||||||
def idle(self):
|
def idle(self):
|
||||||
|
|||||||
@@ -62,7 +62,9 @@ class BlockBreakTimingTests(unittest.TestCase):
|
|||||||
|
|
||||||
with patch('mosfet.game.time.monotonic', return_value=100.0):
|
with patch('mosfet.game.time.monotonic', return_value=100.0):
|
||||||
self.assertTrue(game.break_block((0, 64, 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__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in new issue
Block a user