diff --git a/bb_server/src/particle/mod.rs b/bb_server/src/particle/mod.rs index fab3b58d..d6c0797e 100644 --- a/bb_server/src/particle/mod.rs +++ b/bb_server/src/particle/mod.rs @@ -31,6 +31,24 @@ pub struct Particle { } impl Particle { + pub fn new( + ty: Type, + pos: FPos, + long_distance: bool, + offset: FPos, + count: u32, + data: f32, + ) -> Self { + Self { + ty, + pos, + long_distance, + offset, + count, + data, + } + } + pub fn to_packet( &self, blocks: &block::TypeConverter, diff --git a/bb_server/src/plugin/types/mod.rs b/bb_server/src/plugin/types/mod.rs index 2b9d623f..65a505a1 100644 --- a/bb_server/src/plugin/types/mod.rs +++ b/bb_server/src/plugin/types/mod.rs @@ -25,6 +25,7 @@ pub mod chat; pub mod command; pub mod event; pub mod item; +pub mod particle; pub mod player; pub mod util; pub mod world; @@ -429,6 +430,7 @@ impl PandaPlugin { sl.add_builtin_ty::(); sl.add_builtin_ty::(); sl.add_builtin_ty::(); + sl.add_builtin_ty::(); sl.add_builtin_ty::(); sl.add_builtin_ty::(); sl.add_builtin_ty::(); diff --git a/bb_server/src/plugin/types/particle.rs b/bb_server/src/plugin/types/particle.rs new file mode 100644 index 00000000..0590f1b7 --- /dev/null +++ b/bb_server/src/plugin/types/particle.rs @@ -0,0 +1,36 @@ +use panda::{ + parse::token::Span, + runtime::RuntimeError, +}; +use crate::{ + particle, + particle::Particle, +}; +use bb_server_macros::define_ty; +use crate::plugin::types::util::PFPos; +use std::str::FromStr; + +#[define_ty] +impl PParticle { + info! { + wrap: Particle, + + panda: { + path: "bamboo::particle::Particle", + }, + } + + pub fn new(name: &str, pos: &PFPos, force: bool, offset: &PFPos, count: u32, data: f32) -> Result { + Ok(PParticle { + inner: Particle { + ty: particle::Type::from_str(name) + .map_err(|e| RuntimeError::Custom(e.to_string(), Span::call_site()))?, + pos: pos.inner, + long_distance: force, + offset: offset.inner, + count, + data, + }, + }) + } +} \ No newline at end of file diff --git a/bb_server/src/plugin/types/world/mod.rs b/bb_server/src/plugin/types/world/mod.rs index 12d88275..25402091 100644 --- a/bb_server/src/plugin/types/world/mod.rs +++ b/bb_server/src/plugin/types/world/mod.rs @@ -1,6 +1,7 @@ use super::{ block::{PBlockKind, PBlockType}, item::PStack, + particle::PParticle, util::{PFPos, PPos}, }; use crate::{entity, world::World}; @@ -87,6 +88,10 @@ impl PWorld { self.inner.summon_meta(entity::Type::Item, pos.inner, meta); } + pub fn spawn_particle(&self, particle: &PParticle) { + self.inner.spawn_particle(particle.inner.clone()); + } + /// Plays the given sound at the given positions. All nearby players will be /// able to hear it. pub fn play_sound( diff --git a/examples/debug/plugins/particle/main.pand b/examples/debug/plugins/particle/main.pand new file mode 100644 index 00000000..24594a76 --- /dev/null +++ b/examples/debug/plugins/particle/main.pand @@ -0,0 +1,24 @@ +use bamboo::{ + particle, + util, +} + +on init() { + bamboo::info("owo") +} + +on interact(event, flow) { + let player = event.player + let world = @bamboo.default_world() + + let particle = particle::Particle::new( + "witch", + player.pos(), + true, + util::FPos::new(0.0, 0.0, 0.0), + 100, + 0.0, + ) + + world.spawn_particle(particle) +} diff --git a/examples/debug/plugins/particle/plugin.toml b/examples/debug/plugins/particle/plugin.toml new file mode 100644 index 00000000..48f05e74 --- /dev/null +++ b/examples/debug/plugins/particle/plugin.toml @@ -0,0 +1,2 @@ +type = "panda" +enabled = true