Port inventory components to Minecraft 26.3
This commit is contained in:
+60
-15
@@ -113,30 +113,75 @@ class Commands:
|
||||
if command == 'inv' or command == 'inventory':
|
||||
inv_list = []
|
||||
uniq_item_counts = {}
|
||||
for i in self.g.inv.values():
|
||||
if i.present:
|
||||
inv_list.append((items.ITEM_NAMES[i.item_id], str(i.item_id), i.item_count))
|
||||
for slot, i in self.g.inv.items():
|
||||
if not i.present:
|
||||
continue
|
||||
base_name = items.ITEM_NAMES.get(i.item_id, str(i.item_id))
|
||||
components = getattr(i, 'components', {}) or {}
|
||||
custom_name = components.get('custom_name') or components.get('item_name')
|
||||
if isinstance(custom_name, dict):
|
||||
custom_name = custom_name.get('text') or custom_name.get('raw')
|
||||
display_name = str(custom_name or base_name)
|
||||
details = []
|
||||
for key in ('enchantments', 'stored_enchantments'):
|
||||
for name, level in components.get(key, {}).items():
|
||||
details.append('{} {}'.format(name, level))
|
||||
contents = components.get('container')
|
||||
if contents:
|
||||
nested_count = sum(bool(getattr(item, 'present', False))
|
||||
for item in contents)
|
||||
details.append('{} items inside'.format(nested_count))
|
||||
written = components.get('written_book_content')
|
||||
if written:
|
||||
title = written.get('title', {}).get('raw', '')
|
||||
details.append('book: {} ({} pages)'.format(
|
||||
title, len(written.get('pages', []))))
|
||||
writable = components.get('writable_book_content')
|
||||
if writable:
|
||||
details.append('writable book ({} pages)'.format(
|
||||
len(writable)))
|
||||
if getattr(i, 'components_unknown', False):
|
||||
details.append('components partial')
|
||||
detail_text = ' [{}]'.format(', '.join(details)) if details else ''
|
||||
inv_list.append((slot, display_name, str(i.item_id),
|
||||
i.item_count, detail_text))
|
||||
uniq_item_counts[i.item_id] = (
|
||||
uniq_item_counts.get(i.item_id, 0) + i.item_count)
|
||||
|
||||
if i.item_id not in uniq_item_counts:
|
||||
uniq_item_counts[i.item_id] = 0
|
||||
uniq_item_counts[i.item_id] += i.item_count
|
||||
|
||||
inv_list.sort()
|
||||
console_result = '\n'.join(['{}:{} x {}'.format(*x) for x in inv_list])
|
||||
inv_list.sort(key=lambda entry: (entry[1], entry[2]))
|
||||
console_result = '\n'.join(
|
||||
'slot {}: {}:{} x {}{}'.format(*entry)
|
||||
for entry in inv_list)
|
||||
|
||||
if not console_result:
|
||||
print('Empty')
|
||||
reply = 'empty'
|
||||
else:
|
||||
print(console_result)
|
||||
if self.g.get('inventory_partial', False):
|
||||
print('Warning: inventory contains stacks with undecoded components.')
|
||||
|
||||
reply_result_1 = ', '.join(['{}:{} x {}'.format(*x) for x in inv_list])
|
||||
reply_result_2 = ', '.join(['{}:{} x {}'.format(items.ITEM_NAMES[k], str(k), v) for k,v in uniq_item_counts.items()])
|
||||
reply_result_3 = ', '.join(['{}:{}x{}'.format(items.ITEM_NAMES[k], str(k), v) for k,v in uniq_item_counts.items()])
|
||||
reply_result_4 = ', '.join(['{}:{}x{}'.format(re.sub(r'[aeiou]', '', items.ITEM_NAMES[k]), str(k), v) for k,v in uniq_item_counts.items()])
|
||||
reply_result_5 = ' '.join(['{}{}x{}'.format(re.sub(r'[aeiou]', '', items.ITEM_NAMES[k]), str(k), v) for k,v in uniq_item_counts.items()])
|
||||
reply_result_1 = ', '.join(
|
||||
'{}:{} x {}{}'.format(*entry[1:]) for entry in inv_list)
|
||||
reply_result_components = ', '.join(
|
||||
'{}{}'.format(entry[1], entry[4])
|
||||
for entry in inv_list if entry[4])
|
||||
reply_result_2 = ', '.join(
|
||||
'{}:{} x {}'.format(items.ITEM_NAMES.get(k, str(k)), str(k), v)
|
||||
for k, v in uniq_item_counts.items())
|
||||
reply_result_3 = ', '.join(
|
||||
'{}:{}x{}'.format(items.ITEM_NAMES.get(k, str(k)), str(k), v)
|
||||
for k, v in uniq_item_counts.items())
|
||||
reply_result_4 = ', '.join(
|
||||
'{}:{}x{}'.format(re.sub(r'[aeiou]', '', items.ITEM_NAMES.get(k, str(k))), str(k), v)
|
||||
for k, v in uniq_item_counts.items())
|
||||
reply_result_5 = ' '.join(
|
||||
'{}{}x{}'.format(re.sub(r'[aeiou]', '', items.ITEM_NAMES.get(k, str(k))), str(k), v)
|
||||
for k, v in uniq_item_counts.items())
|
||||
|
||||
for r in [reply_result_1, reply_result_2, reply_result_3, reply_result_4, reply_result_5]:
|
||||
for r in [reply_result_1, reply_result_components,
|
||||
reply_result_2, reply_result_3, reply_result_4,
|
||||
reply_result_5]:
|
||||
reply = r
|
||||
if len(reply) < 256:
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user