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 = 1435
TEST_BLOCK = (616, 78, 496)
#TEST_BLOCK = (616, 78, 496)
TEST_BLOCK = (-100, 64, -167)
AVOID = [

40
game.py
View File

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

53
jobs.py
View File

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

View File

@ -259,30 +259,3 @@ class ClickWindowPacket(Packet):
{'mode': VarInt},
{'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},
]