From ebf325f48b90c189c71c44b4baf106d686f393fe Mon Sep 17 00:00:00 2001 From: Tanner Date: Tue, 17 Nov 2026 19:29:13 +0000 Subject: [PATCH] Support harvesting and caching red sand --- README.md | 17 ++++++++++------- mosfet/info/blocks.py | 4 ++++ mosfet/info/items.py | 4 ++++ mosfet/jobs/gather_sand.py | 6 +++--- mosfet/world.py | 6 +++--- tests/test_indexed_search.py | 37 ++++++++++++++++++------------------ tests/test_storage_labels.py | 5 +++++ 7 files changed, 48 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 155e6dc..0212943 100644 --- a/README.md +++ b/README.md @@ -86,11 +86,11 @@ mosfet sand origin ``` The bot uses the nearest matching loaded sign within 200 blocks. A full bot -name such as `mosfet1` can be used instead of the group name. Sand is harvested -in safe 3x3x1 sections. After each section, pickup/cache/food/sleep maintenance -runs before the job starts the next one. If no matching sign is found, the job -keeps its previous loaded origin, or uses the bot's current block position when -no loaded origin is set. +name such as `mosfet1` can be used instead of the group name. Sand and red sand +are harvested in safe 3x3x1 sections; pickup/cache/food/sleep maintenance runs +between sections. If no matching sign is found, the job keeps its previous +loaded origin, or uses the bot's current block position when no loaded origin +is set. ### Cache labels @@ -105,6 +105,8 @@ Each recognized line adds items to the chest's accepted categories: - `Seeds` — `beetroot_seeds`, `melon_seeds`, `pumpkin_seeds`, `torchflower_seeds`, `wheat_seeds`, and `pitcher_pod`. - `Wheat` — wheat only; wheat seeds are not included. +- `Sand` — sand only. +- `Red Sand` — red sand only. - `Logs` — every log item in the current 26.3 data, including stripped logs, wood, stems, and hyphae. - `Oak Logs` (and labels such as `Spruce Logs`) — that tree's log family, @@ -299,11 +301,12 @@ These will only run for the bot they are addressed to. Replace `1` with the last `1gather wood` - gathers wood from the world -`1gather sand` - gathers sand from the world +`1gather sand` - gathers sand and red sand from the world `1farm logs` (or `1farm wood`) - farms trees and caches their logs -`1farm sand` - gathers sand, first obtaining a shovel from a supply chest +`1farm sand` - gathers sand and red sand, first obtaining a shovel from a +supply chest `1farm wart` - farms netherwart from a certain area diff --git a/mosfet/info/blocks.py b/mosfet/info/blocks.py index 5bd6ac1..fff1ab4 100644 --- a/mosfet/info/blocks.py +++ b/mosfet/info/blocks.py @@ -38,6 +38,7 @@ BREAK_DISTANCE = 6 AIR = MCD_BLOCKS['air']['minStateId'] STONE = MCD_BLOCKS['stone']['minStateId'] SAND = MCD_BLOCKS['sand']['minStateId'] +RED_SAND = MCD_BLOCKS['red_sand']['minStateId'] SOUL_TORCH = MCD_BLOCKS['soul_torch']['minStateId'] EMERALD_BLOCK = MCD_BLOCKS['emerald_block']['minStateId'] SINGLE_SNOW = MCD_BLOCKS.get('snow', MCD_BLOCKS.get('snow_layer', {})).get( @@ -56,6 +57,9 @@ def get_set(names): return result +SAND_IDS = get_set(['sand', 'red_sand']) + + # Collision geometry is safer for navigation than the old hard-coded 1.16 list. NON_SOLID_IDS = { state_id for state_id, boxes in COLLISION_BOXES.items() if not boxes diff --git a/mosfet/info/items.py b/mosfet/info/items.py index 2b87ed4..08b068e 100644 --- a/mosfet/info/items.py +++ b/mosfet/info/items.py @@ -82,6 +82,8 @@ def get_name(idx): CHEST_ID = get_id('chest') GAPPLE_ID = get_id('enchanted_golden_apple') SAND_ID = get_id('sand') +RED_SAND_ID = get_id('red_sand') +SAND_IDS = {SAND_ID, RED_SAND_ID} NETHERWART_ID = get_id('nether_wart') CARROT_ID = get_id('carrot') POTATO_ID = get_id('potato') @@ -96,6 +98,8 @@ IRON_INGOT_ID = get_id('iron_ingot') _LABEL_ITEM_IDS = { + 'sand': {SAND_ID}, + 'red sand': {RED_SAND_ID}, 'seeds': get_set({ 'beetroot_seeds', 'melon_seeds', 'pitcher_pod', 'pumpkin_seeds', 'torchflower_seeds', 'wheat_seeds', diff --git a/mosfet/jobs/gather_sand.py b/mosfet/jobs/gather_sand.py index a4c0ce1..8844a4a 100644 --- a/mosfet/jobs/gather_sand.py +++ b/mosfet/jobs/gather_sand.py @@ -151,7 +151,7 @@ class GatherSandStates: self.state = self.find_new_sand def going_to_sand(self): - if self.g.world.block_at(*self.sand) != blocks.SAND: + if self.g.world.block_at(*self.sand) not in blocks.SAND_IDS: self.g.path = [] self._clear_navigation() self.state = self.find_new_sand @@ -175,7 +175,7 @@ class GatherSandStates: time.monotonic() + self.BREAK_CONFIRM_TIMEOUT) def dig_sand(self): - if self.g.world.block_at(*self.sand) != blocks.SAND: + if self.g.world.block_at(*self.sand) not in blocks.SAND_IDS: self.g.look_at = None self.state = self.find_new_sand return @@ -209,7 +209,7 @@ class GatherSandStates: def wait_break(self): if self.break_deadline is None: self._set_break_deadline() - if self.g.world.block_at(*self.sand) != blocks.SAND: + if self.g.world.block_at(*self.sand) not in blocks.SAND_IDS: print('Sand break confirmed at', self.sand) self.g.look_at = None self.state = self.find_new_sand diff --git a/mosfet/world.py b/mosfet/world.py index 33bdc3f..514523e 100644 --- a/mosfet/world.py +++ b/mosfet/world.py @@ -807,7 +807,7 @@ class World: state_id = self.block_at(*position) if state_id is None: return False, 'block is not loaded' - if state_id != blocks.SAND: + if state_id not in blocks.SAND_IDS: name = blocks.BLOCKS.get(state_id, 'unknown block') return False, 'block is {}, not sand'.format(name) @@ -845,7 +845,7 @@ class World: name = blocks.BLOCKS.get(adjacent, 'hazard block') return False, 'unsafe adjacent {} at {}'.format( name, adjacent_pos) - if adjacent == blocks.SAND: + if adjacent in blocks.SAND_IDS: supported, reason = self._sand_has_immediate_support( adjacent_pos) if not supported: @@ -856,7 +856,7 @@ class World: def find_sand(self, center, distance, player): sand = [] - sand.extend(self.find_blocks(center, distance, [blocks.SAND], 25)) + sand.extend(self.find_blocks(center, distance, blocks.SAND_IDS, 25)) safe_sand = [sand for sand in sand if self.sand_safety(sand)[0]] diff --git a/tests/test_indexed_search.py b/tests/test_indexed_search.py index abd5e5b..3ca031c 100644 --- a/tests/test_indexed_search.py +++ b/tests/test_indexed_search.py @@ -47,26 +47,27 @@ class IndexedSearchTests(unittest.TestCase): world_blocks[(1, 63, 0)] = blocks.SAND self.assertTrue(world.sand_safety(sand)[0]) - def test_sand_search_targets_safe_blocks_in_3x3_slice_only(self): - sand_position = (1, 64, 1) + def test_sand_search_targets_safe_sand_types_in_3x3_slice_only(self): + for sand_state in blocks.SAND_IDS: + sand_position = (1, 64, 1) - class SandChunks: - def get_block_at(self, x, y, z): - position = (x, y, z) - if position == sand_position: - return blocks.SAND - if y < sand_position[1]: - return blocks.STONE - return blocks.AIR + class SandChunks: + def get_block_at(self, x, y, z): + position = (x, y, z) + if position == sand_position: + return sand_state + if y < sand_position[1]: + return blocks.STONE + return blocks.AIR - world = World(Munch(chunks=SandChunks())) - - self.assertTrue(world.check_sand_slice((0, 64, 0))) - self.assertEqual( - world.find_sand((0, 64, 0), 2, (0, 64, 0)), - [sand_position]) - sand_position = (2, 64, 0) - self.assertFalse(world.check_sand_slice((0, 64, 0))) + with self.subTest(sand_state=sand_state): + world = World(Munch(chunks=SandChunks())) + self.assertTrue(world.check_sand_slice((0, 64, 0))) + self.assertEqual( + world.find_sand((0, 64, 0), 2, (0, 64, 0)), + [sand_position]) + sand_position = (2, 64, 0) + self.assertFalse(world.check_sand_slice((0, 64, 0))) def test_index_deduplication_is_linear_and_sort_is_optional(self): far = (10, 64, 0) diff --git a/tests/test_storage_labels.py b/tests/test_storage_labels.py index 485cbf5..ac2d4da 100644 --- a/tests/test_storage_labels.py +++ b/tests/test_storage_labels.py @@ -11,7 +11,12 @@ class StorageLabelTests(unittest.TestCase): wheat = items.storage_item_ids_for_label('Wheat') logs = items.storage_item_ids_for_label('Logs') saplings = items.storage_item_ids_for_label('Saplings') + sand = items.storage_item_ids_for_label('Sand') + red_sand = items.storage_item_ids_for_label('Red Sand') + self.assertEqual(sand, {items.SAND_ID}) + self.assertEqual(red_sand, {items.RED_SAND_ID}) + self.assertNotEqual(sand, red_sand) self.assertEqual(seeds, items.get_set({ 'beetroot_seeds', 'melon_seeds', 'pitcher_pod', 'pumpkin_seeds', 'torchflower_seeds', 'wheat_seeds',