Select most damaged tool

This commit is contained in:
Tanner Collin 2021-02-22 21:31:36 +00:00
parent 743d002167
commit 4b97aaf739

View File

@ -893,7 +893,9 @@ class Game:
def select_item(self, items):
# select the first match from items of inv
# uses smallest stack of that match
# and optionally the most damaged item
inv_items = list(self.g.inv.items())
inv_items.sort(key=lambda x: (x[1].nbt or {}).get('Damage', 0), reverse=True)
inv_items.sort(key=lambda x: x[1].item_count or 0)
for slot, item in inv_items:
if item.item_id in items: