mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
work on genblocks
This commit is contained in:
parent
7d4eceefde
commit
4a3a2d2a3d
4 changed files with 49 additions and 9 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"editor.formatOnSave": true
|
||||
"editor.formatOnSave": false
|
||||
}
|
|
@ -4,10 +4,22 @@ import lib.code.blocks
|
|||
import lib.code.utils
|
||||
import lib.download
|
||||
import lib.extract
|
||||
import lib.utils
|
||||
import sys
|
||||
import os
|
||||
|
||||
version_id = lib.code.version.get_version_id()
|
||||
|
||||
lib.download.get_burger()
|
||||
lib.download.get_client_jar(version_id)
|
||||
|
||||
print('Generating data with burger')
|
||||
os.system(
|
||||
f'cd {lib.utils.get_dir_location("downloads/Burger")} && python munch.py ../client-{version_id}.jar --output ../burger-{version_id}.json --toppings blockstates'
|
||||
)
|
||||
print('Ok')
|
||||
|
||||
mappings = lib.download.get_mappings_for_version(version_id)
|
||||
block_states_data = lib.extract.get_block_states(version_id)
|
||||
|
||||
lib.code.blocks.generate_blocks(block_states_data)
|
||||
lib.code.blocks.generate_blocks(block_states_data, mappings)
|
||||
|
|
|
@ -1,11 +1,29 @@
|
|||
from lib.utils import to_camel_case
|
||||
from lib.utils import get_dir_location
|
||||
from lib.utils import to_camel_case
|
||||
from ..mappings import Mappings
|
||||
import json
|
||||
|
||||
BLOCKS_RS_DIR = get_dir_location('../azalea-block/src/blocks.rs')
|
||||
|
||||
# Terminology:
|
||||
# - Property: A property of a block, like "direction"
|
||||
# - Variant: A potential state of a property, like "up"
|
||||
# - State: A possible state of a block, a combination of variants
|
||||
# - Block: Has properties and states.
|
||||
|
||||
def generate_blocks(blocks: dict):
|
||||
|
||||
def get_property_variants(data) -> list[str]:
|
||||
if 'values' in data:
|
||||
return list(map(str.lower, data['values']))
|
||||
if data['type'] == 'bool':
|
||||
return ['true', 'false']
|
||||
if data['type'] == 'int':
|
||||
# range between data['min'] and data['max']
|
||||
return [str(i) for i in range(data['min'], data['max'] + 1)]
|
||||
raise Exception('Unknown property type: ' + data['type'])
|
||||
|
||||
|
||||
def generate_blocks(blocks: dict, mappings: Mappings):
|
||||
with open(BLOCKS_RS_DIR, 'r') as f:
|
||||
existing_code = f.read().splitlines()
|
||||
|
||||
|
@ -15,7 +33,14 @@ def generate_blocks(blocks: dict):
|
|||
# Find properties
|
||||
properties = {}
|
||||
for block_data in blocks.values():
|
||||
block_properties = block_data.get('properties', {})
|
||||
block_properties = {}
|
||||
for property in block_data.get('states', []):
|
||||
property_name = mappings.get_field(
|
||||
property.get('declared_in', block_data['class']), property['field_name']).lower()
|
||||
property_variants = get_property_variants(property)
|
||||
block_properties[property_name] = property_variants
|
||||
# if property_name == 'eggs':
|
||||
# print(property, property_name, property_variants)
|
||||
properties.update(block_properties)
|
||||
|
||||
# Property codegen
|
||||
|
@ -35,7 +60,6 @@ def generate_blocks(blocks: dict):
|
|||
# Block codegen
|
||||
new_make_block_states_macro_code.append(' Blocks => {')
|
||||
for block_id, block_data in blocks.items():
|
||||
block_id = block_id.split(':')[1]
|
||||
block_states = block_data['states']
|
||||
|
||||
default_property_variants = {}
|
||||
|
|
|
@ -16,10 +16,14 @@ def generate_data_from_server_jar(version_id: str):
|
|||
)
|
||||
|
||||
|
||||
# the minecraft server jar doesn't give enough useful info so we use burger instead
|
||||
# def get_block_states(version_id: str):
|
||||
# generate_data_from_server_jar(version_id)
|
||||
# with open(get_dir_location(f'downloads/generated-{version_id}/reports/blocks.json'), 'r') as f:
|
||||
# return json.load(f)
|
||||
def get_block_states(version_id: str):
|
||||
generate_data_from_server_jar(version_id)
|
||||
with open(get_dir_location(f'downloads/generated-{version_id}/reports/blocks.json'), 'r') as f:
|
||||
return json.load(f)
|
||||
burger_data = get_burger_data_for_version(version_id)
|
||||
return burger_data[0]['blocks']['block']
|
||||
|
||||
|
||||
def get_burger_data_for_version(version_id: str):
|
||||
|
|
Loading…
Add table
Reference in a new issue