Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions bb_server/src/particle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Comment on lines +34 to +51
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the fields are public, no need for a constructor. Forcing users to use struct literals is also clearer, as you can see the field names.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the constructor is still here. forgot to push maybe?

pub fn to_packet(
&self,
blocks: &block::TypeConverter,
Expand Down
2 changes: 2 additions & 0 deletions bb_server/src/plugin/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -429,6 +430,7 @@ impl PandaPlugin {
sl.add_builtin_ty::<item::PInventory>();
sl.add_builtin_ty::<item::PStack>();
sl.add_builtin_ty::<item::PUI>();
sl.add_builtin_ty::<particle::PParticle>();
sl.add_builtin_ty::<command::PCommand>();
sl.add_builtin_ty::<player::PPlayer>();
sl.add_builtin_ty::<player::PTeam>();
Expand Down
36 changes: 36 additions & 0 deletions bb_server/src/plugin/types/particle.rs
Original file line number Diff line number Diff line change
@@ -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<Self, RuntimeError> {
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,
},
})
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo fmt is the way. make sure you're on the nightly toolchain, and it should just fix all this.

5 changes: 5 additions & 0 deletions bb_server/src/plugin/types/world/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{
block::{PBlockKind, PBlockType},
item::PStack,
particle::PParticle,
util::{PFPos, PPos},
};
use crate::{entity, world::World};
Expand Down Expand Up @@ -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(
Expand Down
24 changes: 24 additions & 0 deletions examples/debug/plugins/particle/main.pand
Original file line number Diff line number Diff line change
@@ -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,
)
Comment on lines +14 to +21
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike having a function take 6 arguments. I think using a builder like this would be clearer:

particle::Particle::builder("witch", player.pos())
  .long_distance(true)
  .velocity(0.0, 0.0, 0.0)
  .amount(100)
  .data(0.0)
  .build()

plus, the builder can have some defaults, so you don't need to set everything:

particle::Particle::builder("witch", player.pos())
  .long_distance(true)
  .amount(100)
  .build()


world.spawn_particle(particle)
}
2 changes: 2 additions & 0 deletions examples/debug/plugins/particle/plugin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type = "panda"
enabled = true