Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command API #351

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ff803cd
Some descriptions
Jenya705 May 7, 2023
27f11bf
Some bugs
Jenya705 May 11, 2023
12b1ce3
Some objects
Jenya705 May 20, 2023
365d1c6
primitives, vectors, relative values, angles
Jenya705 May 29, 2023
858892e
BlockPredicate
Jenya705 Jun 2, 2023
da177ba
Merge branch 'valence-rs:main' into brigadier
Jenya705 Jun 3, 2023
5258fb0
merge fix
Jenya705 Jun 3, 2023
f58bf16
Some more api and Block argument
Jenya705 Jun 4, 2023
de3179d
Merge branch 'main' into brigadier
Jenya705 Jun 4, 2023
6f87ba6
CEnum trait
Jenya705 Jun 4, 2023
5f06bff
Merge branch 'brigadier' of github.com:Jenya705/valence into brigadier
Jenya705 Jun 4, 2023
ffa9a3a
GameMode
Jenya705 Jun 4, 2023
838f0f1
argument.rs -> many modules
Jenya705 Jun 5, 2023
485c5e7
Cenums + fixes
Jenya705 Jun 6, 2023
3f10625
Range
Jenya705 Jun 7, 2023
3bfb1d1
StrCursor contains chars and bytes offsets
Jenya705 Jun 7, 2023
9a51965
EntitySelector
Jenya705 Jun 11, 2023
663b88d
Readme.md, selectors PROP_NAMES
Jenya705 Jun 12, 2023
79c0116
Item
Jenya705 Jun 15, 2023
275f5d8
More convenient parse trait
Jenya705 Jun 17, 2023
34970c4
query -> param
Jenya705 Jun 17, 2023
9167640
Const array and Dyn array
Jenya705 Jun 17, 2023
ba7ff7c
Suggestion change
Jenya705 Jun 18, 2023
8492d70
Merge branch 'valence-rs:main' into brigadier
Jenya705 Jun 30, 2023
dc61fd4
Command exec system
Jenya705 Jun 30, 2023
dbd358c
Right command node tree and suggestion's event
Jenya705 Jul 4, 2023
d205de1
Callback execution systems, real nodes, compilation
Jenya705 Jul 24, 2023
aa0a1b5
Integer's parsers and a small tp command
Jenya705 Jul 24, 2023
1c555c2
tp zfloat, to prove that multiple parsers work
Jenya705 Jul 24, 2023
6d5ce1b
Merge branch 'valence-rs:main' into brigadier
Jenya705 Jul 27, 2023
fbfe2b9
Suggestions
Jenya705 Aug 5, 2023
2ea8f51
path fixes
Jenya705 Aug 5, 2023
e3ba4be
Parse::Item, last_entity fix
Jenya705 Aug 5, 2023
30da824
Nodes are now in graph
Jenya705 Aug 10, 2023
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
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ default = [
"network",
"player_list",
"world_border",
"command"
]
advancement = ["dep:valence_advancement"]
anvil = ["dep:valence_anvil"]
Expand All @@ -29,6 +30,7 @@ log = ["dep:bevy_log"]
network = ["dep:valence_network"]
player_list = ["dep:valence_player_list"]
world_border = ["dep:valence_world_border"]
command = ["dep:valence_command"]

[dependencies]
anyhow.workspace = true
Expand All @@ -55,6 +57,7 @@ valence_network = { workspace = true, optional = true }
valence_player_list = { workspace = true, optional = true }
valence_registry.workspace = true
valence_world_border = { workspace = true, optional = true }
valence_command = { workspace = true, optional = true }

[dev-dependencies]
anyhow.workspace = true
Expand Down Expand Up @@ -108,9 +111,11 @@ bevy_utils = { version = "0.11" }
bitfield-struct = "0.3.1"
byteorder = "1.4.3"
bytes = "1.2.1"
casey = "0.4.0"
cesu8 = "1.1.0"
cfb8 = "0.8.1"
clap = { version = "4.0.30", features = ["derive"] }
ctor = "0.2.0"
criterion = "0.4.0"
directories = "5.0.0"
eframe = { version = "0.22.0", default-features = false }
Expand Down Expand Up @@ -149,6 +154,7 @@ serde = "1.0.160"
serde_json = "1.0.96"
sha1 = "0.10.5"
sha2 = "0.10.6"
smallvec = "1.11.0"
syn = "2.0.15"
syntect = { version = "5.0.0", default-features = false }
tempfile = "3.3.0"
Expand All @@ -166,6 +172,7 @@ valence_biome.path = "crates/valence_biome"
valence_block.path = "crates/valence_block"
valence_build_utils.path = "crates/valence_build_utils"
valence_client.path = "crates/valence_client"
valence_command.path = "crates/valence_command"
valence_core_macros.path = "crates/valence_core_macros"
valence_core.path = "crates/valence_core"
valence_dimension.path = "crates/valence_dimension"
Expand Down
28 changes: 28 additions & 0 deletions crates/valence_command/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "valence_command"
version.workspace = true
edition.workspace = true

