mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
Clean code a little
This commit is contained in:
parent
8c5d7407fe
commit
6926907528
2 changed files with 54 additions and 46 deletions
|
@ -8,6 +8,11 @@ pub trait Block {
|
||||||
|
|
||||||
make_block_states! {
|
make_block_states! {
|
||||||
Properties => {
|
Properties => {
|
||||||
|
Face {
|
||||||
|
Floor,
|
||||||
|
Wall,
|
||||||
|
Ceiling,
|
||||||
|
},
|
||||||
Facing {
|
Facing {
|
||||||
North,
|
North,
|
||||||
South,
|
South,
|
||||||
|
@ -18,24 +23,15 @@ make_block_states! {
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
},
|
},
|
||||||
Face {
|
|
||||||
Floor,
|
|
||||||
Wall,
|
|
||||||
Ceiling,
|
|
||||||
},
|
|
||||||
Half {
|
Half {
|
||||||
Top,
|
Top,
|
||||||
Bottom,
|
Bottom,
|
||||||
},
|
},
|
||||||
Open {
|
|
||||||
True,
|
|
||||||
False,
|
|
||||||
},
|
|
||||||
Hinge {
|
Hinge {
|
||||||
Left,
|
Left,
|
||||||
Right,
|
Right,
|
||||||
},
|
},
|
||||||
North {
|
Open {
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
},
|
},
|
||||||
|
@ -43,7 +39,7 @@ make_block_states! {
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
},
|
},
|
||||||
West {
|
North {
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
},
|
},
|
||||||
|
@ -55,6 +51,10 @@ make_block_states! {
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
},
|
},
|
||||||
|
West {
|
||||||
|
True,
|
||||||
|
False,
|
||||||
|
},
|
||||||
InWall {
|
InWall {
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
|
@ -111,30 +111,30 @@ make_block_states! {
|
||||||
OuterLeft,
|
OuterLeft,
|
||||||
OuterRight,
|
OuterRight,
|
||||||
},
|
},
|
||||||
Up {
|
EastWall {
|
||||||
True,
|
None,
|
||||||
False,
|
Low,
|
||||||
|
Tall,
|
||||||
},
|
},
|
||||||
NorthWall {
|
NorthWall {
|
||||||
None,
|
None,
|
||||||
Low,
|
Low,
|
||||||
Tall,
|
Tall,
|
||||||
},
|
},
|
||||||
EastWall {
|
SouthWall {
|
||||||
None,
|
None,
|
||||||
Low,
|
Low,
|
||||||
Tall,
|
Tall,
|
||||||
},
|
},
|
||||||
|
Up {
|
||||||
|
True,
|
||||||
|
False,
|
||||||
|
},
|
||||||
WestWall {
|
WestWall {
|
||||||
None,
|
None,
|
||||||
Low,
|
Low,
|
||||||
Tall,
|
Tall,
|
||||||
},
|
},
|
||||||
SouthWall {
|
|
||||||
None,
|
|
||||||
Low,
|
|
||||||
Tall,
|
|
||||||
},
|
|
||||||
Age {
|
Age {
|
||||||
_0,
|
_0,
|
||||||
_1,
|
_1,
|
||||||
|
@ -170,14 +170,14 @@ make_block_states! {
|
||||||
Partial,
|
Partial,
|
||||||
Full,
|
Full,
|
||||||
},
|
},
|
||||||
Part {
|
|
||||||
Head,
|
|
||||||
Foot,
|
|
||||||
},
|
|
||||||
Occupied {
|
Occupied {
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
},
|
},
|
||||||
|
Part {
|
||||||
|
Head,
|
||||||
|
Foot,
|
||||||
|
},
|
||||||
Candles {
|
Candles {
|
||||||
_1,
|
_1,
|
||||||
_2,
|
_2,
|
||||||
|
@ -228,6 +228,10 @@ make_block_states! {
|
||||||
_2,
|
_2,
|
||||||
_3,
|
_3,
|
||||||
},
|
},
|
||||||
|
Inverted {
|
||||||
|
True,
|
||||||
|
False,
|
||||||
|
},
|
||||||
Power {
|
Power {
|
||||||
_0,
|
_0,
|
||||||
_1,
|
_1,
|
||||||
|
@ -246,10 +250,6 @@ make_block_states! {
|
||||||
_14,
|
_14,
|
||||||
_15,
|
_15,
|
||||||
},
|
},
|
||||||
Inverted {
|
|
||||||
True,
|
|
||||||
False,
|
|
||||||
},
|
|
||||||
Triggered {
|
Triggered {
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
|
@ -355,10 +355,6 @@ make_block_states! {
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
},
|
},
|
||||||
TipDirection {
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
},
|
|
||||||
Thickness {
|
Thickness {
|
||||||
TipMerge,
|
TipMerge,
|
||||||
Tip,
|
Tip,
|
||||||
|
@ -366,6 +362,10 @@ make_block_states! {
|
||||||
Middle,
|
Middle,
|
||||||
Base,
|
Base,
|
||||||
},
|
},
|
||||||
|
TipDirection {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
},
|
||||||
Delay {
|
Delay {
|
||||||
_1,
|
_1,
|
||||||
_2,
|
_2,
|
||||||
|
@ -396,11 +396,11 @@ make_block_states! {
|
||||||
Active,
|
Active,
|
||||||
Cooldown,
|
Cooldown,
|
||||||
},
|
},
|
||||||
Shrieking {
|
CanSummon {
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
},
|
},
|
||||||
CanSummon {
|
Shrieking {
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
},
|
},
|
||||||
|
@ -450,17 +450,17 @@ make_block_states! {
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
},
|
},
|
||||||
Hatch {
|
|
||||||
_0,
|
|
||||||
_1,
|
|
||||||
_2,
|
|
||||||
},
|
|
||||||
Eggs {
|
Eggs {
|
||||||
_1,
|
_1,
|
||||||
_2,
|
_2,
|
||||||
_3,
|
_3,
|
||||||
_4,
|
_4,
|
||||||
},
|
},
|
||||||
|
Hatch {
|
||||||
|
_0,
|
||||||
|
_1,
|
||||||
|
_2,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Blocks => {
|
Blocks => {
|
||||||
acacia_button => BlockBehavior::default(), {
|
acacia_button => BlockBehavior::default(), {
|
||||||
|
|
|
@ -18,7 +18,7 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, mappings: Mappings
|
||||||
new_make_block_states_macro_code = []
|
new_make_block_states_macro_code = []
|
||||||
new_make_block_states_macro_code.append('make_block_states! {')
|
new_make_block_states_macro_code.append('make_block_states! {')
|
||||||
|
|
||||||
def get_property_name(property: dict, block_data_burger: dict) -> str:
|
def get_property_struct_name(property: dict, block_data_burger: dict) -> str:
|
||||||
property_name = None
|
property_name = None
|
||||||
for class_name in [block_data_burger['class']] + block_data_burger['super']:
|
for class_name in [block_data_burger['class']] + block_data_burger['super']:
|
||||||
property_name = mappings.get_field(class_name, property['field_name'])
|
property_name = mappings.get_field(class_name, property['field_name'])
|
||||||
|
@ -34,11 +34,20 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, mappings: Mappings
|
||||||
block_data_report = blocks_report[f'minecraft:{block_id}']
|
block_data_report = blocks_report[f'minecraft:{block_id}']
|
||||||
|
|
||||||
block_properties = {}
|
block_properties = {}
|
||||||
for property in block_data_burger.get('states', []):
|
for property_name in list(block_data_report.get('properties', {}).keys()):
|
||||||
property_variants = block_data_report['properties'][property['name']]
|
property_burger = None
|
||||||
property_name = get_property_name(property, block_data_burger)
|
for property in block_data_burger['states']:
|
||||||
|
if property['name'] == property_name:
|
||||||
|
property_burger = property
|
||||||
|
break
|
||||||
|
if property_burger is None:
|
||||||
|
print('Error: The reports have states for a block, but Burger doesn\'t!', block_data_burger)
|
||||||
|
continue
|
||||||
|
# assert property_burger is not None
|
||||||
|
property_variants = block_data_report['properties'][property_name]
|
||||||
|
property_struct_name = get_property_struct_name(property_burger, block_data_burger)
|
||||||
|
|
||||||
block_properties[property_name] = property_variants
|
block_properties[property_struct_name] = property_variants
|
||||||
properties.update(block_properties)
|
properties.update(block_properties)
|
||||||
|
|
||||||
# Property codegen
|
# Property codegen
|
||||||
|
@ -70,10 +79,9 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, mappings: Mappings
|
||||||
# TODO: use burger to generate the blockbehavior
|
# TODO: use burger to generate the blockbehavior
|
||||||
new_make_block_states_macro_code.append(
|
new_make_block_states_macro_code.append(
|
||||||
f' {block_id} => BlockBehavior::default(), {{')
|
f' {block_id} => BlockBehavior::default(), {{')
|
||||||
print('block data', block_data_burger)
|
|
||||||
for property in block_properties_burger:
|
for property in block_properties_burger:
|
||||||
property_default = default_property_variants.get(property['name'])
|
property_default = default_property_variants.get(property['name'])
|
||||||
property_struct_name = get_property_name(property, block_data_burger)
|
property_struct_name = get_property_struct_name(property, block_data_burger)
|
||||||
assert property_default is not None
|
assert property_default is not None
|
||||||
new_make_block_states_macro_code.append(
|
new_make_block_states_macro_code.append(
|
||||||
f' {to_camel_case(property_struct_name)}={to_camel_case(property_default)},')
|
f' {to_camel_case(property_struct_name)}={to_camel_case(property_default)},')
|
||||||
|
|
Loading…
Add table
Reference in a new issue