2020-09-08 23:51:27 +00:00
|
|
|
import re
|
2020-09-08 21:33:42 +00:00
|
|
|
import time
|
|
|
|
import importlib
|
|
|
|
|
|
|
|
from panda3d.core import LPoint3f
|
|
|
|
|
2020-09-08 23:51:27 +00:00
|
|
|
from minecraft.networking.packets import Packet, clientbound, serverbound
|
|
|
|
|
2020-09-08 21:33:42 +00:00
|
|
|
import utils
|
|
|
|
importlib.reload(utils)
|
|
|
|
import path
|
|
|
|
importlib.reload(path)
|
2020-09-16 03:50:13 +00:00
|
|
|
import blocks
|
|
|
|
importlib.reload(blocks)
|
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
|
2020-09-08 20:07:09 +00:00
|
|
|
|
2020-09-16 03:50:13 +00:00
|
|
|
if packet.block_state_id == blocks.SOUL_TORCH:
|
2020-09-08 21:33:42 +00:00
|
|
|
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
|
2020-09-08 23:51:27 +00:00
|
|
|
|
|
|
|
def handle_chat(message, g):
|
|
|
|
source, text = message
|
|
|
|
reply = None
|
|
|
|
|
|
|
|
match = re.match(r'<(\w+)> (.*)', text)
|
|
|
|
if match:
|
|
|
|
sender, text = match.groups()
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
|
|
|
if text.startswith('! '):
|
|
|
|
text = text[2:]
|
|
|
|
elif text.startswith('!'):
|
|
|
|
text = text[1:]
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
|
|
|
if ' ' in text:
|
|
|
|
command = text.split(' ', 1)[0]
|
|
|
|
data = text.split(' ', 1)[1]
|
|
|
|
else:
|
|
|
|
command = text
|
|
|
|
|
|
|
|
if command == 'ping':
|
|
|
|
reply = 'pong'
|
|
|
|
|
|
|
|
if command == 'echo' and data:
|
|
|
|
reply = data
|
|
|
|
|
|
|
|
if command == 'respawn':
|
|
|
|
packet = serverbound.play.ClientStatusPacket()
|
|
|
|
packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN
|
|
|
|
g.connection.write_packet(packet)
|
|
|
|
reply = 'ok'
|
|
|
|
|
|
|
|
if command == 'pos':
|
|
|
|
reply = str(utils.pint(g.pos))[1:-1]
|
|
|
|
|
|
|
|
if command == 'afk':
|
|
|
|
reply = '/afk'
|
|
|
|
|
2020-09-09 01:52:50 +00:00
|
|
|
if command == 'error':
|
|
|
|
reply = 'ok'
|
|
|
|
raise
|
|
|
|
|
2020-09-08 23:51:27 +00:00
|
|
|
if reply:
|
|
|
|
print(reply)
|
|
|
|
g.chat.send(reply)
|
2020-09-09 21:58:19 +00:00
|
|
|
|
|
|
|
def handle_time_update(packet, g):
|
|
|
|
l = g.local_state
|
|
|
|
l.time = packet.time_of_day % 24000
|
|
|
|
|
|
|
|
def handle_set_slot(packet, g):
|
|
|
|
print(packet)
|
|
|
|
if packet.window_id == 0:
|
|
|
|
g.inv[packet.slot] = packet.slot_data
|
|
|
|
|
|
|
|
|
|
|
|
|