Add sapling collection timeout, skip if we have lots
This commit is contained in:
1 parent
86fbf911a5
commit
6ee930cc28
1 file changed
+15
@@ -17,6 +17,8 @@ from mosfet.info import mcdata
|
||||
from mosfet.info import mobs
|
||||
|
||||
class GrabSaplingStates:
|
||||
NAVIGATION_TIMEOUT = 30.0
|
||||
|
||||
def idle(self):
|
||||
return None
|
||||
|
||||
@@ -38,6 +40,9 @@ class GrabSaplingStates:
|
||||
saplings.sort(key=lambda s: utils.phyp(p, (s.x, s.y, s.z)))
|
||||
|
||||
for s in saplings:
|
||||
if self.g.game.count_items([s.item_id]) > 64:
|
||||
continue
|
||||
|
||||
s_pos = utils.pint((s.x, s.y, s.z))
|
||||
|
||||
check = utils.padd(s_pos, path.BLOCK_BELOW)
|
||||
@@ -57,6 +62,8 @@ class GrabSaplingStates:
|
||||
self.g.path = navpath
|
||||
self.state = self.going_to_sapling
|
||||
self.sapling = s_pos
|
||||
self.sapling_deadline = (
|
||||
time.monotonic() + self.NAVIGATION_TIMEOUT)
|
||||
self.eid_blacklist.append(s.entity_id)
|
||||
print('Going to sapling', self.sapling)
|
||||
return
|
||||
@@ -66,6 +73,13 @@ class GrabSaplingStates:
|
||||
|
||||
def going_to_sapling(self):
|
||||
if utils.pint(self.g.pos) == self.sapling:
|
||||
self.sapling_deadline = None
|
||||
self.state = self.find_saplings
|
||||
elif time.monotonic() >= self.sapling_deadline:
|
||||
print('Timed out navigating to sapling', self.sapling,
|
||||
'- trying another')
|
||||
self.g.path = []
|
||||
self.sapling_deadline = None
|
||||
self.state = self.find_saplings
|
||||
|
||||
def cleanup(self):
|
||||
@@ -81,6 +95,7 @@ class GrabSaplingStates:
|
||||
self.state = self.idle
|
||||
|
||||
self.sapling = None
|
||||
self.sapling_deadline = None
|
||||
self.eid_blacklist = []
|
||||
|
||||
def run(self):
|
||||
|
||||
Reference in new issue
Block a user