-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add /setblock command * fix particles, block state id, block coordinate rounding, WoldPosition formatting * fix block state/block mixup --------- Co-authored-by: user622628252416 <nnew8715@gmail.com>
- Loading branch information
1 parent
91d2eee
commit 29d203c
Showing
16 changed files
with
507 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use async_trait::async_trait; | ||
use pumpkin_protocol::client::play::{ | ||
CommandSuggestion, ProtoCmdArgParser, ProtoCmdArgSuggestionType, | ||
}; | ||
use pumpkin_world::block::block_registry::{self, Block}; | ||
|
||
use crate::{command::dispatcher::CommandError, server::Server}; | ||
|
||
use super::{ | ||
super::{ | ||
args::{ArgumentConsumer, RawArgs}, | ||
CommandSender, | ||
}, | ||
Arg, DefaultNameArgConsumer, FindArg, GetClientSideArgParser, | ||
}; | ||
|
||
pub(crate) struct BlockArgumentConsumer; | ||
|
||
impl GetClientSideArgParser for BlockArgumentConsumer { | ||
fn get_client_side_parser(&self) -> ProtoCmdArgParser { | ||
ProtoCmdArgParser::Resource { | ||
identifier: "block", | ||
} | ||
} | ||
|
||
fn get_client_side_suggestion_type_override(&self) -> Option<ProtoCmdArgSuggestionType> { | ||
None | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl ArgumentConsumer for BlockArgumentConsumer { | ||
async fn consume<'a>( | ||
&self, | ||
_sender: &CommandSender<'a>, | ||
_server: &'a Server, | ||
args: &mut RawArgs<'a>, | ||
) -> Option<Arg<'a>> { | ||
let s = args.pop()?; | ||
|
||
let name = if s.contains(':') { | ||
s.to_string() | ||
} else { | ||
format!("minecraft:{s}") | ||
}; | ||
|
||
Some(Arg::Block(name)) | ||
} | ||
|
||
async fn suggest<'a>( | ||
&self, | ||
_sender: &CommandSender<'a>, | ||
_server: &'a Server, | ||
_input: &'a str, | ||
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> { | ||
Ok(None) | ||
} | ||
} | ||
|
||
impl DefaultNameArgConsumer for BlockArgumentConsumer { | ||
fn default_name(&self) -> &'static str { | ||
"block" | ||
} | ||
|
||
fn get_argument_consumer(&self) -> &dyn ArgumentConsumer { | ||
self | ||
} | ||
} | ||
|
||
impl<'a> FindArg<'a> for BlockArgumentConsumer { | ||
type Data = &'a Block; | ||
|
||
fn find_arg(args: &'a super::ConsumedArgs, name: &'a str) -> Result<Self::Data, CommandError> { | ||
match args.get(name) { | ||
Some(Arg::Block(name)) => match block_registry::get_block(name) { | ||
Some(block) => Ok(block), | ||
None => Err(CommandError::GeneralCommandIssue(format!( | ||
"Block {name} does not exist." | ||
))), | ||
}, | ||
_ => 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
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.