-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_list_classes.py
48 lines (40 loc) · 1.6 KB
/
generate_list_classes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
from typing import cast, Any
with open('src/main/resources/blockStates.json') as fp:
in_json = cast(dict[str, Any], json.load(fp))
with open('src/main/kotlin/io/github/gaming32/mckt/world/Blocks.kt', 'w') as fp:
def p(line: str) -> None:
print(line, file=fp)
p('package io.github.gaming32.mckt.world')
p('')
p('import io.github.gaming32.mckt.GlobalPalette.DEFAULT_BLOCKSTATES')
p('import io.github.gaming32.mckt.objects.Identifier')
p('')
p('@Suppress("unused")')
p('object Blocks {')
p(' private fun getBlock(id: String) =')
p(' DEFAULT_BLOCKSTATES[Identifier.parse(id)] ?: throw Error("Standard block $id not found")')
p('')
for block in in_json.keys():
if not block.startswith("minecraft:"):
continue
block = block.removeprefix("minecraft:")
p(f' val {block.upper()} = getBlock("{block}")')
p('}')
with open('src/main/resources/dataexport/materials.json') as fp:
in_json = cast(dict[str, Any], json.load(fp))
with open('src/main/kotlin/io/github/gaming32/mckt/world/Materials.kt', 'w') as fp:
def p(line: str) -> None:
print(line, file=fp)
p('package io.github.gaming32.mckt.world')
p('')
p('import io.github.gaming32.mckt.BLOCK_MATERIALS')
p('')
p('@Suppress("unused")')
p('object Materials {')
p(' private fun getMaterial(name: String) =')
p(' BLOCK_MATERIALS[name] ?: throw Error("Standard material $name not found")')
p('')
for material in in_json.keys():
p(f' val {material.upper()} = getMaterial("{material}")')
p('}')