Port loiter and harden 26.3 bed updates

This commit is contained in:
Tanner
2026-11-05 01:05:52 +00:00
parent b9d43c7c37
commit efa2140a91
12 changed files with 664 additions and 65 deletions
+46 -28
View File
@@ -17,6 +17,10 @@ from mosfet.info import mcdata
from mosfet.info import mobs
class CheckThreatsStates:
THREAT_DISTANCE = 20
CLEAR_DISTANCE = 30
CHECK_INTERVAL = 2.0
def idle(self):
return None
@@ -28,51 +32,63 @@ class CheckThreatsStates:
w = self.g.world
p = utils.pint(self.g.pos)
threats = w.find_threats(p, 40)
threats = w.find_threats(p, self.THREAT_DISTANCE)
if threats:
print('Found', len(threats), 'threats, fleeing:')
print('Found', len(threats), 'threats, seeking safety:')
print(threats)
self.threats = threats
self.state = self.find_safety
else:
print('Aborting, no threats')
self.state = self.cleanup
self.wait_time = self.CHECK_INTERVAL
self.state = self.wait
def find_safety(self):
w = self.g.world
p = utils.pint(self.g.pos)
safety = w.find_blocks_indexed(p, [blocks.EMERALD_BLOCK])
if not safety:
print('No emerald blocks found, aborting')
self.state = self.cleanup
return
safety.sort(key=lambda s: utils.phyp(p, s))
print('Found emerald blocks:', safety)
for s in safety:
s = utils.padd(s, path.BLOCK_ABOVE)
navpath = w.path_to_place(p, s)
if navpath:
safety_blocks = w.find_blocks_indexed(
p, [blocks.EMERALD_BLOCK], self.THREAT_DISTANCE * 4)
for block in safety_blocks:
spot = utils.padd(block, path.BLOCK_ABOVE)
if w.find_threats(spot, self.CLEAR_DISTANCE):
continue
navpath = w.path_to_place(p, spot)
if navpath is not None:
self.safety = spot
self.external_safety = True
self.g.path = navpath
self.state = self.going_to_safety
self.safety = s
print('Going to safety', self.safety)
print('Going to emerald safety point', self.safety)
return
else:
print('Cant get to safety', self.safety)
time.sleep(0.1)
print('Cant get to safety, aborting')
self.state = self.cleanup
# No configured emerald safe point was reachable. Retreat to a clear,
# supported location that the modern navigator can actually reach.
for spot in w.find_bed_areas(p, self.CLEAR_DISTANCE * 2):
if w.find_threats(spot, self.CLEAR_DISTANCE):
continue
navpath = w.path_to_place(p, spot)
if navpath is not None:
self.safety = spot
self.external_safety = False
self.g.path = navpath
self.state = self.going_to_safety
print('Fleeing to clear area', self.safety)
return
print('No reachable safe area found')
self.wait_time = self.CHECK_INTERVAL
self.state = self.wait
def going_to_safety(self):
if utils.pint(self.g.pos) == self.safety:
print('At safety spot, waiting to be moved')
self.state = self.wait_for_move
if self.external_safety:
print('At emerald safety point, waiting for server move')
self.state = self.wait_for_move
else:
print('At clear retreat spot')
self.wait_time = 3
self.state = self.wait
def wait_for_move(self):
# wait for the server to move the bot when it's safe
@@ -103,6 +119,8 @@ class CheckThreatsStates:
self.safety = None
self.wait_time = 0
self.threats = []
self.external_safety = False
def run(self):
self.state()