Skip to content

Commit

Permalink
fix ClientboundLevelParticlesPacket errors and pathfinder /particle e…
Browse files Browse the repository at this point in the history
…rrors
  • Loading branch information
mat-1 committed Aug 11, 2024
2 parents d9cbe3f + 92c9075 commit 0c4d550
Show file tree
Hide file tree
Showing 132 changed files with 14,209 additions and 14,874 deletions.
674 changes: 362 additions & 312 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A collection of Rust crates for making Minecraft bots, clients, and tools.

<!-- The line below is automatically read and updated by the migrate script, so don't change it manually. -->

_Currently supported Minecraft version: `1.20.4`._
_Currently supported Minecraft version: `1.21.1`._

> [!WARNING]
> Azalea is still very unfinished, though most crates are in a somewhat useable state
Expand Down Expand Up @@ -51,8 +51,12 @@ If you'd like to chat about Azalea, you can join the Matrix space at [#azalea:ma

## Branches

There are several branches in the Azalea repository that target older Minecraft versions. It is not guaranteed that they will be up-to-date with the latest version of Azalea. If you'd like to update them or add more, please open a PR.
There are several branches in the Azalea repository that target older Minecraft versions.
Most of them are severely outdated compared to the latest version of Azalea.
If you'd like to update them or add more, please open a PR.

