From dd428eee19f4a6d0bd15d83de01049d8aa7320a8 Mon Sep 17 00:00:00 2001 From: snavy <1337snavy@gmail.com> Date: Mon, 8 May 2023 04:24:37 +0000 Subject: [PATCH 1/3] simple particle support in panda --- bb_server/src/particle/mod.rs | 18 +++++++++++++ bb_server/src/plugin/types/mod.rs | 2 ++ bb_server/src/plugin/types/particle.rs | 36 +++++++++++++++++++++++++ bb_server/src/plugin/types/world/mod.rs | 5 ++++ 4 files changed, 61 insertions(+) create mode 100644 bb_server/src/plugin/types/particle.rs 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..a73f69c1 --- /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::new( + particle::Type::from_str(name) + .map_err(|e| RuntimeError::Custom(e.to_string(), Span::call_site()))?, + pos.inner, + force, + 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( From e7dbf37eb4be617007bff483804d1b6d3f5d17d9 Mon Sep 17 00:00:00 2001 From: snavy <1337snavy@gmail.com> Date: Mon, 8 May 2023 04:29:39 +0000 Subject: [PATCH 2/3] particle example in panda --- examples/debug/plugins/particle/main.pand | 24 +++++++++++++++++++++ examples/debug/plugins/particle/plugin.toml | 2 ++ 2 files changed, 26 insertions(+) create mode 100644 examples/debug/plugins/particle/main.pand create mode 100644 examples/debug/plugins/particle/plugin.toml diff --git a/examples/debug/plugins/particle/main.pand b/examples/debug/plugins/particle/main.pand new file mode 100644 index 00000000..462854d6 --- /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) +} \ No newline at end of file diff --git a/examples/debug/plugins/particle/plugin.toml b/examples/debug/plugins/particle/plugin.toml new file mode 100644 index 00000000..74372601 --- /dev/null +++ b/examples/debug/plugins/particle/plugin.toml @@ -0,0 +1,2 @@ +type = "panda" +enabled = true \ No newline at end of file From dab41c601139b64c13f98c0cdbef5c6880585a0d Mon Sep 17 00:00:00 2001 From: snavy <1337snavy@gmail.com> Date: Wed, 10 May 2023 04:54:03 +0000 Subject: [PATCH 3/3] remove unnecessary particle constructor --- bb_server/src/plugin/types/particle.rs | 46 ++++++++++----------- examples/debug/plugins/particle/main.pand | 2 +- examples/debug/plugins/particle/plugin.toml | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/bb_server/src/plugin/types/particle.rs b/bb_server/src/plugin/types/particle.rs index a73f69c1..0590f1b7 100644 --- a/bb_server/src/plugin/types/particle.rs +++ b/bb_server/src/plugin/types/particle.rs @@ -1,10 +1,10 @@ use panda::{ - parse::token::Span, - runtime::RuntimeError, + parse::token::Span, + runtime::RuntimeError, }; use crate::{ - particle, - particle::Particle, + particle, + particle::Particle, }; use bb_server_macros::define_ty; use crate::plugin::types::util::PFPos; @@ -12,25 +12,25 @@ use std::str::FromStr; #[define_ty] impl PParticle { - info! { - wrap: Particle, + info! { + wrap: Particle, - panda: { - path: "bamboo::particle::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::new( - particle::Type::from_str(name) - .map_err(|e| RuntimeError::Custom(e.to_string(), Span::call_site()))?, - pos.inner, - force, - offset.inner, - count, - data, - ), - }) - } + 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/examples/debug/plugins/particle/main.pand b/examples/debug/plugins/particle/main.pand index 462854d6..24594a76 100644 --- a/examples/debug/plugins/particle/main.pand +++ b/examples/debug/plugins/particle/main.pand @@ -21,4 +21,4 @@ on interact(event, flow) { ) world.spawn_particle(particle) -} \ No newline at end of file +} diff --git a/examples/debug/plugins/particle/plugin.toml b/examples/debug/plugins/particle/plugin.toml index 74372601..48f05e74 100644 --- a/examples/debug/plugins/particle/plugin.toml +++ b/examples/debug/plugins/particle/plugin.toml @@ -1,2 +1,2 @@ type = "panda" -enabled = true \ No newline at end of file +enabled = true