minecraft-bot/packet_handlers.py

50 lines
1.3 KiB
Python
Raw Normal View History

2020-09-08 21:33:42 +00:00
import time
import importlib
from panda3d.core import LPoint3f
import utils
importlib.reload(utils)
import path
importlib.reload(path)
2020-09-08 20:07:09 +00:00
def handle_join_game(packet, g):
print('Connected.')
print(packet)
g.info = packet
def handle_block_change(packet, g):
2020-09-08 21:33:42 +00:00
l = g.local_state
print('block change:')
2020-09-08 20:07:09 +00:00
print(packet)
2020-09-08 21:33:42 +00:00
if packet.block_state_id == 3887:
try:
l.goal = LPoint3f(x=packet.location[0], y=packet.location[1], z=packet.location[2])
print('new waypoint:', l.goal)
start = time.time()
solution = path.Pathfinder(g.chunks).astar(utils.pint(g.pos), utils.pint(l.goal))
if solution:
solution = list(solution)
l.path = solution
#l.jobstate.state = l.jobstate.stop
print(len(solution))
print(solution)
print(round(time.time() - start, 3), 'seconds')
else:
print('No path found')
#say(connection, 'No path found')
#l.y_v = 10.0
#l.y_a = -36.0
except BaseException as e:
import traceback
print(traceback.format_exc())
2020-09-08 20:07:09 +00:00
def handle_position_and_look(packet, g):
print('pos and look:')
print(packet)
p = LPoint3f(x=packet.x, y=packet.y, z=packet.z)
g.pos = p