parse ChunkStatus at compile time
This commit is contained in:
parent
7b205fe108
commit
da268b548b
1
assets/chunk_status.json
Normal file
1
assets/chunk_status.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
["empty","structure_starts","structure_references","biomes","noise","surface","carvers","features","initialize_light","light","spawn","full"]
|
||||||
@ -4,6 +4,9 @@ version.workspace = true
|
|||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
build = "build/build.rs"
|
build = "build/build.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde.workspace = true
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
|||||||
@ -3,6 +3,7 @@ use std::{env, fs, path::Path, process::Command};
|
|||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
use syn::Ident;
|
use syn::Ident;
|
||||||
|
|
||||||
|
mod chunk_status;
|
||||||
mod packet;
|
mod packet;
|
||||||
mod particle;
|
mod particle;
|
||||||
mod screen;
|
mod screen;
|
||||||
@ -13,6 +14,7 @@ pub fn main() {
|
|||||||
write_generated_file(screen::build(), "screen.rs");
|
write_generated_file(screen::build(), "screen.rs");
|
||||||
write_generated_file(particle::build(), "particle.rs");
|
write_generated_file(particle::build(), "particle.rs");
|
||||||
write_generated_file(sound::build(), "sound.rs");
|
write_generated_file(sound::build(), "sound.rs");
|
||||||
|
write_generated_file(chunk_status::build(), "chunk_status.rs");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_generated_file(content: TokenStream, out_file: &str) {
|
pub fn write_generated_file(content: TokenStream, out_file: &str) {
|
||||||
|
|||||||
31
pumpkin-data/build/chunk_status.rs
Normal file
31
pumpkin-data/build/chunk_status.rs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
use heck::ToPascalCase;
|
||||||
|
use proc_macro2::TokenStream;
|
||||||
|
use quote::quote;
|
||||||
|
|
||||||
|
use crate::ident;
|
||||||
|
|
||||||
|
pub(crate) fn build() -> TokenStream {
|
||||||
|
println!("cargo:rerun-if-changed=assets/chunk_status.json");
|
||||||
|
|
||||||
|
let chunk_status: Vec<String> =
|
||||||
|
serde_json::from_str(include_str!("../../assets/chunk_status.json"))
|
||||||
|
.expect("Failed to parse chunk_status.json");
|
||||||
|
let mut variants = TokenStream::new();
|
||||||
|
|
||||||
|
for status in chunk_status.iter() {
|
||||||
|
let full_name = format!("minecraft:{status}");
|
||||||
|
let name = ident(status.to_pascal_case());
|
||||||
|
variants.extend([quote! {
|
||||||
|
#[serde(rename = #full_name)]
|
||||||
|
#name,
|
||||||
|
}]);
|
||||||
|
}
|
||||||
|
quote! {
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
|
||||||
|
pub enum ChunkStatus {
|
||||||
|
#variants
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,13 +7,13 @@ use crate::ident;
|
|||||||
pub(crate) fn build() -> TokenStream {
|
pub(crate) fn build() -> TokenStream {
|
||||||
println!("cargo:rerun-if-changed=assets/particles.json");
|
println!("cargo:rerun-if-changed=assets/particles.json");
|
||||||
|
|
||||||
let screens: Vec<String> = serde_json::from_str(include_str!("../../assets/particles.json"))
|
let particle: Vec<String> = serde_json::from_str(include_str!("../../assets/particles.json"))
|
||||||
.expect("Failed to parse particles.json");
|
.expect("Failed to parse particles.json");
|
||||||
let mut variants = TokenStream::new();
|
let mut variants = TokenStream::new();
|
||||||
|
|
||||||
for (id, screen) in screens.iter().enumerate() {
|
for (id, particle) in particle.iter().enumerate() {
|
||||||
let id = id as u8;
|
let id = id as u8;
|
||||||
let name = ident(screen.to_pascal_case());
|
let name = ident(particle.to_pascal_case());
|
||||||
|
|
||||||
variants.extend([quote! {
|
variants.extend([quote! {
|
||||||
#name = #id,
|
#name = #id,
|
||||||
|
|||||||
@ -7,13 +7,13 @@ use crate::ident;
|
|||||||
pub(crate) fn build() -> TokenStream {
|
pub(crate) fn build() -> TokenStream {
|
||||||
println!("cargo:rerun-if-changed=assets/sounds.json");
|
println!("cargo:rerun-if-changed=assets/sounds.json");
|
||||||
|
|
||||||
let screens: Vec<String> = serde_json::from_str(include_str!("../../assets/sounds.json"))
|
let sound: Vec<String> = serde_json::from_str(include_str!("../../assets/sounds.json"))
|
||||||
.expect("Failed to parse sounds.json");
|
.expect("Failed to parse sounds.json");
|
||||||
let mut variants = TokenStream::new();
|
let mut variants = TokenStream::new();
|
||||||
|
|
||||||
for (id, screen) in screens.iter().enumerate() {
|
for (id, sound) in sound.iter().enumerate() {
|
||||||
let id = id as u16;
|
let id = id as u16;
|
||||||
let name = ident(screen.to_pascal_case());
|
let name = ident(sound.to_pascal_case());
|
||||||
|
|
||||||
variants.extend([quote! {
|
variants.extend([quote! {
|
||||||
#name = #id,
|
#name = #id,
|
||||||
|
|||||||
@ -13,3 +13,7 @@ pub mod particle {
|
|||||||
pub mod sound {
|
pub mod sound {
|
||||||
include!(concat!(env!("OUT_DIR"), "/sound.rs"));
|
include!(concat!(env!("OUT_DIR"), "/sound.rs"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod chunk_status {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/chunk_status.rs"));
|
||||||
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ pumpkin-nbt = { path = "../pumpkin-nbt" }
|
|||||||
pumpkin-util = { path = "../pumpkin-util" }
|
pumpkin-util = { path = "../pumpkin-util" }
|
||||||
pumpkin-config = { path = "../pumpkin-config" }
|
pumpkin-config = { path = "../pumpkin-config" }
|
||||||
pumpkin-macros = { path = "../pumpkin-macros" }
|
pumpkin-macros = { path = "../pumpkin-macros" }
|
||||||
|
pumpkin-data = { path = "../pumpkin-data" }
|
||||||
|
|
||||||
bytes.workspace = true
|
bytes.workspace = true
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
use fastnbt::LongArray;
|
use fastnbt::LongArray;
|
||||||
|
use pumpkin_data::chunk_status::ChunkStatus;
|
||||||
use pumpkin_util::math::{ceil_log2, vector2::Vector2};
|
use pumpkin_util::math::{ceil_log2, vector2::Vector2};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, iter::repeat_with};
|
use std::{collections::HashMap, iter::repeat_with};
|
||||||
@ -161,34 +162,6 @@ struct ChunkNbt {
|
|||||||
heightmaps: ChunkHeightmaps,
|
heightmaps: ChunkHeightmaps,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
|
|
||||||
enum ChunkStatus {
|
|
||||||
#[serde(rename = "minecraft:empty")]
|
|
||||||
Empty,
|
|
||||||
#[serde(rename = "minecraft:structure_starts")]
|
|
||||||
StructureStarts,
|
|
||||||
#[serde(rename = "minecraft:structure_references")]
|
|
||||||
StructureReferences,
|
|
||||||
#[serde(rename = "minecraft:biomes")]
|
|
||||||
Biomes,
|
|
||||||
#[serde(rename = "minecraft:noise")]
|
|
||||||
Noise,
|
|
||||||
#[serde(rename = "minecraft:surface")]
|
|
||||||
Surface,
|
|
||||||
#[serde(rename = "minecraft:carvers")]
|
|
||||||
Carvers,
|
|
||||||
#[serde(rename = "minecraft:features")]
|
|
||||||
Features,
|
|
||||||
#[serde(rename = "minecraft:initialize_light")]
|
|
||||||
InitLight,
|
|
||||||
#[serde(rename = "minecraft:light")]
|
|
||||||
Light,
|
|
||||||
#[serde(rename = "minecraft:spawn")]
|
|
||||||
Spawn,
|
|
||||||
#[serde(rename = "minecraft:full")]
|
|
||||||
Full,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The Heightmap for a completely empty chunk
|
/// The Heightmap for a completely empty chunk
|
||||||
impl Default for ChunkHeightmaps {
|
impl Default for ChunkHeightmaps {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user