- [1.20.5-1.20.6](https://github.com/azalea-rs/azalea/tree/1.20.6)
- [1.20.4](https://github.com/azalea-rs/azalea/tree/1.20.4)
- [1.20.2](https://github.com/azalea-rs/azalea/tree/1.20.2)
- [1.20-1.20.1](https://github.com/azalea-rs/azalea/tree/1.20.1)
- [1.19.4](https://github.com/azalea-rs/azalea/tree/1.19.4)
Expand Down
24 changes: 12 additions & 12 deletions azalea-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ edition = "2021"
license = "MIT"
name = "azalea-auth"
repository = "https://github.com/azalea-rs/azalea/tree/main/azalea-auth"
version = "0.9.1"
version = "0.10.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
azalea-buf = { path = "../azalea-buf", version = "0.9.0" }
azalea-crypto = { path = "../azalea-crypto", version = "0.9.0" }
base64 = "0.22.0"
azalea-buf = { path = "../azalea-buf", version = "0.10.0" }
azalea-crypto = { path = "../azalea-crypto", version = "0.10.0" }
base64 = "0.22.1"
chrono = { version = "0.4.38", default-features = false, features = ["serde"] }
tracing = "0.1.40"
num-bigint = "0.4.4"
num-bigint = "0.4.6"
once_cell = "1.19.0"
reqwest = { version = "0.12.4", default-features = false, features = [
reqwest = { version = "0.12.5", default-features = false, features = [
"json",
"rustls-tls",
] }
rsa = "0.9.6"
serde = { version = "1.0.198", features = ["derive"] }
serde_json = "1.0.116"
thiserror = "1.0.58"
tokio = { version = "1.37.0", features = ["fs"] }
uuid = { version = "1.8.0", features = ["serde", "v3"] }
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.120"
thiserror = "1.0.61"
tokio = { version = "1.38.0", features = ["fs"] }
uuid = { version = "1.9.1", features = ["serde", "v3"] }
md-5 = "0.10.6"

[dev-dependencies]
env_logger = "0.11.3"
tokio = { version = "1.37.0", features = ["full"] }
tokio = { version = "1.38.0", features = ["full"] }
8 changes: 4 additions & 4 deletions azalea-block/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ edition = "2021"
license = "MIT"
name = "azalea-block"
repository = "https://github.com/azalea-rs/azalea/tree/main/azalea-block"
version = "0.9.1"
version = "0.10.2"

[lib]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
azalea-block-macros = { path = "./azalea-block-macros", version = "0.9.0" }
azalea-buf = { path = "../azalea-buf", version = "0.9.0" }
azalea-registry = { version = "0.9.0", path = "../azalea-registry" }
azalea-block-macros = { path = "./azalea-block-macros", version = "0.10.0" }
azalea-buf = { path = "../azalea-buf", version = "0.10.0" }
azalea-registry = { version = "0.10.0", path = "../azalea-registry" }
6 changes: 3 additions & 3 deletions azalea-block/azalea-block-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ edition = "2021"
license = "MIT"
name = "azalea-block-macros"
repository = "https://github.com/azalea-rs/azalea/tree/main/azalea-block/azalea-block-macros"
version = "0.9.1"
version = "0.10.2"

[lib]
proc-macro = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
proc-macro2 = "1.0.81"
proc-macro2 = "1.0.86"
quote = "1.0.36"
syn = "2.0.60"
syn = "2.0.68"
74 changes: 42 additions & 32 deletions azalea-block/azalea-block-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ struct PropertyDefinitions {
properties: Vec<PropertyDefinition>,
}

/// `snowy: Snowy(false)` or `axis: properties::Axis::Y`
/// `"snowy": Snowy(false)` or `"axis": properties::Axis::Y`
#[derive(Debug)]
struct PropertyWithNameAndDefault {
// "snowy" / "axis"
name: Ident,
// "snowy" "axis"
name: String,
/// The property name, potentially modified so it works better as a struct
/// field.
name_ident: Ident,
// Snowy / Axis
property_type: Ident,
property_value_type: Ident,
Expand All @@ -54,7 +57,7 @@ struct PropertyWithNameAndDefault {

/// ```ignore
/// grass_block => BlockBehavior::default(), {
/// snowy: false,
/// "snowy": false,
/// },
/// ```
struct BlockDefinition {
Expand All @@ -64,8 +67,8 @@ struct BlockDefinition {
}
impl Parse for PropertyWithNameAndDefault {
fn parse(input: ParseStream) -> Result<Self> {
// `snowy: Snowy(false)` or `axis: properties::Axis::Y`
let property_name = input.parse()?;
// `"snowy": Snowy(false)` or `"axis": properties::Axis::Y`
let property_name = input.parse::<LitStr>()?.value();
input.parse::<Token![:]>()?;

let first_ident = input.call(Ident::parse_any)?;
Expand Down Expand Up @@ -100,8 +103,11 @@ impl Parse for PropertyWithNameAndDefault {
}
};

let property_name_ident = name_to_ident(&property_name);

Ok(PropertyWithNameAndDefault {
name: property_name,
name_ident: property_name_ident,
property_type,
property_value_type,
is_enum,
Expand Down Expand Up @@ -196,11 +202,11 @@ impl Parse for PropertyDefinitions {

impl Parse for BlockDefinition {
fn parse(input: ParseStream) -> Result<Self> {
// acacia_button => BlockBehavior::default(), {
// Facing=North,
// Powered=False,
// Face=Wall,
// }
// acacia_button => BlockBehavior::new().strength(0.5, 0.5), {
// "face": Face::Wall,
// "facing": FacingCardinal::North,
// "powered": Powered(false),
// },
let name = input.parse()?;
input.parse::<Token![=>]>()?;
let behavior = input.parse()?;
Expand Down Expand Up @@ -416,29 +422,25 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
Some(
previous_names
.iter()
.filter(|&p| p == &property.name.to_string())
.filter(|&p| p == &property.name)
.count(),
)
} else {
None
};
// ```ignore
// let mut property_name = property_struct_names_to_names
// .get(&property.property_type.to_string())
// .unwrap_or_else(|| panic!("Property '{}' is bad", property.property_type))
// .clone();
// ```

let mut property_name = property_struct_names_to_names
.get(&property.name.to_string())
.get(&property.name)
.cloned()
.unwrap_or_else(|| property.name.to_string());
.unwrap_or_else(|| property.name.clone());
previous_names.push(property_name.clone());
if let Some(index) = index {
// property_name.push_str(&format!("_{}", &index.to_string()));
write!(property_name, "_{index}").unwrap();
}
properties_with_name.push(PropertyWithNameAndDefault {
name: Ident::new(&property_name, proc_macro2::Span::call_site()),
name_ident: name_to_ident(&property_name),
name: property_name,
property_type: property.property_type.clone(),
property_value_type: property.property_value_type.clone(),
is_enum: property.is_enum,
Expand All @@ -457,17 +459,15 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
let mut block_struct_fields = quote! {};
for PropertyWithNameAndDefault {
property_value_type,
name,
name_ident,
is_enum,
..
} in &properties_with_name
{
// let property_name_snake =
// Ident::new(&property.to_string(), proc_macro2::Span::call_site());
block_struct_fields.extend(if *is_enum {
quote! { pub #name: properties::#property_value_type, }
quote! { pub #name_ident: properties::#property_value_type, }
} else {
quote! { pub #name: #property_value_type, }
quote! { pub #name_ident: #property_value_type, }
});
}

Expand Down Expand Up @@ -502,7 +502,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
let mut from_block_to_state_combination_match_inner = quote! {};
for i in 0..properties_with_name.len() {
let property = &properties_with_name[i];
let property_name = &property.name;
let property_name_ident = &property.name_ident;
let property_value_name_ident = &property.property_type;
let variant =
Ident::new(&combination[i].to_string(), proc_macro2::Span::call_site());
Expand All @@ -526,7 +526,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
};

from_block_to_state_combination_match_inner.extend(quote! {
#property_name: #property_variant,
#property_name_ident: #property_variant,
});

// add to properties_to_state_ids
Expand Down Expand Up @@ -586,7 +586,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
for i in (0..properties_with_name.len()).rev() {
let PropertyWithNameAndDefault {
property_type: property_struct_name_ident,
name: property_name,
name_ident: property_name_ident,
property_value_type,
..
} = &properties_with_name[i];
Expand All @@ -603,7 +603,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
}
};
from_state_to_block_inner.extend(quote! {
#property_name: #conversion_code,
#property_name_ident: #conversion_code,
});

division *= property_variants_count;
Expand All @@ -630,12 +630,12 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {

let mut block_default_fields = quote! {};
for PropertyWithNameAndDefault {
name,
name_ident,
default: property_default,
..
} in properties_with_name
{
block_default_fields.extend(quote! { #name: #property_default, });
block_default_fields.extend(quote! { #name_ident: #property_default, });
}

let block_behavior = &block.behavior;
Expand Down Expand Up @@ -823,3 +823,13 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {

generated.into()
}

/// Convert a name to a Rust identifier, replacing some Rust keywords with
/// alternatives (e.g. `type` -> `kind`).
fn name_to_ident(name: &str) -> Ident {
let ident_str = match name {
"type" => "kind",
_ => name,
};
Ident::new(ident_str, proc_macro2::Span::call_site())
}
Loading

0 comments on commit 0c4d550

Please sign in to comment.