parse scoreboard display slot at compile time
This commit is contained in:
parent
621bc31f48
commit
03cb80b216
1
assets/scoreboard_display_slot.json
Normal file
1
assets/scoreboard_display_slot.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
["LIST","SIDEBAR","BELOW_NAME","TEAM_BLACK","TEAM_DARK_BLUE","TEAM_DARK_GREEN","TEAM_DARK_AQUA","TEAM_DARK_RED","TEAM_DARK_PURPLE","TEAM_GOLD","TEAM_GRAY","TEAM_DARK_GRAY","TEAM_BLUE","TEAM_GREEN","TEAM_AQUA","TEAM_RED","TEAM_LIGHT_PURPLE","TEAM_YELLOW","TEAM_WHITE"]
|
||||||
@ -10,6 +10,7 @@ mod entity_pose;
|
|||||||
mod game_event;
|
mod game_event;
|
||||||
mod packet;
|
mod packet;
|
||||||
mod particle;
|
mod particle;
|
||||||
|
mod scoreboard_slot;
|
||||||
mod screen;
|
mod screen;
|
||||||
mod sound;
|
mod sound;
|
||||||
mod sound_category;
|
mod sound_category;
|
||||||
@ -23,6 +24,7 @@ pub fn main() {
|
|||||||
write_generated_file(game_event::build(), "game_event.rs");
|
write_generated_file(game_event::build(), "game_event.rs");
|
||||||
write_generated_file(sound_category::build(), "sound_category.rs");
|
write_generated_file(sound_category::build(), "sound_category.rs");
|
||||||
write_generated_file(entity_pose::build(), "entity_pose.rs");
|
write_generated_file(entity_pose::build(), "entity_pose.rs");
|
||||||
|
write_generated_file(scoreboard_slot::build(), "scoreboard_slot.rs");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn array_to_tokenstream(array: Vec<String>) -> TokenStream {
|
pub fn array_to_tokenstream(array: Vec<String>) -> TokenStream {
|
||||||
|
|||||||
20
pumpkin-data/build/scoreboard_slot.rs
Normal file
20
pumpkin-data/build/scoreboard_slot.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
use proc_macro2::TokenStream;
|
||||||
|
use quote::quote;
|
||||||
|
|
||||||
|
use crate::array_to_tokenstream;
|
||||||
|
|
||||||
|
pub(crate) fn build() -> TokenStream {
|
||||||
|
println!("cargo:rerun-if-changed=assets/scoreboard_display_slot.json");
|
||||||
|
|
||||||
|
let sound_categories: Vec<String> =
|
||||||
|
serde_json::from_str(include_str!("../../assets/scoreboard_display_slot.json"))
|
||||||
|
.expect("Failed to parse scoreboard_display_slot.json");
|
||||||
|
let variants = array_to_tokenstream(sound_categories);
|
||||||
|
|
||||||
|
quote! {
|
||||||
|
#[repr(u8)]
|
||||||
|
pub enum ScoreboardDisplaySlot {
|
||||||
|
#variants
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -12,6 +12,7 @@ pub mod particle {
|
|||||||
|
|
||||||
pub mod sound {
|
pub mod sound {
|
||||||
include!(concat!(env!("OUT_DIR"), "/sound.rs"));
|
include!(concat!(env!("OUT_DIR"), "/sound.rs"));
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/sound_category.rs"));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod chunk_status {
|
pub mod chunk_status {
|
||||||
@ -22,10 +23,10 @@ pub mod game_event {
|
|||||||
include!(concat!(env!("OUT_DIR"), "/game_event.rs"));
|
include!(concat!(env!("OUT_DIR"), "/game_event.rs"));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod sound_category {
|
pub mod entity {
|
||||||
include!(concat!(env!("OUT_DIR"), "/sound_category.rs"));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod entity_pose {
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/entity_pose.rs"));
|
include!(concat!(env!("OUT_DIR"), "/entity_pose.rs"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod scoreboard {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/scoreboard_slot.rs"));
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
use pumpkin_data::packet::clientbound::PLAY_SET_DISPLAY_OBJECTIVE;
|
use pumpkin_data::{
|
||||||
|
packet::clientbound::PLAY_SET_DISPLAY_OBJECTIVE, scoreboard::ScoreboardDisplaySlot,
|
||||||
|
};
|
||||||
use pumpkin_macros::client_packet;
|
use pumpkin_macros::client_packet;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
@ -12,33 +14,10 @@ pub struct CDisplayObjective<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CDisplayObjective<'a> {
|
impl<'a> CDisplayObjective<'a> {
|
||||||
pub fn new(position: DisplaySlot, score_name: &'a str) -> Self {
|
pub fn new(position: ScoreboardDisplaySlot, score_name: &'a str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
position: VarInt(position as i32),
|
position: VarInt(position as i32),
|
||||||
score_name,
|
score_name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(i32)]
|
|
||||||
pub enum DisplaySlot {
|
|
||||||
List,
|
|
||||||
Sidebar,
|
|
||||||
BelowName,
|
|
||||||
TeamBlack,
|
|
||||||
TeamDarkBlue,
|
|
||||||
TeamDarkGreen,
|
|
||||||
TeanDarkAqua,
|
|
||||||
TeamDarkRed,
|
|
||||||
TeamDarkPurple,
|
|
||||||
TeamGold,
|
|
||||||
TeamGray,
|
|
||||||
TeamDarkGray,
|
|
||||||
TeamBlue,
|
|
||||||
TeamGreen,
|
|
||||||
TeamAqua,
|
|
||||||
TeamRed,
|
|
||||||
TeamLightPurple,
|
|
||||||
TeamYellow,
|
|
||||||
TeamWhite,
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use bytes::BufMut;
|
use bytes::BufMut;
|
||||||
use pumpkin_data::{packet::clientbound::PLAY_SOUND_ENTITY, sound_category::SoundCategory};
|
use pumpkin_data::{packet::clientbound::PLAY_SOUND_ENTITY, sound::SoundCategory};
|
||||||
use pumpkin_macros::client_packet;
|
use pumpkin_macros::client_packet;
|
||||||
|
|
||||||
use crate::{bytebuf::ByteBufMut, ClientPacket, IDOrSoundEvent, SoundEvent, VarInt};
|
use crate::{bytebuf::ByteBufMut, ClientPacket, IDOrSoundEvent, SoundEvent, VarInt};
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use bytes::BufMut;
|
use bytes::BufMut;
|
||||||
use pumpkin_data::{packet::clientbound::PLAY_SOUND, sound_category::SoundCategory};
|
use pumpkin_data::{packet::clientbound::PLAY_SOUND, sound::SoundCategory};
|
||||||
use pumpkin_macros::client_packet;
|
use pumpkin_macros::client_packet;
|
||||||
|
|
||||||
use crate::{bytebuf::ByteBufMut, ClientPacket, IDOrSoundEvent, SoundEvent, VarInt};
|
use crate::{bytebuf::ByteBufMut, ClientPacket, IDOrSoundEvent, SoundEvent, VarInt};
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use core::f32;
|
|||||||
use std::sync::{atomic::AtomicBool, Arc};
|
use std::sync::{atomic::AtomicBool, Arc};
|
||||||
|
|
||||||
use crossbeam::atomic::AtomicCell;
|
use crossbeam::atomic::AtomicCell;
|
||||||
use pumpkin_data::entity_pose::EntityPose;
|
use pumpkin_data::entity::EntityPose;
|
||||||
use pumpkin_entity::{entity_type::EntityType, EntityId};
|
use pumpkin_entity::{entity_type::EntityType, EntityId};
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
client::play::{CHeadRot, CSetEntityMetadata, CTeleportEntity, CUpdateEntityRot, Metadata},
|
client::play::{CHeadRot, CSetEntityMetadata, CTeleportEntity, CUpdateEntityRot, Metadata},
|
||||||
|
|||||||
@ -9,7 +9,7 @@ use std::{
|
|||||||
|
|
||||||
use crossbeam::atomic::AtomicCell;
|
use crossbeam::atomic::AtomicCell;
|
||||||
use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG};
|
use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG};
|
||||||
use pumpkin_data::{sound::Sound, sound_category::SoundCategory};
|
use pumpkin_data::sound::{Sound, SoundCategory};
|
||||||
use pumpkin_entity::{entity_type::EntityType, EntityId};
|
use pumpkin_entity::{entity_type::EntityType, EntityId};
|
||||||
use pumpkin_inventory::player::PlayerInventory;
|
use pumpkin_inventory::player::PlayerInventory;
|
||||||
use pumpkin_protocol::server::play::{
|
use pumpkin_protocol::server::play::{
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
use pumpkin_data::{particle::Particle, sound::Sound, sound_category::SoundCategory};
|
use pumpkin_data::{
|
||||||
|
particle::Particle,
|
||||||
|
sound::{Sound, SoundCategory},
|
||||||
|
};
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
client::play::{CEntityVelocity, CParticle},
|
client::play::{CEntityVelocity, CParticle},
|
||||||
codec::var_int::VarInt,
|
codec::var_int::VarInt,
|
||||||
|
|||||||
@ -11,7 +11,10 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use level_time::LevelTime;
|
use level_time::LevelTime;
|
||||||
use pumpkin_config::BasicConfiguration;
|
use pumpkin_config::BasicConfiguration;
|
||||||
use pumpkin_data::{entity_pose::EntityPose, sound::Sound, sound_category::SoundCategory};
|
use pumpkin_data::{
|
||||||
|
entity::EntityPose,
|
||||||
|
sound::{Sound, SoundCategory},
|
||||||
|
};
|
||||||
use pumpkin_entity::{entity_type::EntityType, EntityId};
|
use pumpkin_entity::{entity_type::EntityType, EntityId};
|
||||||
use pumpkin_protocol::client::play::{CBlockUpdate, CRespawn, CSoundEffect, CWorldEvent};
|
use pumpkin_protocol::client::play::{CBlockUpdate, CRespawn, CSoundEffect, CWorldEvent};
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use pumpkin_data::scoreboard::ScoreboardDisplaySlot;
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
client::play::{CDisplayObjective, CUpdateObjectives, CUpdateScore, RenderType},
|
client::play::{CDisplayObjective, CUpdateObjectives, CUpdateScore, RenderType},
|
||||||
codec::var_int::VarInt,
|
codec::var_int::VarInt,
|
||||||
@ -43,7 +44,7 @@ impl Scoreboard {
|
|||||||
.await;
|
.await;
|
||||||
world
|
world
|
||||||
.broadcast_packet_all(&CDisplayObjective::new(
|
.broadcast_packet_all(&CDisplayObjective::new(
|
||||||
pumpkin_protocol::client::play::DisplaySlot::Sidebar,
|
ScoreboardDisplaySlot::Sidebar,
|
||||||
objective.name,
|
objective.name,
|
||||||
))
|
))
|
||||||
.await;
|
.await;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user