mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-25 23:31:30 +11:00
9c9f672a22
## 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.
39 lines
902 B
Rust
39 lines
902 B
Rust
use heck::ToPascalCase;
|
|
use proc_macro2::TokenStream;
|
|
use quote::quote;
|
|
use serde::Deserialize;
|
|
|
|
use crate::ident;
|
|
|
|
#[derive(Deserialize)]
|
|
struct Packet {
|
|
name: String,
|
|
side: String,
|
|
state: String,
|
|
id: i32,
|
|
}
|
|
|
|
pub fn build() -> anyhow::Result<TokenStream> {
|
|
let packets: Vec<Packet> =
|
|
serde_json::from_str(include_str!("../../../extracted/packets.json"))?;
|
|
|
|
let mut consts = TokenStream::new();
|
|
|
|
for packet in packets {
|
|
let stripped_name = packet.name.strip_suffix("Packet").unwrap_or(&packet.name);
|
|
|
|
let name_ident = ident(stripped_name.to_pascal_case());
|
|
let id = packet.id;
|
|
|
|
let doc = format!("Side: {}\nState: {}", packet.side, packet.state);
|
|
|
|
consts.extend([quote! {
|
|
#[doc = #doc]
|
|
#[allow(non_upper_case_globals)]
|
|
pub const #name_ident: i32 = #id;
|
|
}]);
|
|
}
|
|
|
|
Ok(consts)
|
|
}
|