Begin port to 26.3: movement

This commit is contained in:
Tanner
2026-11-03 22:48:15 +00:00
parent 891f14b988
commit 59c76471f2
23 changed files with 30692 additions and 478 deletions
+84 -273
View File
@@ -1,280 +1,84 @@
import json
import importlib
"""Minecraft 26.3 block-state metadata and legacy automation selectors."""
from itertools import product
from mosfet.info import mcdata
MCD_BLOCKS = {}
for d in mcdata.mcd.blocks.values():
MCD_BLOCKS[d['name']] = d
with open('minecraft_data/blocks.json') as f:
JSON_BLOCKS = json.load(f)
MCD_BLOCKS = mcdata.mcd.blocks
JSON_BLOCKS = {'minecraft:' + name: data
for name, data in MCD_BLOCKS.items()}
BLOCKS = {}
for name, data in JSON_BLOCKS.items():
for state in data['states']:
BLOCKS[state['id']] = name.replace('minecraft:', '')
PROPS = {}
for name, data in JSON_BLOCKS.items():
for state in data['states']:
PROPS[state['id']] = state.get('properties', {})
COLLISION_BOXES = {}
for name, data in MCD_BLOCKS.items():
first = data['minStateId']
last = data['maxStateId']
properties = data.get('states', [])
property_values = [prop.get('values', []) for prop in properties]
combinations = list(product(*property_values)) if property_values else [()]
for offset, state_id in enumerate(range(first, last + 1)):
BLOCKS[state_id] = name
if offset < len(combinations):
PROPS[state_id] = {
prop['name']: value
for prop, value in zip(properties, combinations[offset])
}
else:
PROPS[state_id] = {}
shape_ref = mcdata.mcd.collision_shapes['blocks'].get(name, 1)
refs = shape_ref if isinstance(shape_ref, list) else [shape_ref] * (last-first+1)
for offset, state_id in enumerate(range(first, last + 1)):
ref = refs[offset] if offset < len(refs) else refs[-1]
COLLISION_BOXES[state_id] = mcdata.mcd.collision_shapes['shapes'].get(
str(ref), [])
BREAK_DISTANCE = 6
AIR = 0
STONE = 1
SAND = 66
SINGLE_SNOW = 3921
SOUL_TORCH = 4008
EMERALD_BLOCK = 5407
AIR = MCD_BLOCKS['air']['minStateId']
STONE = MCD_BLOCKS['stone']['minStateId']
SAND = MCD_BLOCKS['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(
'minStateId', AIR)
TEST_BLOCK = (616, 78, 496)
AVOID = [
'lava',
'water',
'fire',
'magma_block',
'oak_fence',
'oak_fence_gate',
'nether_brick_fence',
'spruce_fence_gate',
'birch_fence_gate',
'jungle_fence_gate',
'acacia_fence_gate',
'dark_oak_fence_gate',
'spruce_fence',
'birch_fence',
'jungle_fence',
'acacia_fence',
'dark_oak_fence',
'sweet_berry_bush',
'nether_portal',
'end_portal',
'cobblestone_wall',
'mossy_cobblestone_wall',
'brick_wall',
'prismarine_wall',
'red_sandstone_wall',
'mossy_stone_brick_wall',
'granite_wall',
'stone_brick_wall',
'nether_brick_wall',
'andesite_wall',
'red_nether_brick_wall',
'sandstone_wall',
'end_stone_brick_wall',
'diorite_wall',
'oak_sapling', # saplings can grow up and hurt
'spruce_sapling',
'birch_sapling',
'jungle_sapling',
'acacia_sapling',
'dark_oak_sapling',
]
NON_SOLID = [
'air',
'powered_rail',
'detector_rail',
'grass',
'fern',
'dead_bush',
'seagrass',
'tall_seagrass',
'dandelion',
'poppy',
'blue_orchid',
'allium',
'azure_bluet',
'red_tulip',
'orange_tulip',
'white_tulip',
'pink_tulip',
'oxeye_daisy',
'cornflower',
'wither_rose',
'lily_of_the_valley',
'brown_mushroom',
'red_mushroom',
'torch',
'wall_torch',
'redstone_wire',
'wheat',
'oak_sign',
'spruce_sign',
'birch_sign',
'acacia_sign',
'jungle_sign',
'dark_oak_sign',
'rail',
'oak_wall_sign',
'spruce_wall_sign',
'birch_wall_sign',
'acacia_wall_sign',
'jungle_wall_sign',
'dark_oak_wall_sign',
'lever',
'stone_pressure_plate',
'oak_pressure_plate',
'spruce_pressure_plate',
'birch_pressure_plate',
'jungle_pressure_plate',
'acacia_pressure_plate',
'dark_oak_pressure_plate',
'redstone_torch',
'redstone_wall_torch',
'stone_button',
'sugar_cane',
'repeater',
'attached_pumpkin_stem',
'attached_melon_stem',
'pumpkin_stem',
'melon_stem',
'nether_wart',
'tripwire_hook',
'tripwire',
'carrots',
'potatoes',
'oak_button',
'spruce_button',
'birch_button',
'jungle_button',
'acacia_button',
'dark_oak_button',
'light_weighted_pressure_plate',
'heavy_weighted_pressure_plate',
'comparator',
'activator_rail',
'white_carpet',
'orange_carpet',
'magenta_carpet',
'light_blue_carpet',
'yellow_carpet',
'lime_carpet',
'pink_carpet',
'gray_carpet',
'light_gray_carpet',
'cyan_carpet',
'purple_carpet',
'blue_carpet',
'brown_carpet',
'green_carpet',
'red_carpet',
'black_carpet',
'sunflower',
'lilac',
'rose_bush',
'peony',
'tall_grass',
'large_fern',
'white_banner',
'orange_banner',
'magenta_banner',
'light_blue_banner',
'yellow_banner',
'lime_banner',
'pink_banner',
'gray_banner',
'light_gray_banner',
'cyan_banner',
'purple_banner',
'blue_banner',
'brown_banner',
'green_banner',
'red_banner',
'black_banner',
'white_wall_banner',
'orange_wall_banner',
'magenta_wall_banner',
'light_blue_wall_banner',
'yellow_wall_banner',
'lime_wall_banner',
'pink_wall_banner',
'gray_wall_banner',
'light_gray_wall_banner',
'cyan_wall_banner',
'purple_wall_banner',
'blue_wall_banner',
'brown_wall_banner',
'green_wall_banner',
'red_wall_banner',
'black_wall_banner',
'beetroots',
'bamboo_sapling',
'void_air',
'cave_air',
'lantern',
'soul_torch',
]
LOGS = [
'oak_log',
'spruce_log',
'birch_log',
'jungle_log',
'acacia_log',
'dark_oak_log',
]
LEAVES = [
'oak_leaves',
'spruce_leaves',
'birch_leaves',
'jungle_leaves',
'acacia_leaves',
'dark_oak_leaves',
]
SAPLINGS = [
'oak_sapling',
'spruce_sapling',
'birch_sapling',
'jungle_sapling',
'acacia_sapling',
'dark_oak_sapling',
]
BEDS = [
'white_bed',
'orange_bed',
'magenta_bed',
'light_blue_bed',
'yellow_bed',
'lime_bed',
'pink_bed',
'gray_bed',
'light_gray_bed',
'cyan_bed',
'purple_bed',
'blue_bed',
'brown_bed',
'green_bed',
'red_bed',
'black_bed',
]
INDEXED = [
'chest',
'trapped_chest',
'emerald_block',
'barrel',
] + BEDS
def get_set(ids):
def get_set(names):
"""Return every state ID belonging to the named blocks; ignore removed names."""
result = set()
for block_name in ids:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
result.add(state['id'])
for name in names:
name = name.removeprefix('minecraft:')
data = MCD_BLOCKS.get(name)
if data is not None:
result.update(range(data['minStateId'], data['maxStateId'] + 1))
return result
NON_SOLID_IDS = get_set(NON_SOLID)
NON_SOLID_IDS.add(SINGLE_SNOW)
# 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
}
AVOID = {
'lava', 'water', 'fire', 'magma_block', 'sweet_berry_bush',
'nether_portal', 'end_portal', 'cactus', 'powder_snow',
}
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
LOG_IDS = get_set(LOGS)
LEAF_IDS = get_set(LEAVES)
CHEST_IDS = get_set(['chest'])
@@ -287,21 +91,28 @@ CARROT_IDS = get_set(['carrots'])
BEETROOT_IDS = get_set(['beetroots'])
SAPLING_IDS = get_set(SAPLINGS)
BED_IDS = get_set(BEDS)
INDEXED_IDS = set()
for block_name in INDEXED:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
INDEXED_IDS.add(state['id'])
INDEXED_IDS = get_set(INDEXED)
MATURE_WHEAT_ID = max(WHEAT_IDS)
MATURE_POTATO_ID = max(POTATO_IDS)
MATURE_CARROT_ID = max(CARROT_IDS)
MATURE_BEETROOT_ID = max(BEETROOT_IDS)
def _mature_state(name, property_name, mature_value):
data = MCD_BLOCKS.get(name)
if data is None:
return None
for state_id in range(data['minStateId'], data['maxStateId'] + 1):
if PROPS[state_id].get(property_name) == str(mature_value):
return state_id
return data['maxStateId']
MATURE_WHEAT_ID = _mature_state('wheat', 'age', 7)
MATURE_POTATO_ID = _mature_state('potatoes', 'age', 7)
MATURE_CARROT_ID = _mature_state('carrots', 'age', 7)
MATURE_BEETROOT_ID = _mature_state('beetroots', 'age', 3)
def get(block_state_id):
return MCD_BLOCKS[BLOCKS[block_state_id]]
def get(bid):
name = BLOCKS[bid]
return MCD_BLOCKS[name]
def find(name):
return MCD_BLOCKS[name]
return MCD_BLOCKS[name.removeprefix('minecraft:')]