[dependencies]
async-trait.workspace = true
bevy_ecs.workspace = true
bevy_app.workspace = true
bevy_hierarchy.workspace = true
byteorder.workspace = true
valence_core.workspace = true
anyhow.workspace = true
glam.workspace = true
serde_json.workspace = true
serde.workspace = true
valence_client.workspace = true
valence_block.workspace = true
valence_nbt.workspace = true
valence_entity.workspace = true
valence_instance.workspace = true
ctor.workspace = true
casey.workspace = true
paste.workspace = true
rustc-hash.workspace = true
smallvec.workspace = true
parking_lot.workspace = true
tokio.workspace = true
106 changes: 106 additions & 0 deletions crates/valence_command/src/boolean.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
use std::any::TypeId;
use std::borrow::Cow;

use bevy_ecs::system::SystemParamItem;
use valence_core::text::Text;
use valence_core::translation_key::{PARSING_BOOL_EXPECTED, PARSING_BOOL_INVALID};

use crate::command::CommandExecutorBase;
use crate::nodes::NodeSuggestion;
use crate::parse::{Parse, ParseResult};
use crate::pkt;
use crate::reader::{ArcStrReader, StrLocated, StrReader, StrSpan};
use crate::suggestions::Suggestion;

#[async_trait::async_trait]
impl Parse for bool {
type Item<'a> = bool;

type Data<'a> = ();

type Suggestions = StrSpan;

type SuggestionsParam = ();

type SuggestionsAsyncData = Cow<'static, [Suggestion<'static>]>;

const VANILLA: bool = true;

fn parse_id() -> TypeId {
TypeId::of::<Self>()
}

fn item_id() -> TypeId {
TypeId::of::<Self>()
}

fn parse<'a>(
_data: &Self::Data<'a>,
suggestions: &mut Self::Suggestions,
reader: &mut StrReader<'a>,
) -> ParseResult<Self> {
reader.span_err_located(suggestions, |reader| {
let str = reader.read_unquoted_str();
if str.is_empty() {
Err(Text::translate(PARSING_BOOL_EXPECTED, vec![]))
} else if str.eq_ignore_ascii_case("true") {
Ok(true)
} else if str.eq_ignore_ascii_case("false") {
Ok(false)
} else {
Err(Text::translate(
PARSING_BOOL_INVALID,
vec![str.to_string().into()],
))
}
})
}

fn brigadier(_data: &Self::Data<'_>) -> Option<pkt::Parser<'static>> {
Some(pkt::Parser::Bool)
}

fn brigadier_suggestions(_data: &Self::Data<'_>) -> Option<NodeSuggestion> {
None
}

fn create_suggestions_data(
_data: &Self::Data<'_>,
command: ArcStrReader,
_executor: CommandExecutorBase,
suggestions: &Self::Suggestions,
_param: SystemParamItem<Self::SuggestionsParam>,
) -> Self::SuggestionsAsyncData {
const EMPTY: &[Suggestion<'static>] = &[];
const ONLY_TRUE: &[Suggestion<'static>] = &[Suggestion::new_str("true")];
const ONLY_FALSE: &[Suggestion<'static>] = &[Suggestion::new_str("false")];
const BOTH: &[Suggestion<'static>] =
&[Suggestion::new_str("true"), Suggestion::new_str("false")];

let str = suggestions.in_str(command.reader().str()).unwrap();

Cow::Borrowed(if str.len() > 5 {
EMPTY
} else {
let lc_str = str.to_ascii_lowercase();
if str.len() == 0 {
BOTH
} else if "true".starts_with(&lc_str) {
ONLY_TRUE
} else if "false".starts_with(&lc_str) {
ONLY_FALSE
} else {
EMPTY
}
})
}

async fn suggestions(
_command: ArcStrReader,
_executor: CommandExecutorBase,
suggestions: Box<Self::Suggestions>,
async_data: Self::SuggestionsAsyncData,
) -> StrLocated<Cow<'static, [Suggestion<'static>]>> {
StrLocated::new(*suggestions, async_data)
}
}
Loading