valence/crates/valence_protocol/build/main.rs
Ryan Johnson 9c9f672a22
Update to 1.19.4 (#302)
## Description

Closes #291

- Update extractors to support Minecraft 1.19.4
- Update code generators.
- Changed generated entity component names to avoid name collisions.
- Update `glam` version.
- Added `Encode` and `Decode` for `glam` types in `valence_protocol`.
- Fixed inconsistent packet names and assign packet IDs automatically.
- Remove `ident` and rename `ident_str` to `ident`.
- Rework registry codec configuration. Biomes and dimensions exist as
entities.`BiomeRegistry` and `DimensionTypeRegistry` resources have been
added. The vanilla registry codec is loaded at startup.

### Issues
- Creating new instances has become more tedious than it should be. This
will be addressed later.

## Test Plan

Steps:
1. Boot up a vanilla server with online mode disabled.
2. Run the `packet_inspector`.
3. Connect to the vanilla server through the packet inspector to ensure
all packets are updated correctly.
4. Close the vanilla server and try some valence examples.
2023-03-31 14:58:47 -07:00

51 lines
1.3 KiB
Rust

use std::path::Path;
use std::process::Command;
use std::{env, fs};
use anyhow::Context;
use proc_macro2::{Ident, Span};
mod block;
mod enchant;
mod item;
mod packet_id;
mod sound;
mod translation_key;
pub fn main() -> anyhow::Result<()> {
println!("cargo:rerun-if-changed=../../extracted/");
let generators = [
(block::build as fn() -> _, "block.rs"),
(enchant::build, "enchant.rs"),
(item::build, "item.rs"),
(sound::build, "sound.rs"),
(translation_key::build, "translation_key.rs"),
(packet_id::build, "packet_id.rs"),
];
let out_dir = env::var_os("OUT_DIR").context("failed to get OUT_DIR env var")?;
for (gen, file_name) in generators {
let path = Path::new(&out_dir).join(file_name);
let code = gen()?.to_string();
fs::write(&path, code)?;
// Format the output for debugging purposes.
// Doesn't matter if rustfmt is unavailable.
let _ = Command::new("rustfmt").arg(path).output();
}
Ok(())
}
fn ident(s: impl AsRef<str>) -> Ident {
let s = s.as_ref().trim();
match s.as_bytes() {
// TODO: check for the other rust keywords.
[b'0'..=b'9', ..] | b"type" => Ident::new(&format!("_{s}"), Span::call_site()),
_ => Ident::new(s, Span::call_site()),
}
}