Compare commits

..

No commits in common. "320f925fa10a92cd0795a61075e189a58cd2ab16" and "f8d44e7e3818c0396711a55e7639433a0321e2ab" have entirely different histories.

5 changed files with 28 additions and 97 deletions

View File

@ -22,7 +22,8 @@ SINGLE_SNOW = 3921
#SOUL_TORCH = 4008 #SOUL_TORCH = 4008
SOUL_TORCH = 1435 SOUL_TORCH = 1435
TEST_BLOCK = (616, 78, 496) #TEST_BLOCK = (616, 78, 496)
TEST_BLOCK = (-100, 64, -167)
AVOID = [ AVOID = [

38
game.py
View File

@ -10,8 +10,7 @@ from panda3d.core import LPoint3f
from minecraft.networking.packets import Packet, clientbound, serverbound from minecraft.networking.packets import Packet, clientbound, serverbound
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace
from protocol.packets import TimeUpdatePacket, SetSlotPacket, PlayerDiggingPacket, BlockBreakAnimationPacket, AcknowledgePlayerDiggingPacket, HeldItemChangePacket, PickItemPacket, OpenWindowPacket, ClickWindowPacket, CloseWindowPacket, ServerWindowConfirmationPacket, ClientWindowConfirmationPacket from protocol.packets import TimeUpdatePacket, SetSlotPacket, PlayerDiggingPacket, BlockBreakAnimationPacket, AcknowledgePlayerDiggingPacket, HeldItemChangePacket, PickItemPacket, OpenWindowPacket, ClickWindowPacket, CloseWindowPacket
from protocol.types import Slot
import utils import utils
importlib.reload(utils) importlib.reload(utils)
@ -187,7 +186,6 @@ class Game:
register(self.handle_break_animation, BlockBreakAnimationPacket) register(self.handle_break_animation, BlockBreakAnimationPacket)
register(self.handle_break_ack, AcknowledgePlayerDiggingPacket) register(self.handle_break_ack, AcknowledgePlayerDiggingPacket)
register(self.handle_window, OpenWindowPacket) register(self.handle_window, OpenWindowPacket)
register(self.handle_window_confirmation, ClientWindowConfirmationPacket)
self.g.chat.set_handler(self.handle_chat) self.g.chat.set_handler(self.handle_chat)
@ -298,16 +296,12 @@ class Game:
reply = 'ok' reply = 'ok'
if command == 'inv': if command == 'inv':
print(self.g.inv)
inv_list = [] inv_list = []
for i in self.g.inv.values(): for i in self.g.inv.values():
if i.present: if i.present:
inv_list.append('{}:{} x {}'.format(items.ITEM_NAMES[i.item_id], str(i.item_id), i.item_count)) inv_list.append('{}:{} x {}'.format(items.ITEM_NAMES[i.item_id], str(i.item_id), i.item_count))
reply = ', '.join(inv_list) reply = ', '.join(inv_list)
if not reply:
reply = 'empty'
if command == 'drop': if command == 'drop':
self.drop_stack() self.drop_stack()
@ -340,13 +334,10 @@ class Game:
if command == 'click' and data: if command == 'click' and data:
if self.g.window: if self.g.window:
slot, button, mode = [int(x) for x in data.split(' ')] window_id, slot, button, mode = [int(x) for x in data.split(' ')]
try:
item = self.g.window.contents[slot] item = self.g.window.contents[slot]
except KeyError:
item = Slot(present=False, item_id=None, item_count=None, nbt=None)
print(item) print(item)
self.click_window(slot, button, mode, item) self.click_window(window_id, slot, button, mode, item)
else: else:
reply = 'nothing open' reply = 'nothing open'
@ -365,8 +356,7 @@ class Game:
elif g.window: elif g.window:
g.window.contents[packet.slot] = packet.slot_data g.window.contents[packet.slot] = packet.slot_data
if packet.window_id >= 0 and not packet.slot_data.present: if not packet.slot_data.present:
print('unlocking item lock')
g.item_lock = False g.item_lock = False
def break_block(self, location): def break_block(self, location):
@ -461,22 +451,17 @@ class Game:
def handle_window(self, packet): def handle_window(self, packet):
print(packet) print(packet)
self.g.window = Bunch(data=packet, contents=dict(), count=0) self.g.window = Bunch(data=packet, contents=dict())
def click_window(self, slot, button, mode, item):
w = self.g.window
def click_window(self, window_id, slot, button, mode, item):
packet = ClickWindowPacket() packet = ClickWindowPacket()
packet.window_id = w.data.window_id packet.window_id = window_id
packet.slot = slot packet.slot = slot
packet.button = button packet.button = button
packet.action_number = w.count packet.action_number = 1
packet.mode = mode packet.mode = mode
packet.clicked_item = item packet.clicked_item = item
self.g.connection.write_packet(packet) self.g.connection.write_packet(packet)
print('<--', packet)
w.count += 1
def close_window(self): def close_window(self):
packet = CloseWindowPacket() packet = CloseWindowPacket()
@ -484,13 +469,6 @@ class Game:
self.g.connection.write_packet(packet) self.g.connection.write_packet(packet)
self.g.window = None self.g.window = None
def handle_window_confirmation(self, packet):
print(packet)
packet2 = ServerWindowConfirmationPacket()
packet2.window_id = packet.window_id
packet2.action_number = packet.action_number
packet2.accepted = packet.accepted
self.g.connection.write_packet(packet2)
def tick(self): def tick(self):
if self.g.breaking: if self.g.breaking:

53
jobs.py
View File

@ -15,8 +15,6 @@ import blocks
importlib.reload(blocks) importlib.reload(blocks)
import items import items
importlib.reload(items) importlib.reload(items)
import data
importlib.reload(data)
class LumberjackStates: class LumberjackStates:
@ -379,10 +377,9 @@ class CacheItemsStates:
return None return None
def init(self): def init(self):
num_stacks = len([x for x in self.g.inv.values() if x.present]) #if len(self.g.inv) >= 27:
print('inventory amount:', num_stacks) if len(self.g.inv) >= 2:
if num_stacks >= 27: self.state = self.find_chest_spot
self.state = self.find_cache_spot
else: else:
print('Aborting caching, not full') print('Aborting caching, not full')
self.state = self.cleanup self.state = self.cleanup
@ -456,8 +453,8 @@ class CacheItemsStates:
if self.g.item_lock: return if self.g.item_lock: return
w = self.g.window w = self.g.window
w_info = data.WINDOWS[w.data.window_type] w_data = data.WINDOWS[w.window_type]
w_inventory_slots = w_info.inventory w_inventory_slots = w_data.inventory
for slot_num in w_inventory_slots: for slot_num in w_inventory_slots:
if slot_num not in w.contents: if slot_num not in w.contents:
@ -465,28 +462,24 @@ class CacheItemsStates:
slot = w.contents[slot_num] slot = w.contents[slot_num]
if not slot.present:
continue
if slot.item_id in items.USEFUL_ITEMS: if slot.item_id in items.USEFUL_ITEMS:
continue continue
print('moving', slot) print('moving', slot)
#inv_slot_num = slot_num - w_info.slot_diff inv_slot_num = slot_num - w_data.slot_diff
#self.g.inv.pop(inv_slot_num, None) self.g.inv.pop(inv_slot_num, None)
self.g.item_lock = True self.g.item_lock = True
self.g.game.click_window(slot_num, 0, 1, slot) self.g.game.click_window(w.window_id, slot_num, 0, 1, slot)
return return
print('nothing left to move') print('nothing left to move')
self.state = self.close_chest self.state = close_chest
def close_chest(self): def close_chest(self):
print('closing chest') print('closing chest')
self.g.game.close_window() self.g.game.close_window()
self.g.chat.send('cache at ' + str(self.area)[1:-1])
self.state = self.cleanup self.state = self.cleanup
def cleanup(self): def cleanup(self):
@ -516,29 +509,17 @@ class JobStates:
return None return None
def gather_sand(self): def gather_sand(self):
s1 = self.gather_sand_states s = self.gather_sand_states
s2 = self.sleep_with_bed_states if s.state == s.idle:
s3 = self.cache_items_states s.state = s.init
elif s.state == s.done:
#s.state = s.init
if s1.state == s1.idle: self.prev_state = self.gather_sand
s1.state = s1.init self.state = self.sleep_with_bed
s2.state = s2.init
s3.state = s3.init
elif s1.state == s1.done:
if s2.state != s2.done:
s2.run()
return return
if s3.state != s3.done: s.run()
s3.run()
return
s1.state = s1.init
s2.state = s2.init
s3.state = s3.init
return
s1.run()
def lumberjack(self): def lumberjack(self):
s1 = self.lumberjack_states s1 = self.lumberjack_states

View File

@ -18,8 +18,6 @@ def get_packets(old_get_packets):
mc_packets.add(packets.OpenWindowPacket) mc_packets.add(packets.OpenWindowPacket)
mc_packets.add(packets.CloseWindowPacket) mc_packets.add(packets.CloseWindowPacket)
mc_packets.add(packets.ClickWindowPacket) mc_packets.add(packets.ClickWindowPacket)
mc_packets.add(packets.ClientWindowConfirmationPacket)
mc_packets.add(packets.ServerWindowConfirmationPacket)
return mc_packets return mc_packets
return lambda x: wrapper(old_get_packets, x) return lambda x: wrapper(old_get_packets, x)

View File

@ -259,30 +259,3 @@ class ClickWindowPacket(Packet):
{'mode': VarInt}, {'mode': VarInt},
{'clicked_item': Slot}, {'clicked_item': Slot},
] ]
class ClientWindowConfirmationPacket(Packet):
# Sent by the server indicating whether a request from the client was accepted
# https://wiki.vg/Protocol#Window_Confirmation_.28clientbound.29
id = 0x11
packet_name = 'client window confirmation'
definition = [
{'window_id': Byte},
{'action_number': Short},
{'accepted': Boolean},
]
class ServerWindowConfirmationPacket(Packet):
# Sent by the client to confirm an unaccepted click
# https://wiki.vg/Protocol#Window_Confirmation_.28serverbound.29
id = 0x07
packet_name = 'client window confirmation'
definition = [
{'window_id': Byte},
{'action_number': Short},
{'accepted': Boolean},
]