mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
parse entity pose at compile time
This commit is contained in:
1
assets/entity_pose.json
Normal file
1
assets/entity_pose.json
Normal 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"]
|
||||
@@ -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 {
|
||||
|
||||
21
pumpkin-data/build/entity_pose.rs
Normal file
21
pumpkin-data/build/entity_pose.rs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
pub mod entity_type;
|
||||
pub mod pose;
|
||||
|
||||
pub type EntityId = i32;
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user