From 0b462f4a7612ed9bf695b5e7e9ffd038dd68f0ff Mon Sep 17 00:00:00 2001 From: Tanner Date: Thu, 19 Nov 2026 14:42:07 +0000 Subject: [PATCH] Avoid planted saplings when pathfinding --- mosfet/info/blocks.py | 14 +++++++------- tests/test_door_navigation.py | 11 +++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/mosfet/info/blocks.py b/mosfet/info/blocks.py index fff1ab4..f7c4e66 100644 --- a/mosfet/info/blocks.py +++ b/mosfet/info/blocks.py @@ -60,6 +60,12 @@ def get_set(names): SAND_IDS = get_set(['sand', 'red_sand']) +LOGS = sorted(name for name in MCD_BLOCKS + if name.endswith(('_log', '_wood', '_stem', '_hyphae'))) +LEAVES = sorted(name for name in MCD_BLOCKS if name.endswith('_leaves')) +SAPLINGS = sorted(name for name in MCD_BLOCKS + if name.endswith('_sapling') or name.endswith('_propagule')) + # 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 @@ -67,19 +73,13 @@ NON_SOLID_IDS = { AVOID = { 'lava', 'water', 'fire', 'magma_block', 'sweet_berry_bush', 'nether_portal', 'end_portal', 'cactus', 'powder_snow', -} +} | set(SAPLINGS) AVOID_IDS = get_set(AVOID) AVOID_IDS.update( state_id for state_id, name in BLOCKS.items() if name.endswith(('_fence', '_fence_gate', '_wall')) ) WATER_IDS = get_set(['water']) - -LOGS = sorted(name for name in MCD_BLOCKS - if name.endswith(('_log', '_wood', '_stem', '_hyphae'))) -LEAVES = sorted(name for name in MCD_BLOCKS if name.endswith('_leaves')) -SAPLINGS = sorted(name for name in MCD_BLOCKS - if name.endswith('_sapling') or name.endswith('_propagule')) BEDS = sorted(name for name in MCD_BLOCKS if name.endswith('_bed')) INDEXED = ['chest', 'trapped_chest', 'emerald_block', 'barrel'] + BEDS + [ 'wheat', 'potatoes', 'carrots', 'beetroots', 'nether_wart', diff --git a/tests/test_door_navigation.py b/tests/test_door_navigation.py index b4e1ebe..c323bbf 100644 --- a/tests/test_door_navigation.py +++ b/tests/test_door_navigation.py @@ -27,6 +27,17 @@ class DoorNavigationTests(unittest.TestCase): blocks.PROPS[state].get('open') == str(opened).lower() and blocks.PROPS[state].get('powered') == str(powered).lower()) + def test_pathfinder_avoids_all_sapling_and_propagule_states(self): + self.assertTrue(blocks.SAPLING_IDS) + self.assertLessEqual(blocks.SAPLING_IDS, blocks.AVOID_IDS) + + state_id = next(iter(blocks.SAPLING_IDS)) + finder = Pathfinder(Munch( + chunks=FakeChunks({(1, 64, 0): state_id}), + crawling=False, unopenable_doors=set())) + self.assertTrue(finder.bavoid((1, 64, 0))) + self.assertFalse(finder.check_traverse((0, 64, 0), (1, 0, 0))) + def test_pathfinder_treats_openable_doors_as_passable_but_not_iron(self): wooden = self.door_state('oak_door') iron = self.door_state('iron_door')