Add window slot packet and item info
This commit is contained in:
146
bot.py
146
bot.py
@@ -6,6 +6,7 @@ from itertools import count
|
||||
|
||||
|
||||
import blocks
|
||||
import items
|
||||
import custom_packets
|
||||
|
||||
from minecraft import authentication
|
||||
@@ -379,6 +380,11 @@ def break_block(connection, coords, time):
|
||||
s['break_time'] = time
|
||||
s['break_timeout'] = 0.25
|
||||
|
||||
def say(connection, message):
|
||||
packet = serverbound.play.ChatPacket()
|
||||
packet.message = message
|
||||
connection.write_packet(packet)
|
||||
|
||||
|
||||
BLOCK_ABOVE = (0, +1, 0)
|
||||
BLOCK_BELOW = (0, -1, 0)
|
||||
@@ -491,6 +497,9 @@ class LumberjackStates:
|
||||
def idle(self):
|
||||
return None
|
||||
|
||||
def init(self):
|
||||
self.state = self.find_new_tree
|
||||
|
||||
def find_new_tree(self):
|
||||
print('Finding new tree...')
|
||||
w = MCWorld(self.player_info.chunks)
|
||||
@@ -512,7 +521,7 @@ class LumberjackStates:
|
||||
else: # for
|
||||
print('Unable to get to tree', self.tree)
|
||||
self.bad_trees.append(self.tree)
|
||||
self.state = self.finished
|
||||
self.state = self.done
|
||||
return
|
||||
|
||||
s['path'] = path
|
||||
@@ -588,9 +597,9 @@ class LumberjackStates:
|
||||
if self.wait_time > 0:
|
||||
self.wait_time -= TICK
|
||||
else:
|
||||
self.state = self.finished
|
||||
self.state = self.done
|
||||
|
||||
def finished(self):
|
||||
def done(self):
|
||||
return None
|
||||
|
||||
|
||||
@@ -617,17 +626,23 @@ class JobStates:
|
||||
def lumberjack(self):
|
||||
l = self.lumberjack_states
|
||||
if l.state == l.idle:
|
||||
l.state = l.find_new_tree
|
||||
elif l.state == l.finished:
|
||||
l.state = l.init
|
||||
elif l.state == l.done:
|
||||
# check time, etc
|
||||
l.state = l.find_new_tree
|
||||
l.state = l.init
|
||||
|
||||
l.run()
|
||||
|
||||
def __init__(self, player_info):
|
||||
def stop(self):
|
||||
self.lumberjack_states = LumberjackStates(self.player_info)
|
||||
self.state = self.idle
|
||||
|
||||
def __init__(self, connection, player_info):
|
||||
self.connection = connection
|
||||
self.player_info = player_info
|
||||
self.state = self.idle
|
||||
self.lumberjack_states = LumberjackStates(player_info)
|
||||
self.lumberjack_states = LumberjackStates(self.player_info)
|
||||
self.survive = False
|
||||
|
||||
def run(self):
|
||||
self.state()
|
||||
@@ -785,7 +800,7 @@ def init(connection, player_info):
|
||||
s['break_timeout'] = 0
|
||||
s['break_finished_packet'] = None
|
||||
|
||||
s['jobstate'] = JobStates(player_info)
|
||||
s['jobstate'] = JobStates(connection, player_info)
|
||||
s['jobstate'].run()
|
||||
|
||||
def main(connection, player_info):
|
||||
@@ -819,13 +834,12 @@ def main(connection, player_info):
|
||||
if solution:
|
||||
solution = list(solution)
|
||||
s['path'] = solution
|
||||
s['jobstate'].state = s['jobstate'].stop
|
||||
print(len(solution))
|
||||
print(solution)
|
||||
print(round(time.time() - start, 3), 'seconds')
|
||||
else:
|
||||
packet = serverbound.play.ChatPacket()
|
||||
packet.message = 'No path found'
|
||||
connection.write_packet(packet)
|
||||
say(connection, 'No path found')
|
||||
|
||||
#s['y_v'] = 10.0
|
||||
#s['y_a'] = -36.0
|
||||
@@ -842,37 +856,37 @@ def main(connection, player_info):
|
||||
#connection.register_packet_listener(
|
||||
# y, AcknowledgePlayerDiggingPacket)
|
||||
|
||||
def z(p):
|
||||
def handle_set_slot(p):
|
||||
print(p)
|
||||
if p.window_id == 0:
|
||||
player_info.inv[p.slot] = p.slot_data
|
||||
|
||||
connection.register_packet_listener(
|
||||
z, custom_packets.BlockBreakAnimationPacket)
|
||||
handle_set_slot, custom_packets.SetSlotPacket)
|
||||
|
||||
def print_chat(chat_packet):
|
||||
print("Message (%s): %s" % (
|
||||
chat_packet.field_string('position'), chat_packet.json_data))
|
||||
try:
|
||||
print("Message (%s): %s" % (
|
||||
chat_packet.field_string('position'), chat_packet.json_data))
|
||||
|
||||
if '!reload' in chat_packet.json_data:
|
||||
global running
|
||||
running = False
|
||||
elif '!afk' in chat_packet.json_data:
|
||||
packet = serverbound.play.ChatPacket()
|
||||
packet.message = '/afk'
|
||||
connection.write_packet(packet)
|
||||
elif '!respawn' in chat_packet.json_data:
|
||||
packet = serverbound.play.ClientStatusPacket()
|
||||
packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN
|
||||
connection.write_packet(packet)
|
||||
elif '!chunk' in chat_packet.json_data:
|
||||
print(len(player_info.chunks.chunks.keys()))
|
||||
print(player_info.chunks.chunks[(38, 4, 33)].__dict__)
|
||||
elif '!block' in chat_packet.json_data:
|
||||
block = player_info.chunks.get_block_at(616, 78, 496)
|
||||
packet = serverbound.play.ChatPacket()
|
||||
packet.message = str(block)
|
||||
connection.write_packet(packet)
|
||||
elif '!path' in chat_packet.json_data:
|
||||
try:
|
||||
if '!reload' in chat_packet.json_data:
|
||||
global running
|
||||
running = False
|
||||
elif '!afk' in chat_packet.json_data:
|
||||
say(connection, '/afk')
|
||||
elif '!respawn' in chat_packet.json_data:
|
||||
packet = serverbound.play.ClientStatusPacket()
|
||||
packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN
|
||||
connection.write_packet(packet)
|
||||
elif '!chunk' in chat_packet.json_data:
|
||||
print(len(player_info.chunks.chunks.keys()))
|
||||
print(player_info.chunks.chunks[(38, 4, 33)].__dict__)
|
||||
elif '!block' in chat_packet.json_data:
|
||||
block = player_info.chunks.get_block_at(616, 78, 496)
|
||||
packet = serverbound.play.ChatPacket()
|
||||
packet.message = str(block)
|
||||
connection.write_packet(packet)
|
||||
elif '!path' in chat_packet.json_data:
|
||||
s['goal'] = LPoint3f(655, 86, 341)
|
||||
print('new waypoint:', s['goal'])
|
||||
start = time.time()
|
||||
@@ -881,11 +895,7 @@ def main(connection, player_info):
|
||||
s['path'] = solution
|
||||
print(len(solution))
|
||||
print(round(time.time() - start, 3), 'seconds')
|
||||
except BaseException as e:
|
||||
import traceback
|
||||
print(traceback.format_exc())
|
||||
elif '!tree' in chat_packet.json_data:
|
||||
try:
|
||||
elif '!tree' in chat_packet.json_data:
|
||||
mc_world = MCWorld(player_info.chunks)
|
||||
start = time.time()
|
||||
coords = mc_world.find_tree(pint(player_info.pos), 100)
|
||||
@@ -895,40 +905,44 @@ def main(connection, player_info):
|
||||
path = mc_world.navigate_to_opening(pint(player_info.pos), openings[0])
|
||||
print(path)
|
||||
print(round(time.time() - start, 3), 'seconds')
|
||||
except BaseException as e:
|
||||
import traceback
|
||||
print(traceback.format_exc())
|
||||
elif '!break' in chat_packet.json_data:
|
||||
try:
|
||||
elif '!break' in chat_packet.json_data:
|
||||
coords = pint(player_info.pos)
|
||||
coords = padd(coords, CHECK_NORTH)
|
||||
|
||||
break_block(connection, coords, 2.5)
|
||||
#break_block(connection, coords, 0.35)
|
||||
except BaseException as e:
|
||||
import traceback
|
||||
print(traceback.format_exc())
|
||||
elif '!pick' in chat_packet.json_data:
|
||||
try:
|
||||
elif '!pick' in chat_packet.json_data:
|
||||
packet = custom_packets.PickItemPacket()
|
||||
packet.slot_to_use = 1
|
||||
connection.write_packet(packet)
|
||||
except BaseException as e:
|
||||
import traceback
|
||||
print(traceback.format_exc())
|
||||
elif '!echo' in chat_packet.json_data:
|
||||
try:
|
||||
elif '!inv' in chat_packet.json_data:
|
||||
for i in player_info.inv.values():
|
||||
if i.present:
|
||||
print(items.ITEM_NAMES[i.item_id], 'x', i.item_count)
|
||||
elif '!echo' in chat_packet.json_data:
|
||||
parts = chat_packet.json_data.split('\'')
|
||||
packet = serverbound.play.ChatPacket()
|
||||
packet.message = parts[1]
|
||||
connection.write_packet(packet)
|
||||
except BaseException as e:
|
||||
import traceback
|
||||
print(traceback.format_exc())
|
||||
elif 'get wood' in chat_packet.json_data:
|
||||
print('setting job state to lumberjack')
|
||||
s['jobstate'].state = s['jobstate'].lumberjack
|
||||
say(connection, parts[1])
|
||||
elif 'get wood and survive' in chat_packet.json_data:
|
||||
for i in player_info.inv.values():
|
||||
if i.item_id in items.BED_IDS:
|
||||
break
|
||||
else: # for
|
||||
say(connection, 'I need a bed')
|
||||
return
|
||||
|
||||
s['jobstate'].state = s['jobstate'].lumberjack
|
||||
s['jobstate'].survive = True
|
||||
elif 'get wood' in chat_packet.json_data:
|
||||
s['jobstate'].state = s['jobstate'].lumberjack
|
||||
elif 'stop job' in chat_packet.json_data:
|
||||
say(connection, 'ok')
|
||||
s['jobstate'].state = s['jobstate'].stop
|
||||
elif 'where are you' in chat_packet.json_data:
|
||||
say(connection, str(pint(player_info.pos))[1:-1])
|
||||
|
||||
except BaseException as e:
|
||||
import traceback
|
||||
print(traceback.format_exc())
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user