mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
registries
This commit is contained in:
parent
d373ee5482
commit
b7bae0830f
8 changed files with 4922 additions and 15 deletions
|
@ -110,8 +110,7 @@ impl From<OptionalGameType> for Option<GameType> {
|
|||
impl McBufReadable for OptionalGameType {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> {
|
||||
let id = i8::read_from(buf)?;
|
||||
GameType::from_optional_id(id)
|
||||
.ok_or(BufReadError::UnexpectedEnumVariant { id: id as i32 })
|
||||
GameType::from_optional_id(id).ok_or(BufReadError::UnexpectedEnumVariant { id: id as i32 })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -8,18 +8,8 @@ import lib.utils
|
|||
|
||||
version_id = lib.code.version.get_version_id()
|
||||
|
||||
|
||||
lib.extract.get_generator_mod_data(version_id, 'blockCollisionShapes')
|
||||
|
||||
# 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_burger = lib.extract.get_block_states_burger(version_id)
|
||||
ordered_blocks = lib.extract.get_ordered_blocks_burger(version_id)
|
||||
|
@ -27,3 +17,7 @@ block_states_report = lib.extract.get_block_states_report(version_id)
|
|||
|
||||
lib.code.blocks.generate_blocks(
|
||||
block_states_burger, block_states_report, ordered_blocks, mappings)
|
||||
|
||||
lib.code.utils.fmt()
|
||||
|
||||
print('Done!')
|
||||
|
|
16
codegen/genregistries.py
Normal file
16
codegen/genregistries.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
import lib.code.registry
|
||||
import lib.code.version
|
||||
import lib.code.packet
|
||||
import lib.code.utils
|
||||
import lib.download
|
||||
import lib.extract
|
||||
import lib.utils
|
||||
|
||||
version_id = lib.code.version.get_version_id()
|
||||
registries = lib.extract.get_registries_report(version_id)
|
||||
|
||||
lib.code.registry.generate_registries(registries)
|
||||
|
||||
lib.code.utils.fmt()
|
||||
|
||||
print('Done!')
|
32
codegen/lib/code/registry.py
Normal file
32
codegen/lib/code/registry.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from typing import Optional
|
||||
from lib.utils import to_snake_case, upper_first_letter, get_dir_location, to_camel_case
|
||||
from ..mappings import Mappings
|
||||
import re
|
||||
|
||||
REGISTRIES_DIR = get_dir_location('../azalea-registry/src/lib.rs')
|
||||
|
||||
|
||||
def generate_registries(registries: dict):
|
||||
code = []
|
||||
|
||||
code.append('use registry_macros::registry;')
|
||||
code.append('')
|
||||
|
||||
for registry_name, registry in registries.items():
|
||||
# registry!(Block, {
|
||||
# Air => "minecraft:air",
|
||||
# Stone => "minecraft:stone"
|
||||
# });
|
||||
registry_struct_name = to_camel_case(registry_name.split(':')[1])
|
||||
code.append(f'registry!({registry_struct_name}, {{')
|
||||
registry_entries = sorted(
|
||||
registry['entries'].items(), key=lambda x: x[1]['protocol_id'])
|
||||
for variant_name, _variant in registry_entries:
|
||||
variant_struct_name = to_camel_case(
|
||||
variant_name.split(':')[1])
|
||||
code.append(f'\t{variant_struct_name} => "{variant_name}",')
|
||||
code.append('});')
|
||||
code.append('')
|
||||
|
||||
with open(REGISTRIES_DIR, 'w') as f:
|
||||
f.write('\n'.join(code))
|
|
@ -24,6 +24,12 @@ def get_block_states_report(version_id: str):
|
|||
return json.load(f)
|
||||
|
||||
|
||||
def get_registries_report(version_id: str):
|
||||
generate_data_from_server_jar(version_id)
|
||||
with open(get_dir_location(f'downloads/generated-{version_id}/reports/registries.json'), 'r') as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
def get_block_states_burger(version_id: str):
|
||||
burger_data = get_burger_data_for_version(version_id)
|
||||
return burger_data[0]['blocks']['block']
|
||||
|
|
|
@ -10,7 +10,8 @@ def to_snake_case(name: str):
|
|||
|
||||
|
||||
def to_camel_case(name: str):
|
||||
s = re.sub('_([a-z])', lambda m: m.group(1).upper(), name)
|
||||
s = re.sub('[_ ](\w)', lambda m: m.group(1).upper(),
|
||||
name.replace('.', '_').replace('/', '_'))
|
||||
s = upper_first_letter(s)
|
||||
# if the first character is a number, we need to add an underscore
|
||||
# maybe we could convert it to the number name (like 2 would become "two")?
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
from lib.code.packet import fix_state
|
||||
from lib.utils import PacketIdentifier, group_packets
|
||||
import lib.code.utils
|
||||
import lib.code.version
|
||||
import lib.code.blocks
|
||||
import lib.code.packet
|
||||
import lib.code.utils
|
||||
import lib.download
|
||||
import lib.extract
|
||||
import sys
|
||||
|
@ -102,6 +103,20 @@ lib.code.version.set_protocol_version(
|
|||
new_burger_data[0]['version']['protocol'])
|
||||
lib.code.version.set_version_id(new_version_id)
|
||||
|
||||
print('Updated protocol!')
|
||||
|
||||
|
||||
old_ordered_blocks = lib.extract.get_ordered_blocks_burger(old_version_id)
|
||||
new_ordered_blocks = lib.extract.get_ordered_blocks_burger(new_version_id)
|
||||
if old_ordered_blocks != new_ordered_blocks:
|
||||
print('Blocks changed, updating...')
|
||||
block_states_burger = lib.extract.get_block_states_burger(new_version_id)
|
||||
block_states_report = lib.extract.get_block_states_report(new_version_id)
|
||||
|
||||
lib.code.blocks.generate_blocks(
|
||||
block_states_burger, block_states_report, old_ordered_blocks, new_mappings)
|
||||
|
||||
|
||||
lib.code.utils.fmt()
|
||||
|
||||
print('Done!')
|
||||
|
|
Loading…
Add table
Reference in a new issue