Skip to content

Commit

Permalink
parse Sounds into enum at compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Jan 10, 2025
1 parent c711d15 commit 45a591b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 41 deletions.
4 changes: 4 additions & 0 deletions pumpkin-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ pub mod screen {
pub mod particle {
include!(concat!(env!("OUT_DIR"), "/particle.rs"));
}

pub mod sound {
include!(concat!(env!("OUT_DIR"), "/sound.rs"));
}
6 changes: 0 additions & 6 deletions pumpkin-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ pub fn pumpkin_block(input: TokenStream, item: TokenStream) -> TokenStream {
gen.into()
}

mod sound;
#[proc_macro]
pub fn sound(item: TokenStream) -> TokenStream {
sound::sound_impl(item)
}

mod block_state;
#[proc_macro]
pub fn block_state(item: TokenStream) -> TokenStream {
Expand Down
21 changes: 0 additions & 21 deletions pumpkin-macros/src/sound.rs

This file was deleted.

8 changes: 4 additions & 4 deletions pumpkin/src/block/blocks/chest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use async_trait::async_trait;
use pumpkin_data::screen::WindowType;
use pumpkin_data::{screen::WindowType, sound::Sound};
use pumpkin_inventory::{Chest, OpenContainer};
use pumpkin_macros::{pumpkin_block, sound};
use pumpkin_macros::pumpkin_block;
use pumpkin_protocol::{client::play::CBlockAction, codec::var_int::VarInt};
use pumpkin_util::math::position::WorldPosition;
use pumpkin_world::{
Expand Down Expand Up @@ -114,12 +114,12 @@ impl ChestBlock {
if state == ChestState::IsClosed && num_players == 0 {
player
.world()
.play_block_sound(sound!("block.chest.close"), location)
.play_block_sound(Sound::BlockChestClose as u16, location)
.await;
} else if state == ChestState::IsOpened && num_players == 1 {
player
.world()
.play_block_sound(sound!("block.chest.open"), location)
.play_block_sound(Sound::BlockChestOpen as u16, location)
.await;
}

Expand Down
6 changes: 3 additions & 3 deletions pumpkin/src/entity/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use std::{

use crossbeam::atomic::AtomicCell;
use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG};
use pumpkin_data::sound::Sound;
use pumpkin_entity::{entity_type::EntityType, EntityId};
use pumpkin_inventory::player::PlayerInventory;
use pumpkin_macros::sound;
use pumpkin_protocol::server::play::{
SCloseContainer, SCookieResponse as SPCookieResponse, SPlayPingRequest, SPlayerLoaded,
};
Expand Down Expand Up @@ -317,7 +317,7 @@ impl Player {
{
world
.play_sound(
sound!("entity.player.attack.nodamage"),
Sound::EntityPlayerAttackNodamage as u16,
SoundCategory::Players,
&pos,
)
Expand All @@ -326,7 +326,7 @@ impl Player {
}

world
.play_sound(sound!("entity.player.hurt"), SoundCategory::Players, &pos)
.play_sound(Sound::EntityPlayerHurt as u16, SoundCategory::Players, &pos)
.await;

let attack_type = AttackType::new(self, attack_cooldown_progress as f32).await;
Expand Down
13 changes: 6 additions & 7 deletions pumpkin/src/net/combat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::f32::consts::PI;

use pumpkin_data::particle::Particle;
use pumpkin_macros::sound;
use pumpkin_data::{particle::Particle, sound::Sound};
use pumpkin_protocol::{
client::play::{CEntityVelocity, CParticle},
codec::var_int::VarInt,
Expand Down Expand Up @@ -122,7 +121,7 @@ pub async fn player_attack_sound(pos: &Vector3<f64>, world: &World, attack_type:
AttackType::Knockback => {
world
.play_sound(
sound!("entity.player.attack.knockback"),
Sound::EntityPlayerAttackKnockback as u16,
SoundCategory::Players,
pos,
)
Expand All @@ -131,7 +130,7 @@ pub async fn player_attack_sound(pos: &Vector3<f64>, world: &World, attack_type:
AttackType::Critical => {
world
.play_sound(
sound!("entity.player.attack.crit"),
Sound::EntityPlayerAttackCrit as u16,
SoundCategory::Players,
pos,
)
Expand All @@ -140,7 +139,7 @@ pub async fn player_attack_sound(pos: &Vector3<f64>, world: &World, attack_type:
AttackType::Sweeping => {
world
.play_sound(
sound!("entity.player.attack.sweep"),
Sound::EntityPlayerAttackSweep as u16,
SoundCategory::Players,
pos,
)
Expand All @@ -149,7 +148,7 @@ pub async fn player_attack_sound(pos: &Vector3<f64>, world: &World, attack_type:
AttackType::Strong => {
world
.play_sound(
sound!("entity.player.attack.strong"),
Sound::EntityPlayerAttackStrong as u16,
SoundCategory::Players,
pos,
)
Expand All @@ -158,7 +157,7 @@ pub async fn player_attack_sound(pos: &Vector3<f64>, world: &World, attack_type:
AttackType::Weak => {
world
.play_sound(
sound!("entity.player.attack.weak"),
Sound::EntityPlayerAttackWeak as u16,
SoundCategory::Players,
pos,
)
Expand Down

0 comments on commit 45a591b

Please sign in to comment.