Add sign-labeled chest storage

This commit is contained in:
Tanner
2026-11-07 16:35:57 +00:00
parent ab8f59a89b
commit 43b37b76f6
7 changed files with 401 additions and 66 deletions
+1 -1
View File
@@ -147,7 +147,7 @@ class GatherWoodPortTests(unittest.TestCase):
self.assertTrue(items.AXE_IDS.issubset(items.NEEDED_ITEMS))
self.assertTrue(items.SAPLING_IDS.issubset(items.WANTED_ITEMS))
job.grab_supplies_states.state = job.grab_supplies_states.find_barrels
job.grab_supplies_states.state = job.grab_supplies_states.find_supply_chests
job.clear_leaves_states.state = job.clear_leaves_states.find_leaves
job.plant_tree_states.state = job.plant_tree_states.check_feet
job.grab_sapling_states.state = job.grab_sapling_states.find_saplings
+45 -6
View File
@@ -8,6 +8,14 @@ from mosfet.jobs.grab_supplies import GrabSuppliesStates
class GroundSupplyTests(unittest.TestCase):
def test_default_needed_supplies_are_configured_by_constructor(self):
state = GrabSuppliesStates(Munch())
self.assertEqual(items.FOOD, [
'cooked_porkchop', 'cooked_beef', 'bread', 'cooked_chicken',
'cooked_cod', 'cooked_salmon',
])
self.assertEqual(items.FOOD_IDS, items.get_set({
'cooked_porkchop', 'cooked_beef', 'bread', 'cooked_chicken',
'cooked_cod', 'cooked_salmon',
}))
self.assertEqual(state.supplies, {
tuple(items.BED_IDS): (1, 1),
(items.CHEST_ID,): (1, 1),
@@ -44,19 +52,50 @@ class GroundSupplyTests(unittest.TestCase):
self.assertEqual(state.target_items, (items.CHEST_ID,))
self.assertIs(state.state.__func__, state.find_ground_items.__func__)
def test_unreachable_barrel_ends_supply_task_without_trying_more(self):
def test_supply_selection_uses_only_addressed_supply_chests(self):
position = (4, 64, 0)
chest_record = {
'position': position,
'positions': (position,),
'labels': {'mosfet supplies'},
'sign_positions': {(4, 64, 1)},
}
class FakeWorld:
@staticmethod
def path_to_place_faked(_start, _barrel):
return None
def find_supply_chests(_center, _bot_name, _distance):
return [chest_record]
@staticmethod
def find_blocks_indexed(*_args):
raise AssertionError('grab_supplies must not search barrels')
state = GrabSuppliesStates(Munch(
name='mosfet1', pos=(0.5, 64.0, 0.5), world=FakeWorld()))
state.find_supply_chests()
state.choose_supply_chest()
self.assertEqual(state.chest, position)
self.assertIs(state.state.__func__, state.path_to_supply_chest.__func__)
def test_unreachable_supply_chest_ends_task_without_searching_barrels(self):
class FakeWorld:
@staticmethod
def path_to_place_faked(_start, _chest):
return None
position = (10, 64, 10)
state = GrabSuppliesStates(Munch(
pos=(0.5, 64.0, 0.5), world=FakeWorld(), chunks=Munch()))
state.barrel = (10, 64, 10)
state.path_to_barrel()
state.supply_chests = [{
'position': position, 'positions': (position,),
'labels': {'mosfet supplies'},
}]
state.choose_supply_chest()
state.path_to_supply_chest()
state.choose_supply_chest()
self.assertIs(state.state.__func__, state.cleanup.__func__)
self.assertEqual(state.bad_barrels, [(10, 64, 10)])
def test_job_walks_to_and_picks_up_dropped_supply_before_barrels(self):
axe_id = next(iter(items.AXE_IDS))
+77
View File
@@ -0,0 +1,77 @@
import unittest
from munch import Munch
from mosfet.info import blocks, items
from mosfet.jobs.cache_items import CacheItemsStates
from mosfet.world import World
class LabeledStorageTests(unittest.TestCase):
def test_labels_resolve_to_item_categories(self):
seeds = items.storage_item_ids_for_label('Seeds')
wheat = items.storage_item_ids_for_label('Wheat')
self.assertEqual(seeds, items.get_set({
'beetroot', 'beetroot_seeds', 'carrot', 'melon_seeds',
'nether_wart', 'pitcher_pod', 'potato', 'pumpkin_seeds',
'torchflower_seeds', 'wheat_seeds',
}))
self.assertEqual(items.storage_item_ids_for_label('Dirt'), set())
self.assertEqual(items.storage_item_ids_for_label('Stone'), set())
self.assertIn(items.WHEAT_SEEDS_ID, seeds)
self.assertEqual(wheat, {items.WHEAT_ID})
self.assertNotIn(items.WHEAT_SEEDS_ID, wheat)
def test_sign_label_associates_with_adjacent_double_chest(self):
sign_pos = (0, 64, 0)
left_chest = (0, 64, 1)
right_chest = (1, 64, 1)
blocks_by_pos = {left_chest: 5552, right_chest: 5560}
chunks = Munch(
block_entities={sign_pos: {
'type': 7,
'data': {'front_text': {'messages': [
'Seeds', '', '', '',
]}},
}},
index={},
get_block_at=lambda *pos: blocks_by_pos.get(tuple(pos)),
)
chests = World(Munch(chunks=chunks)).find_labeled_chests(
sign_pos, 10)
self.assertEqual(len(chests), 1)
self.assertEqual(chests[0]['positions'], (left_chest, right_chest))
self.assertIn(items.WHEAT_SEEDS_ID, chests[0]['item_ids'])
self.assertEqual(chests[0]['labels'], {'Seeds'})
def test_wheat_chest_does_not_cache_seeds(self):
wheat = Munch(present=True, item_id=items.WHEAT_ID, item_count=64)
seeds = Munch(present=True, item_id=items.WHEAT_SEEDS_ID, item_count=64)
clicks = []
class FakeGame:
@staticmethod
def count_window_slots():
return 0
@staticmethod
def click_window(*args):
clicks.append(args)
cache = CacheItemsStates(Munch(
inv={9: wheat, 10: seeds}, item_lock=False,
window=Munch(container_slots=27, contents={
**dict.fromkeys(range(27)), 27: wheat, 28: seeds,
}),
game=FakeGame(),
))
cache.is_labeled_container = True
cache.container_item_ids = items.storage_item_ids_for_label('Wheat')
cache.move_items()
self.assertEqual(clicks, [(27, 0, 1, wheat)])
if __name__ == '__main__':
unittest.main()