Files
minecraft-bot/mosfet/automation_26_3.py
T
2026-11-03 22:48:15 +00:00

78 lines
2.8 KiB
Python

"""Safe, movement-only bridge from legacy navigation to protocol 777."""
import threading
import time
import traceback
def start(global_state):
"""Start the legacy path-following physics, without legacy job/game packets."""
g = global_state
g.protocol_version = 777
g.time = 0.0
g.path = []
g.look_at = None
g.y_v = 0.0
g.y_a = 0.0
g.crawling = False
g.afk_timeout = 0.0
g.objects = g.get('objects') or {}
g.players = g.get('players') or {}
g.breaking = None
g.break_time = 0.0
g.correction_count = g.get('correction_count', 0)
g.yaw = float(g.get('yaw', 0.0) or 0.0)
g.pitch = float(g.get('pitch', 0.0) or 0.0)
g.chunks.loading = False
# Local navigation only needs nearby chunks; waiting for the entire view
# radius can stall on servers that stream chunks gradually.
g.physics_render_distance = 2
g.movement_paused = False
g.movement_status = 'idle'
g.movement_error = None
# Inventory, interaction, and job packets remain disabled until migrated.
g.job = None
g.game = None
def run():
from mosfet import bot, utils
loaded_since = None
while (g.get('running', True) and g.get('connection') and
g.connection.connected):
started = time.monotonic()
now = time.monotonic()
if g.chunks.check_loaded(g.physics_render_distance):
if loaded_since is None:
loaded_since = now
else:
loaded_since = None
# Let the initial position correction and first chunk batch settle
# before allowing any client-originated movement.
movement_ready = loaded_since is not None and now - loaded_since >= 0.5
if g.get('movement_paused'):
g.movement_status = 'paused'
elif g.path and not movement_ready:
g.movement_status = 'waiting_for_chunks'
elif g.path and movement_ready:
g.movement_status = 'following_path'
try:
bot.tick(g)
except Exception:
traceback.print_exc()
g.movement_error = traceback.format_exc()
g.path = []
g.movement_status = 'error'
print('[26.3 movement] stopped after navigation error',
flush=True)
return
elif not g.path and not g.get('movement_paused'):
g.movement_status = 'idle'
delay = max(0.0, utils.TICK - (time.monotonic() - started))
time.sleep(delay)
worker = threading.Thread(target=run, name='mosfet-26.3-movement',
daemon=True)
g.movement_thread = worker
worker.start()
return worker