|
|
|
@ -285,13 +285,33 @@ class Game: |
|
|
|
|
reply = 'ok' |
|
|
|
|
|
|
|
|
|
if command == 'inv': |
|
|
|
|
inv_list = [] |
|
|
|
|
for i in self.g.inv.values(): |
|
|
|
|
if i.present: |
|
|
|
|
print(items.ITEM_NAMES[i.item_id], 'x', 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) |
|
|
|
|
|
|
|
|
|
if command == 'drop': |
|
|
|
|
self.drop_stack() |
|
|
|
|
|
|
|
|
|
if command == 'time': |
|
|
|
|
reply = str(self.g.time) |
|
|
|
|
|
|
|
|
|
if command == 'select' and data: |
|
|
|
|
item = int(data) |
|
|
|
|
if self.select_item([item]): |
|
|
|
|
reply = 'ok' |
|
|
|
|
else: |
|
|
|
|
reply = 'not found' |
|
|
|
|
|
|
|
|
|
if command == 'dump' and data: |
|
|
|
|
item = int(data) |
|
|
|
|
if self.has_item([item]): |
|
|
|
|
self.g.dumping = item |
|
|
|
|
reply = 'ok' |
|
|
|
|
else: |
|
|
|
|
reply = 'not found' |
|
|
|
|
|
|
|
|
|
if reply: |
|
|
|
|
print(reply) |
|
|
|
|
self.g.chat.send(reply) |
|
|
|
@ -304,6 +324,9 @@ class Game: |
|
|
|
|
if packet.window_id == 0: |
|
|
|
|
self.g.inv[packet.slot] = packet.slot_data |
|
|
|
|
|
|
|
|
|
if not packet.slot_data.present: |
|
|
|
|
self.g.dump_lock = False |
|
|
|
|
|
|
|
|
|
def break_block(self, location): |
|
|
|
|
bid = self.g.chunks.get_block_at(*location) |
|
|
|
|
if bid != 0: |
|
|
|
@ -325,7 +348,6 @@ class Game: |
|
|
|
|
self.g.chunks.set_block_at(*self.g.breaking, 0) |
|
|
|
|
self.g.breaking = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_break_animation(self, packet): |
|
|
|
|
print(packet) |
|
|
|
|
|
|
|
|
@ -366,9 +388,41 @@ class Game: |
|
|
|
|
else: |
|
|
|
|
self.pick(slot) |
|
|
|
|
|
|
|
|
|
def has_item(self, items): |
|
|
|
|
# select the first match from items of inv |
|
|
|
|
for slot, item in self.g.inv.items(): |
|
|
|
|
if item.item_id in items: |
|
|
|
|
return True |
|
|
|
|
else: #for |
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
def select_item(self, items): |
|
|
|
|
# select the first match from items of inv |
|
|
|
|
for slot, item in self.g.inv.items(): |
|
|
|
|
if item.item_id in items: |
|
|
|
|
self.g.game.choose_slot(slot) |
|
|
|
|
return True |
|
|
|
|
else: #for |
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
def drop_stack(self): |
|
|
|
|
packet = PlayerDiggingPacket() |
|
|
|
|
packet.status = 3 |
|
|
|
|
packet.location = utils.pint(self.g.pos) |
|
|
|
|
packet.face = 1 |
|
|
|
|
self.g.connection.write_packet(packet) |
|
|
|
|
|
|
|
|
|
def tick(self): |
|
|
|
|
if self.g.breaking: |
|
|
|
|
self.animate() |
|
|
|
|
|
|
|
|
|
if time.time() >= self.g.break_time - 2*utils.TICK: |
|
|
|
|
self.break_finish() |
|
|
|
|
|
|
|
|
|
if self.g.dumping and not self.g.dump_lock: |
|
|
|
|
if self.select_item([self.g.dumping]): |
|
|
|
|
self.drop_stack() |
|
|
|
|
self.g.dump_lock = True |
|
|
|
|
else: |
|
|
|
|
self.g.dumping = None |
|
|
|
|
|
|
|
|
|