Start work on implementing multi-state blocks in blocks.py
@@ -52,6 +52,8 @@ from_block_state_id_code = ""
from_block_state_id_code += "pub fn from_block_state_id(id: u16) -> Self {\n" \
"match id {" \
+state_code = ""
+
for block_prop_name in data:
print("Reading for block %s", block_prop_name)
block_name = strip_minecraft_identifier(block_prop_name)
@@ -60,17 +62,21 @@ for block_prop_name in data:
states = obj["states"]
single_state = len(states) == 1
+ camel = snake_to_upper_camel(block_name)
if single_state:
- camel = snake_to_upper_camel(block_name)
id = str(states[0]["id"])
enum_code += camel + ",\n"
block_state_id_code += "Block::" + camel + " => " + id + ",\n"
from_block_state_id_code += id + " => Block::" + camel + ",\n"
else:
- print("unimplemented")
+ state_code += "pub struct " + camel + "Data {"
+ props = obj["properties"]
+ for prop_name in props:
+ vals = props[prop_name]
+ state_code += "}"
enum_code += "}"
@@ -79,9 +85,12 @@ block_state_id_code += "}\n}"
from_block_state_id_code += "_ => panic!(\"Unknown block state ID {}\", id),"
from_block_state_id_code += "}\n}"
+fout.write("// This file was generated by /scripts/blocks.py\n\n")
fout.write(enum_code)
+fout.write("\n")
fout.write("impl Block {\n")
fout.write(block_state_id_code)
fout.write("\n\n")
fout.write(from_block_state_id_code)
fout.write("}")
+fout.write("\n" + state_code)
\ No newline at end of file
