-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
296 additions
and
51 deletions.
There are no files selected for viewing
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
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,68 @@ | ||
use async_trait::async_trait; | ||
use pumpkin_data::particle::Particle; | ||
use pumpkin_protocol::client::play::{ArgumentType, CommandSuggestion, SuggestionProviders}; | ||
|
||
use crate::command::{ | ||
args::{Arg, ArgumentConsumer, DefaultNameArgConsumer, FindArg, GetClientSideArgParser}, | ||
dispatcher::CommandError, | ||
tree::RawArgs, | ||
CommandSender, | ||
}; | ||
use crate::server::Server; | ||
|
||
pub struct ParticleArgumentConsumer; | ||
|
||
impl GetClientSideArgParser for ParticleArgumentConsumer { | ||
fn get_client_side_parser(&self) -> ArgumentType { | ||
ArgumentType::Resource { | ||
identifier: "particle_type", | ||
} | ||
} | ||
|
||
fn get_client_side_suggestion_type_override(&self) -> Option<SuggestionProviders> { | ||
None | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl ArgumentConsumer for ParticleArgumentConsumer { | ||
async fn consume<'a>( | ||
&'a self, | ||
_sender: &CommandSender<'a>, | ||
_server: &'a Server, | ||
args: &mut RawArgs<'a>, | ||
) -> Option<Arg<'a>> { | ||
let name = args.pop()?; | ||
|
||
// Create a static damage type first | ||
let particle = Particle::from_name(&name.replace("minecraft:", ""))?; | ||
// Find matching static damage type from values array | ||
Some(Arg::Particle(particle)) | ||
} | ||
|
||
async fn suggest<'a>( | ||
&'a self, | ||
_sender: &CommandSender<'a>, | ||
_server: &'a Server, | ||
_input: &'a str, | ||
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> { | ||
Ok(None) | ||
} | ||
} | ||
|
||
impl DefaultNameArgConsumer for ParticleArgumentConsumer { | ||
fn default_name(&self) -> &'static str { | ||
"particle_type" | ||
} | ||
} | ||
|
||
impl<'a> FindArg<'a> for ParticleArgumentConsumer { | ||
type Data = &'a Particle; | ||
|
||
fn find_arg(args: &'a super::ConsumedArgs, name: &str) -> Result<Self::Data, CommandError> { | ||
match args.get(name) { | ||
Some(Arg::Particle(data)) => Ok(data), | ||
_ => Err(CommandError::InvalidConsumption(Some(name.to_string()))), | ||
} | ||
} | ||
} |
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,92 @@ | ||
use async_trait::async_trait; | ||
use pumpkin_util::{math::vector3::Vector3, text::TextComponent}; | ||
|
||
use crate::command::{ | ||
args::{ | ||
bounded_num::BoundedNumArgumentConsumer, particle::ParticleArgumentConsumer, | ||
position_3d::Position3DArgumentConsumer, ConsumedArgs, FindArg, | ||
}, | ||
tree::{builder::argument, CommandTree}, | ||
CommandError, CommandExecutor, CommandSender, | ||
}; | ||
const NAMES: [&str; 1] = ["particle"]; | ||
|
||
const DESCRIPTION: &str = "Spawns a Particle at position."; | ||
|
||
const ARG_NAME: &str = "name"; | ||
|
||
const ARG_POS: &str = "pos"; | ||
const ARG_DELTA: &str = "delta"; | ||
const ARG_SPEED: &str = "speed"; | ||
const ARG_COUNT: &str = "count"; | ||
|
||
struct ParticleExecutor; | ||
|
||
#[async_trait] | ||
impl CommandExecutor for ParticleExecutor { | ||
async fn execute<'a>( | ||
&self, | ||
sender: &mut CommandSender<'a>, | ||
_server: &crate::server::Server, | ||
args: &ConsumedArgs<'a>, | ||
) -> Result<(), CommandError> { | ||
let particle = ParticleArgumentConsumer::find_arg(args, ARG_NAME)?; | ||
let pos = Position3DArgumentConsumer::find_arg(args, ARG_POS); | ||
let delta = Position3DArgumentConsumer::find_arg(args, ARG_DELTA); | ||
let speed = BoundedNumArgumentConsumer::<f32>::find_arg(args, ARG_SPEED); | ||
let count = BoundedNumArgumentConsumer::<i32>::find_arg(args, ARG_COUNT); | ||
|
||
// TODO: Make this work in console | ||
if let Some(player) = sender.as_player() { | ||
let pos = pos.unwrap_or(player.living_entity.entity.pos.load()); | ||
let delta = delta.unwrap_or(Vector3::new(0.0, 0.0, 0.0)); | ||
let delta: Vector3<f32> = Vector3::new(delta.x as f32, delta.y as f32, delta.z as f32); | ||
let speed = speed.unwrap_or(Ok(0.0)).unwrap_or(0.0); | ||
let count = count.unwrap_or(Ok(0)).unwrap_or(0); | ||
|
||
player | ||
.world() | ||
.await | ||
.spawn_particle(pos, delta, speed, count, *particle) | ||
.await; | ||
sender | ||
.send_message(TextComponent::translate( | ||
"commands.particle.success", | ||
[TextComponent::text(format!("{particle:?}"))].into(), | ||
)) | ||
.await; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
pub fn init_command_tree() -> CommandTree { | ||
CommandTree::new(NAMES, DESCRIPTION).then( | ||
argument(ARG_NAME, ParticleArgumentConsumer) | ||
.execute(ParticleExecutor) | ||
.then( | ||
argument(ARG_POS, Position3DArgumentConsumer) | ||
.execute(ParticleExecutor) | ||
.then( | ||
argument(ARG_DELTA, Position3DArgumentConsumer) | ||
.execute(ParticleExecutor) | ||
.then( | ||
argument( | ||
ARG_SPEED, | ||
BoundedNumArgumentConsumer::<f32>::new().min(0.0), | ||
) | ||
.execute(ParticleExecutor) | ||
.then( | ||
argument( | ||
ARG_COUNT, | ||
BoundedNumArgumentConsumer::<i32>::new().min(0), | ||
) | ||
.execute(ParticleExecutor), | ||
), | ||
), | ||
), | ||
), | ||
// TODO: Add NBT | ||
) | ||
} |
Oops, something went wrong.