Clear leaves when low on saplings

This commit is contained in:
2020-10-17 23:35:43 -06:00
parent 69b0c057d6
commit 90388cf110
3 changed files with 134 additions and 50 deletions
+15 -7
View File
@@ -190,6 +190,10 @@ class MCWorld:
result.append(obj)
return result
def find_leaves(self, center, distance):
for a in self.find_blocks_3d(center, blocks.LEAF_IDS, distance, 10):
yield a
class Game:
def __init__(self, global_state):
@@ -374,12 +378,16 @@ class Game:
if command == 'dump' and data:
item = int(data)
if self.has_item([item]):
if self.count_items([item]):
self.g.dumping = item
reply = 'ok'
else:
reply = 'not found'
if command == 'count' and data:
item = int(data)
reply = str(self.count_items([item]))
if command == 'open':
self.open_container(blocks.TEST_BLOCK)
@@ -502,13 +510,13 @@ class Game:
else:
self.pick(slot)
def has_item(self, items):
# test if any from items is in inv
def count_items(self, items):
# count how many items are in inv
count = 0
for slot, item in self.g.inv.items():
if item.item_id in items:
return True
else: #for
return False
count += item.item_count
return count
def select_item(self, items):
# select the first match from items of inv
@@ -661,7 +669,7 @@ class Game:
if self.g.breaking:
self.animate()
if time.time() >= self.g.break_time - 2*utils.TICK:
if time.time() >= self.g.break_time: #- 2*utils.TICK:
self.break_finish()
if self.g.dumping and not self.g.item_lock: