-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added CSoundEffect packet * Added sound macro added a macro that turns sound namespaces to the sounds id * added CEntitySoundEffect * updated id to i32 * Added sound effects to pvp * Added sweeping and particles * Added I-Frames to living entity * Refactored combat split up the combat handling into multiple functions and a new combat module * use new packet macro * updated json files * fixed attacking * use builtin clamp
- Loading branch information
Showing
17 changed files
with
7,566 additions
and
75 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use std::{collections::HashMap, sync::LazyLock}; | ||
|
||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
pub struct Particle { | ||
name: String, | ||
id: i32, | ||
} | ||
|
||
static SOUNDS: LazyLock<HashMap<String, i32>> = LazyLock::new(|| { | ||
serde_json::from_str::<Vec<Particle>>(include_str!("../../assets/particles.json")) | ||
.expect("Could not parse particles.json registry.") | ||
.into_iter() | ||
.map(|val| (val.name, val.id)) | ||
.collect() | ||
}); | ||
|
||
pub(crate) fn particle_impl(item: TokenStream) -> TokenStream { | ||
let input_string = item.to_string(); | ||
let sound_name = input_string.trim_matches('"'); | ||
|
||
let id = SOUNDS.get(sound_name).expect("Invalid particle"); | ||
quote! { #id }.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use std::{collections::HashMap, sync::LazyLock}; | ||
|
||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
pub struct Sound { | ||
name: String, | ||
id: i32, | ||
} | ||
|
||
static SOUNDS: LazyLock<HashMap<String, i32>> = LazyLock::new(|| { | ||
serde_json::from_str::<Vec<Sound>>(include_str!("../../assets/sounds.json")) | ||
.expect("Could not parse sounds.json registry.") | ||
.into_iter() | ||
.map(|val| (val.name, val.id)) | ||
.collect() | ||
}); | ||
|
||
pub(crate) fn sound_impl(item: TokenStream) -> TokenStream { | ||
let input_string = item.to_string(); | ||
let sound_name = input_string.trim_matches('"'); | ||
|
||
let id = SOUNDS.get(sound_name).expect("Invalid sound"); | ||
quote! { #id }.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use pumpkin_macros::client_packet; | ||
use serde::Serialize; | ||
|
||
use crate::{SoundCategory, VarInt}; | ||
|
||
use super::ClientboundPlayPackets; | ||
|
||
#[derive(Serialize)] | ||
#[client_packet(ClientboundPlayPackets::EntitySoundEffect as i32)] | ||
pub struct CEntitySoundEffect { | ||
sound_id: VarInt, | ||
// TODO: add sound from name | ||
// sound_name: Option<&'a str>, | ||
// has_fixed_range: Option<bool>, | ||
// range: Option<f32>, | ||
sound_category: VarInt, | ||
entity_id: VarInt, | ||
volume: f32, | ||
pitch: f32, | ||
seed: f64, | ||
} | ||
|
||
impl CEntitySoundEffect { | ||
pub fn new( | ||
sound_id: VarInt, | ||
sound_category: SoundCategory, | ||
entity_id: VarInt, | ||
volume: f32, | ||
pitch: f32, | ||
seed: f64, | ||
) -> Self { | ||
Self { | ||
sound_id: VarInt(sound_id.0 + 1), | ||
sound_category: VarInt(sound_category as i32), | ||
entity_id, | ||
volume, | ||
pitch, | ||
seed, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use pumpkin_macros::client_packet; | ||
use serde::Serialize; | ||
|
||
use crate::{SoundCategory, VarInt}; | ||
|
||
use super::ClientboundPlayPackets; | ||
|
||
#[derive(Serialize)] | ||
#[client_packet(ClientboundPlayPackets::SoundEffect as i32)] | ||
pub struct CSoundEffect { | ||
sound_id: VarInt, | ||
// TODO: add sound from name | ||
// sound_name: Option<&'a str>, | ||
// has_fixed_range: Option<bool>, | ||
// range: Option<f32>, | ||
sound_category: VarInt, | ||
effect_position_x: i32, | ||
effect_position_y: i32, | ||
effect_position_z: i32, | ||
volume: f32, | ||
pitch: f32, | ||
seed: f64, | ||
} | ||
|
||
impl CSoundEffect { | ||
#[allow(clippy::too_many_arguments)] | ||
pub fn new( | ||
sound_id: VarInt, | ||
sound_category: SoundCategory, | ||
effect_position_x: f64, | ||
effect_position_y: f64, | ||
effect_position_z: f64, | ||
volume: f32, | ||
pitch: f32, | ||
seed: f64, | ||
) -> Self { | ||
Self { | ||
sound_id: VarInt(sound_id.0 + 1), | ||
sound_category: VarInt(sound_category as i32), | ||
effect_position_x: (effect_position_x * 8.0) as i32, | ||
effect_position_y: (effect_position_y * 8.0) as i32, | ||
effect_position_z: (effect_position_z * 8.0) as i32, | ||
volume, | ||
pitch, | ||
seed, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.