parse entity pose at compile time

This commit is contained in:
Alexander Medvedev
2025-01-11 16:20:31 +01:00
parent c95b27eafb
commit 621bc31f48
8 changed files with 32 additions and 26 deletions

1
assets/entity_pose.json Normal file
View File

@@ -0,0 +1 @@
["STANDING","FALL_FLYING","SLEEPING","SWIMMING","SPIN_ATTACK","CROUCHING","LONG_JUMPING","DYING","CROAKING","USING_TONGUE","SITTING","ROARING","SNIFFING","EMERGING","DIGGING","SLIDING","SHOOTING","INHALING"]

View File

@@ -6,6 +6,7 @@ use proc_macro2::{Span, TokenStream};
use syn::Ident;
mod chunk_status;
mod entity_pose;
mod game_event;
mod packet;
mod particle;
@@ -21,6 +22,7 @@ pub fn main() {
write_generated_file(chunk_status::build(), "chunk_status.rs");
write_generated_file(game_event::build(), "game_event.rs");
write_generated_file(sound_category::build(), "sound_category.rs");
write_generated_file(entity_pose::build(), "entity_pose.rs");
}
pub fn array_to_tokenstream(array: Vec<String>) -> TokenStream {

View File

@@ -0,0 +1,21 @@
use proc_macro2::TokenStream;
use quote::quote;
use crate::array_to_tokenstream;
pub(crate) fn build() -> TokenStream {
println!("cargo:rerun-if-changed=assets/entity_pose.json");
let sound_categories: Vec<String> =
serde_json::from_str(include_str!("../../assets/entity_pose.json"))
.expect("Failed to parse entity_pose.json");
let variants = array_to_tokenstream(sound_categories);
quote! {
#[derive(Clone, Copy)]
#[repr(u8)]
pub enum EntityPose {
#variants
}
}
}

View File

@@ -25,3 +25,7 @@ pub mod game_event {
pub mod sound_category {
include!(concat!(env!("OUT_DIR"), "/sound_category.rs"));
}
pub mod entity_pose {
include!(concat!(env!("OUT_DIR"), "/entity_pose.rs"));
}

View File

@@ -1,4 +1,3 @@
pub mod entity_type;
pub mod pose;
pub type EntityId = i32;

View File

@@ -1,22 +0,0 @@
#[derive(Clone, Copy)]
#[repr(i32)]
pub enum EntityPose {
Standing = 0,
FallFlying,
Sleeping,
Swimming,
SpinAttack,
Crouching,
LongJumping,
Dying,
Croaking,
UsingTongue,
Sitting,
Roaring,
Sniffing,
Emerging,
Digging,
Sliding,
Shooting,
Inhaling,
}

View File

@@ -2,7 +2,8 @@ use core::f32;
use std::sync::{atomic::AtomicBool, Arc};
use crossbeam::atomic::AtomicCell;
use pumpkin_entity::{entity_type::EntityType, pose::EntityPose, EntityId};
use pumpkin_data::entity_pose::EntityPose;
use pumpkin_entity::{entity_type::EntityType, EntityId};
use pumpkin_protocol::{
client::play::{CHeadRot, CSetEntityMetadata, CTeleportEntity, CUpdateEntityRot, Metadata},
codec::var_int::VarInt,

View File

@@ -11,8 +11,8 @@ use crate::{
};
use level_time::LevelTime;
use pumpkin_config::BasicConfiguration;
use pumpkin_data::{sound::Sound, sound_category::SoundCategory};
use pumpkin_entity::{entity_type::EntityType, pose::EntityPose, EntityId};
use pumpkin_data::{entity_pose::EntityPose, sound::Sound, sound_category::SoundCategory};
use pumpkin_entity::{entity_type::EntityType, EntityId};
use pumpkin_protocol::client::play::{CBlockUpdate, CRespawn, CSoundEffect, CWorldEvent};
use pumpkin_protocol::{
client::play::CLevelEvent,