Throw designated items at signs during caching

This commit is contained in:
Tanner committed 2026-11-10 15:11:27 +00:00
1 parent 46b0657bcf
commit ce3be28d0c
4 files changed
+469 -2

No files matched your search

+134
View File
@@ -30,6 +30,140 @@ class CacheItemsTests(unittest.TestCase):
'Found 11 labeled chests; found 0 trapped chests: []',
output.getvalue())
def test_throw_signs_are_checked_before_cache_containers(self):
directive = {
'position': (2, 64, 0), 'side': 'front',
'item_name': 'seeds', 'item_ids': {items.WHEAT_SEEDS_ID},
}
class FakeWorld:
@staticmethod
def find_throw_signs(_center, _bot_name, _distance):
return [directive]
@staticmethod
def find_labeled_chests(*_args):
return []
@staticmethod
def find_blocks_indexed(*_args):
return []
state = CacheItemsStates(Munch(
world=FakeWorld(), pos=(0, 64, 0), name='mosfet1'))
state.find_trapped_chests()
self.assertIs(state.state.__func__, state.choose_throw_sign.__func__)
self.assertEqual(state.throw_signs, [directive])
def test_throw_sign_does_not_bypass_cache_inventory_threshold(self):
class FakeWorld:
@staticmethod
def find_throw_signs(*_args):
raise AssertionError('throw signs are checked only at threshold')
class FakeGame:
@staticmethod
def count_inventory_slots():
return 1
state = CacheItemsStates(Munch(
world=FakeWorld(), pos=(0, 64, 0), name='mosfet2',
game=FakeGame(), inv={
9: Munch(present=True, item_id=items.WHEAT_SEEDS_ID,
item_count=12),
}, minimum_cache_slots=27))
state.init()
self.assertIs(state.state.__func__, state.cleanup.__func__)
def test_throw_sign_throws_target_item_at_cache_threshold(self):
position = (2, 64, 0)
opening = (1, 64, 0)
seed = Munch(present=True, item_id=items.WHEAT_SEEDS_ID,
item_count=12)
dropped = []
g = Munch(
name='mosfet2', pos=(0, 64, 0), inv={9: seed},
item_lock=False, drop_waiting=None, path=[], look_at=None,
minimum_cache_slots=27,
)
directive = {
'position': position, 'side': 'front', 'item_name': 'seeds',
'item_ids': items.storage_item_ids_for_label('seeds'),
}
class FakeWorld:
@staticmethod
def find_throw_signs(_center, bot_name, _distance):
self.assertEqual(bot_name, 'mosfet2')
return [directive]
@staticmethod
def find_throw_openings(sign, center, radius):
self.assertEqual(sign, directive)
self.assertEqual(radius, 3)
return [{'position': opening, 'alignment': 1.0}]
@staticmethod
def find_labeled_chests(*_args):
return []
@staticmethod
def find_blocks_indexed(*_args):
return []
@staticmethod
def path_to_place(start, target):
return [start, target]
class FakeGame:
@staticmethod
def count_inventory_slots():
return 27
@staticmethod
def drop_inventory_slot(slot, whole_stack=True):
dropped.append((slot, whole_stack))
g.drop_waiting = {'slot': slot}
return True
@staticmethod
def select_item(_item_ids):
return False
g.world = FakeWorld()
g.game = FakeGame()
state = CacheItemsStates(g)
state.init()
self.assertIs(state.state.__func__, state.find_trapped_chests.__func__)
state.find_trapped_chests()
self.assertIs(state.state.__func__, state.choose_throw_sign.__func__)
state.choose_throw_sign()
self.assertEqual(state.opening, opening)
g.pos = opening
state.going_to_throw_sign()
self.assertEqual(g.look_at, position)
state.wait_time = 0
state.turn_to_throw_sign()
state.throw_items()
self.assertEqual(dropped, [(9, True)])
self.assertIs(state.state.__func__, state.wait_for_throw.__func__)
g.drop_waiting = None
g.inv[9] = Munch(present=False, item_id=0, item_count=0)
state.wait_for_throw()
state.throw_items()
self.assertIs(state.state.__func__, state.choose_throw_sign.__func__)
state.choose_throw_sign()
self.assertIs(state.state.__func__, state.choose_trapped_chest.__func__)
state.choose_trapped_chest()
state.select_chest()
self.assertIs(state.state.__func__, state.cleanup.__func__)
def test_wanted_single_stack_is_not_considered_transferable(self):
wanted_id = items.WHEAT_SEEDS_ID
old_wanted = items.WANTED_ITEMS