Fix item caching bugs

This commit is contained in:
2020-09-20 23:41:55 -06:00
parent f8d44e7e38
commit 6489984640
5 changed files with 75 additions and 19 deletions
+30 -9
View File
@@ -10,7 +10,8 @@ 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
from protocol.packets import TimeUpdatePacket, SetSlotPacket, PlayerDiggingPacket, BlockBreakAnimationPacket, AcknowledgePlayerDiggingPacket, HeldItemChangePacket, PickItemPacket, OpenWindowPacket, ClickWindowPacket, CloseWindowPacket, ServerWindowConfirmationPacket, ClientWindowConfirmationPacket
from protocol.types import Slot
import utils
importlib.reload(utils)
@@ -186,6 +187,7 @@ 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)
@@ -302,6 +304,9 @@ class Game:
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()
@@ -334,10 +339,13 @@ class Game:
if command == 'click' and data:
if self.g.window:
window_id, slot, button, mode = [int(x) for x in data.split(' ')]
item = self.g.window.contents[slot]
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)
print(item)
self.click_window(window_id, slot, button, mode, item)
self.click_window(slot, button, mode, item)
else:
reply = 'nothing open'
@@ -356,7 +364,8 @@ class Game:
elif g.window:
g.window.contents[packet.slot] = packet.slot_data
if not packet.slot_data.present:
if packet.window_id >= 0 and not packet.slot_data.present:
print('unlocking item lock')
g.item_lock = False
def break_block(self, location):
@@ -451,17 +460,22 @@ class Game:
def handle_window(self, packet):
print(packet)
self.g.window = Bunch(data=packet, contents=dict())
self.g.window = Bunch(data=packet, contents=dict(), count=0)
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.window_id = window_id
packet.window_id = w.data.window_id
packet.slot = slot
packet.button = button
packet.action_number = 1
packet.action_number = w.count
packet.mode = mode
packet.clicked_item = item
self.g.connection.write_packet(packet)
print('<--', packet)
w.count += 1
def close_window(self):
packet = CloseWindowPacket()
@@ -469,6 +483,13 @@ 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: