Add sapling pickup threshold hysteresis

This commit is contained in:
Tanner committed 2026-11-15 00:35:23 +00:00
1 parent 6ee930cc28
commit 8ada31a918
1 file changed
+25 -1
+25 -1
View File
@@ -18,6 +18,8 @@ from mosfet.info import mobs
class GrabSaplingStates: class GrabSaplingStates:
NAVIGATION_TIMEOUT = 30.0 NAVIGATION_TIMEOUT = 30.0
SAPLING_SKIP_THRESHOLD = 64
SAPLING_RESUME_THRESHOLD = 32
def idle(self): def idle(self):
return None return None
@@ -26,6 +28,26 @@ class GrabSaplingStates:
self.state = self.find_saplings self.state = self.find_saplings
print('Trying to grab a sapling') print('Trying to grab a sapling')
def _refresh_skipped_item_ids(self):
for item_id in tuple(self.skipped_item_ids):
if (self.g.game.count_items([item_id]) <
self.SAPLING_RESUME_THRESHOLD):
self.skipped_item_ids.remove(item_id)
print('Sapling count fell below {}, resuming pickup'.format(
self.SAPLING_RESUME_THRESHOLD))
def _skip_sapling_type(self, item_id):
if item_id in self.skipped_item_ids:
return True
count = self.g.game.count_items([item_id])
if count > self.SAPLING_SKIP_THRESHOLD:
self.skipped_item_ids.add(item_id)
print('Have more than a stack of sapling item {}; skipping drops '
'until below {}'.format(
item_id, self.SAPLING_RESUME_THRESHOLD))
return True
return False
def find_saplings(self): def find_saplings(self):
w = self.g.world w = self.g.world
p = utils.pint(self.g.pos) p = utils.pint(self.g.pos)
@@ -40,7 +62,7 @@ class GrabSaplingStates:
saplings.sort(key=lambda s: utils.phyp(p, (s.x, s.y, s.z))) saplings.sort(key=lambda s: utils.phyp(p, (s.x, s.y, s.z)))
for s in saplings: for s in saplings:
if self.g.game.count_items([s.item_id]) > 64: if self._skip_sapling_type(s.item_id):
continue continue
s_pos = utils.pint((s.x, s.y, s.z)) s_pos = utils.pint((s.x, s.y, s.z))
@@ -97,6 +119,8 @@ class GrabSaplingStates:
self.sapling = None self.sapling = None
self.sapling_deadline = None self.sapling_deadline = None
self.eid_blacklist = [] self.eid_blacklist = []
self.skipped_item_ids = set()
def run(self): def run(self):
self._refresh_skipped_item_ids()
self.state() self.state()