Simplify handling block and item ids

This commit is contained in:
Tanner Collin 2021-04-18 23:02:16 +00:00
parent fac4309e43
commit 5ff0394dc3
2 changed files with 38 additions and 101 deletions

100
blocks.py
View File

@ -28,10 +28,6 @@ EMERALD_BLOCK = 5407
TEST_BLOCK = (616, 78, 496)
WATER = [
'water',
]
AVOID = [
'lava',
'water',
@ -263,89 +259,37 @@ INDEXED = [
'barrel',
] + BEDS
NON_SOLID_IDS = set([SINGLE_SNOW])
for block_name in NON_SOLID:
def get_set(ids):
result = set()
for block_name in ids:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
NON_SOLID_IDS.add(state['id'])
AVOID_IDS = set()
for block_name in AVOID:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
AVOID_IDS.add(state['id'])
WATER_IDS = set()
for block_name in WATER:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
WATER_IDS.add(state['id'])
LOG_IDS = set()
for block_name in LOGS:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
LOG_IDS.add(state['id'])
LEAF_IDS = set()
for block_name in LEAVES:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
LEAF_IDS.add(state['id'])
CHEST_IDS = set()
for block_name in ['chest']:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
CHEST_IDS.add(state['id'])
BARREL_IDS = set()
for block_name in ['barrel']:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
BARREL_IDS.add(state['id'])
TRAPPED_CHEST_IDS = set()
for block_name in ['trapped_chest']:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
TRAPPED_CHEST_IDS.add(state['id'])
NETHERWART_IDS = set()
for block_name in ['nether_wart']:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
NETHERWART_IDS.add(state['id'])
WHEAT_IDS = set()
for block_name in ['wheat']:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
WHEAT_IDS.add(state['id'])
POTATO_IDS = set()
for block_name in ['potatoes']:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
POTATO_IDS.add(state['id'])
CARROT_IDS = set()
for block_name in ['carrots']:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
CARROT_IDS.add(state['id'])
BEETROOT_IDS = set()
for block_name in ['beetroots']:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
BEETROOT_IDS.add(state['id'])
SAPLING_IDS = set()
for block_name in SAPLINGS:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
SAPLING_IDS.add(state['id'])
BED_IDS = set()
for block_name in BEDS:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
BED_IDS.add(state['id'])
result.add(state['id'])
return result
NON_SOLID_IDS = get_set(NON_SOLID)
NON_SOLID_IDS.add(SINGLE_SNOW)
AVOID_IDS = get_set(AVOID)
WATER_IDS = get_set(['water'])
LOG_IDS = get_set(LOGS)
LEAF_IDS = get_set(LEAVES)
CHEST_IDS = get_set(['chest'])
BARREL_IDS = get_set(['barrel'])
TRAPPED_CHEST_IDS = get_set(['trapped_chest'])
NETHERWART_IDS = get_set(['nether_wart'])
WHEAT_IDS = get_set(['wheat'])
POTATO_IDS = get_set(['potatoes'])
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'])
MATURE_WHEAT_ID = max(WHEAT_IDS)
MATURE_POTATO_ID = max(POTATO_IDS)
MATURE_CARROT_ID = max(CARROT_IDS)

View File

@ -67,34 +67,25 @@ LOGS = [
'dark_oak_log',
]
BED_IDS = set()
for item_name in BEDS:
BED_IDS.add(ITEMS['minecraft:'+item_name]['protocol_id'])
SHOVEL_IDS = set()
for item_name in SHOVELS:
SHOVEL_IDS.add(ITEMS['minecraft:'+item_name]['protocol_id'])
def get_set(ids):
result = set()
for item_name in ids:
result.add(ITEMS['minecraft:'+item_name]['protocol_id'])
return result
AXE_IDS = set()
for item_name in AXES:
AXE_IDS.add(ITEMS['minecraft:'+item_name]['protocol_id'])
FOOD_IDS = set()
for item_name in FOOD:
FOOD_IDS.add(ITEMS['minecraft:'+item_name]['protocol_id'])
SAPLING_IDS = set()
for item_name in SAPLINGS:
SAPLING_IDS.add(ITEMS['minecraft:'+item_name]['protocol_id'])
LOG_IDS = set()
for item_name in LOGS:
LOG_IDS.add(ITEMS['minecraft:'+item_name]['protocol_id'])
BED_IDS = get_set(BEDS)
SHOVEL_IDS = get_set(SHOVELS)
AXE_IDS = get_set(AXES)
FOOD_IDS = get_set(FOOD)
SAPLING_IDS = get_set(SAPLINGS)
LOG_IDS = get_set(LOGS)
ITEM_NAMES = {}
for item_name, item in ITEMS.items():
ITEM_NAMES[ITEMS[item_name]['protocol_id']] = item_name.replace('minecraft:', '')
def get_id(name):
return ITEMS['minecraft:' + name]['protocol_id']
@ -115,7 +106,9 @@ BERRIES_ID = get_id('sweet_berries')
IRON_INGOT_ID = get_id('iron_ingot')
INIT_NEEDED_ITEMS = BED_IDS | FOOD_IDS | set([CHEST_ID])
INIT_NEEDED_ITEMS = BED_IDS | FOOD_IDS
INIT_NEEDED_ITEMS.add(CHEST_ID)
NEEDED_ITEMS = INIT_NEEDED_ITEMS
INIT_WANTED_ITEMS = set()