Skip to content

Commit 80cf746

Browse files
committed
inventory
1 parent 1e70dc6 commit 80cf746

8 files changed

Lines changed: 4623 additions & 6 deletions

File tree

build.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::path::Path;
66
fn main() {
77
load_packets();
88
load_blocks();
9+
load_items();
910
}
1011

1112
fn load_packets() {
@@ -64,8 +65,6 @@ fn load_packets() {
6465
out.push_str("}\n");
6566
}
6667

67-
dbg!(tree);
68-
6968
let out_path = Path::new(&env::var("OUT_DIR").unwrap()).join("packets.rs");
7069
fs::write(out_path, out).unwrap();
7170
}
@@ -101,4 +100,30 @@ fn load_blocks() {
101100

102101
let out_path = Path::new(&env::var("OUT_DIR").unwrap()).join("blocks.rs");
103102
fs::write(out_path, out).unwrap();
103+
}
104+
105+
fn load_items() {
106+
let manifest = env::var("CARGO_MANIFEST_DIR").unwrap();
107+
let json_path = Path::new(&manifest).join("src/assets/items.json");
108+
println!("cargo:rerun-if-changed={}", json_path.display());
109+
110+
let bytes = fs::read(&json_path).expect("Failed to read items.json");
111+
112+
let json: HashMap<String, serde_json::Value> =
113+
serde_json::from_slice(&bytes).expect("Failed to parse items.json");
114+
115+
let mut out = String::new();
116+
117+
for (key, item) in json["entries"].as_object().unwrap() {
118+
out.push_str(
119+
&format!(
120+
"pub const {}: i32 = {};\n",
121+
key.to_uppercase().replace("MINECRAFT:", "").replace("/", "_"),
122+
item["protocol_id"].as_u64().unwrap()
123+
)
124+
);
125+
}
126+
127+
let out_path = Path::new(&env::var("OUT_DIR").unwrap()).join("items.rs");
128+
fs::write(out_path, out).unwrap();
104129
}

0 commit comments

Comments
 (0)