Improve inv selections
This commit is contained in:
parent
0bbe516818
commit
69b0c057d6
8
bot.py
8
bot.py
|
@ -63,8 +63,6 @@ def tick(global_state):
|
|||
########## object physics ##########
|
||||
|
||||
for eid, obj in copy(g.objects).items():
|
||||
start_x = obj.x
|
||||
|
||||
if obj.velocity_x:
|
||||
obj.x += obj.velocity_x / 8000
|
||||
if obj.velocity_y:
|
||||
|
@ -72,7 +70,7 @@ def tick(global_state):
|
|||
if obj.velocity_z:
|
||||
obj.z += obj.velocity_z / 8000
|
||||
|
||||
block_below = g.chunks.get_block_at(floor(obj.x), int(obj.y-0.20), floor(obj.z))
|
||||
block_below = g.chunks.get_block_at(floor(obj.x), floor(obj.y-0.20), floor(obj.z))
|
||||
in_air = block_below in blocks.NON_SOLID_IDS
|
||||
|
||||
if in_air:
|
||||
|
@ -85,6 +83,10 @@ def tick(global_state):
|
|||
obj.velocity_y = 0
|
||||
obj.velocity_z *= 0.5
|
||||
|
||||
# float object back up in case it clipped through multiple blocks
|
||||
while g.chunks.get_block_at(floor(obj.x), floor(obj.y), floor(obj.z)) not in blocks.NON_SOLID_IDS:
|
||||
obj.y += 1
|
||||
|
||||
if abs(obj.velocity_x) < 1: obj.velocity_x = 0
|
||||
if abs(obj.velocity_z) < 1: obj.velocity_z = 0
|
||||
|
||||
|
|
8
game.py
8
game.py
|
@ -355,6 +355,7 @@ class Game:
|
|||
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))
|
||||
inv_list.sort()
|
||||
result = '\n'.join(inv_list)
|
||||
print(result or 'Empty')
|
||||
|
||||
|
@ -502,7 +503,7 @@ class Game:
|
|||
self.pick(slot)
|
||||
|
||||
def has_item(self, items):
|
||||
# select the first match from items of inv
|
||||
# test if any from items is in inv
|
||||
for slot, item in self.g.inv.items():
|
||||
if item.item_id in items:
|
||||
return True
|
||||
|
@ -511,7 +512,10 @@ class Game:
|
|||
|
||||
def select_item(self, items):
|
||||
# select the first match from items of inv
|
||||
for slot, item in self.g.inv.items():
|
||||
# uses smallest stack of that match
|
||||
inv_items = list(self.g.inv.items())
|
||||
inv_items.sort(key=lambda x: x[1].item_count or 0)
|
||||
for slot, item in inv_items:
|
||||
if item.item_id in items:
|
||||
self.g.game.choose_slot(slot)
|
||||
return True
|
||||
|
|
Loading…
Reference in New Issue
Block a user