-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.py
More file actions
54 lines (42 loc) · 1.93 KB
/
Copy pathgenerate.py
File metadata and controls
54 lines (42 loc) · 1.93 KB
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
49
50
51
52
53
"""Generate all packets, blocks, and other asset data extracted from Minecraft"""
import logging
import json
def generate():
packets = None
if packets is None:
with open("./generated/generated/reports/packets.json", "r") as file:
packets = json.load(file)
pool = packets["play"]["clientbound"]
with open("./packets.py", "w") as file:
file.write("\"\"\"Generated by generate.py\"\"\"")
file.write("from dataclasses import dataclass\n")
file.write("\n")
file.write("@dataclass(frozen=True)\n")
file.write("class Clientbound:\n")
for packet in pool:
protocol_id = hex(pool[packet]["protocol_id"])
packet = packet.split(":")[1]
file.write(f" {packet}: int = {protocol_id}\n")
file.write("\n")
file.write(" @classmethod\n")
file.write(" def for_id(cls, p_id: int) -> str:\n")
file.write(" for attr, value in cls.__dict__.items():\n")
file.write(" if not attr.startswith('__'): # Ignore special attributes like __module__\n")
file.write(" if value == p_id:\n")
file.write(" return attr\n")
file.write(" return \"\"\n\n")
file.flush()
file.close()
if __name__ == "__main__":
import subprocess
import argparse
parser = argparse.ArgumentParser(description="Generate the packets.py file from generated server reports")
parser.add_argument("-r", "--reports", help="Generate the reports from the server jar", action='store_true')
# Parse arguments
args = parser.parse_args()
if args.reports:
rv = subprocess.call(("cd ./generated && " +
"java -DbundlerMainClass='net.minecraft.data.Main' -jar " +
"../server/server.jar --reports"
), shell=True)
generate()