Skip to content

Commit

Permalink
Merge branch 'main' into 1.20.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Oct 11, 2023
2 parents 3f83148 + d5f424b commit 6a30a43
Show file tree
Hide file tree
Showing 55 changed files with 775 additions and 520 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A collection of Rust crates for making Minecraft bots, clients, and tools.
## Features

- [Accurate physics](https://github.com/azalea-rs/azalea/blob/main/azalea-physics/src/lib.rs) (but some features like knockback and water physics aren't yet implemented)
- [Accurate physics](https://github.com/azalea-rs/azalea/blob/main/azalea-physics/src/lib.rs) (but some features like entity collisions and water physics aren't yet implemented)
- [Pathfinder](https://azalea.matdoes.dev/azalea/pathfinder/index.html)
- [Swarms](https://azalea.matdoes.dev/azalea/swarm/index.html)
- [Breaking blocks](https://azalea.matdoes.dev/azalea/struct.Client.html#method.mine)
Expand Down Expand Up @@ -55,7 +55,7 @@ For fun, mostly. I wasn't satisfied with the current state of Minecraft bot libr

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.

- [1.20-1.20.1](https://github.com/mat-1/azalea/tree/1.20.1)
- [1.19.4](https://github.com/mat-1/azalea/tree/1.19.4)
- [1.19.3](https://github.com/mat-1/azalea/tree/1.19.3)
- [1.19.2](https://github.com/mat-1/azalea/tree/1.19.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)
- [1.19.3](https://github.com/azalea-rs/azalea/tree/1.19.3)
- [1.19.2](https://github.com/azalea-rs/azalea/tree/1.19.2)
2 changes: 1 addition & 1 deletion azalea-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "A port of Mojang's Authlib and launcher authentication."
edition = "2021"
license = "MIT"
name = "azalea-auth"
repository = "https://github.com/mat-1/azalea/tree/main/azalea-auth"
repository = "https://github.com/azalea-rs/azalea/tree/main/azalea-auth"
version = "0.8.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion azalea-block/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "Representation of Minecraft block states."
edition = "2021"
license = "MIT"
name = "azalea-block"
repository = "https://github.com/mat-1/azalea/tree/main/azalea-block"
repository = "https://github.com/azalea-rs/azalea/tree/main/azalea-block"
version = "0.8.0"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion azalea-block/azalea-block-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "Proc macros used by azalea-block."
edition = "2021"
license = "MIT"
name = "azalea-block-macros"
repository = "https://github.com/mat-1/azalea/tree/main/azalea-block/azalea-block-macros"
repository = "https://github.com/azalea-rs/azalea/tree/main/azalea-block/azalea-block-macros"
version = "0.8.0"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion azalea-brigadier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "A port of Mojang's Brigadier command parsing and dispatching libr
edition = "2021"
license = "MIT"
name = "azalea-brigadier"
repository = "https://github.com/mat-1/azalea/tree/main/azalea-brigadier"
repository = "https://github.com/azalea-rs/azalea/tree/main/azalea-brigadier"
version = "0.8.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion azalea-brigadier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ assert_eq!(
);
```

See the [tests](https://github.com/mat-1/azalea/tree/main/azalea-brigadier/tests) for more.
See the [tests](https://github.com/azalea-rs/azalea/tree/main/azalea-brigadier/tests) for more.

4 changes: 2 additions & 2 deletions azalea-brigadier/src/arguments/argument_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{any::Any, rc::Rc};
use std::{any::Any, sync::Arc};

use crate::{exceptions::CommandSyntaxException, string_reader::StringReader};

pub trait ArgumentType {
fn parse(&self, reader: &mut StringReader) -> Result<Rc<dyn Any>, CommandSyntaxException>;
fn parse(&self, reader: &mut StringReader) -> Result<Arc<dyn Any>, CommandSyntaxException>;
}
6 changes: 3 additions & 3 deletions azalea-brigadier/src/arguments/bool_argument_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{any::Any, rc::Rc};
use std::{any::Any, sync::Arc};

use crate::{
context::CommandContext, exceptions::CommandSyntaxException, string_reader::StringReader,
Expand All @@ -10,8 +10,8 @@ use super::ArgumentType;
struct Boolean;

impl ArgumentType for Boolean {
fn parse(&self, reader: &mut StringReader) -> Result<Rc<dyn Any>, CommandSyntaxException> {
Ok(Rc::new(reader.read_boolean()?))
fn parse(&self, reader: &mut StringReader) -> Result<Arc<dyn Any>, CommandSyntaxException> {
Ok(Arc::new(reader.read_boolean()?))
}
}

Expand Down
6 changes: 3 additions & 3 deletions azalea-brigadier/src/arguments/double_argument_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{any::Any, rc::Rc};
use std::{any::Any, sync::Arc};

use crate::{
context::CommandContext,
Expand All @@ -15,7 +15,7 @@ struct Double {
}

impl ArgumentType for Double {
fn parse(&self, reader: &mut StringReader) -> Result<Rc<dyn Any>, CommandSyntaxException> {
fn parse(&self, reader: &mut StringReader) -> Result<Arc<dyn Any>, CommandSyntaxException> {
let start = reader.cursor;
let result = reader.read_double()?;
if let Some(minimum) = self.minimum {
Expand All @@ -38,7 +38,7 @@ impl ArgumentType for Double {
.create_with_context(reader));
}
}
Ok(Rc::new(result))
Ok(Arc::new(result))
}
}

Expand Down
6 changes: 3 additions & 3 deletions azalea-brigadier/src/arguments/float_argument_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{any::Any, rc::Rc};
use std::{any::Any, sync::Arc};

use crate::{
context::CommandContext,
Expand All @@ -15,7 +15,7 @@ struct Float {
}

impl ArgumentType for Float {
fn parse(&self, reader: &mut StringReader) -> Result<Rc<dyn Any>, CommandSyntaxException> {
fn parse(&self, reader: &mut StringReader) -> Result<Arc<dyn Any>, CommandSyntaxException> {
let start = reader.cursor;
let result = reader.read_float()?;
if let Some(minimum) = self.minimum {
Expand All @@ -38,7 +38,7 @@ impl ArgumentType for Float {
.create_with_context(reader));
}
}
Ok(Rc::new(result))
Ok(Arc::new(result))
}
}

Expand Down
6 changes: 3 additions & 3 deletions azalea-brigadier/src/arguments/integer_argument_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{any::Any, rc::Rc};
use std::{any::Any, sync::Arc};

use crate::{
context::CommandContext,
Expand All @@ -15,7 +15,7 @@ struct Integer {
}

impl ArgumentType for Integer {
fn parse(&self, reader: &mut StringReader) -> Result<Rc<dyn Any>, CommandSyntaxException> {
fn parse(&self, reader: &mut StringReader) -> Result<Arc<dyn Any>, CommandSyntaxException> {
let start = reader.cursor;
let result = reader.read_int()?;
if let Some(minimum) = self.minimum {
Expand All @@ -38,7 +38,7 @@ impl ArgumentType for Integer {
.create_with_context(reader));
}
}
Ok(Rc::new(result))
Ok(Arc::new(result))
}
}

Expand Down
6 changes: 3 additions & 3 deletions azalea-brigadier/src/arguments/long_argument_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{any::Any, rc::Rc};
use std::{any::Any, sync::Arc};

use crate::{
context::CommandContext,
Expand All @@ -15,7 +15,7 @@ struct Long {
}

impl ArgumentType for Long {
fn parse(&self, reader: &mut StringReader) -> Result<Rc<dyn Any>, CommandSyntaxException> {
fn parse(&self, reader: &mut StringReader) -> Result<Arc<dyn Any>, CommandSyntaxException> {
let start = reader.cursor;
let result = reader.read_long()?;
if let Some(minimum) = self.minimum {
Expand All @@ -38,7 +38,7 @@ impl ArgumentType for Long {
.create_with_context(reader));
}
}
Ok(Rc::new(result))
Ok(Arc::new(result))
}
}

Expand Down
6 changes: 3 additions & 3 deletions azalea-brigadier/src/arguments/string_argument_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{any::Any, rc::Rc};
use std::{any::Any, sync::Arc};

use crate::{
context::CommandContext, exceptions::CommandSyntaxException, string_reader::StringReader,
Expand All @@ -17,7 +17,7 @@ pub enum StringArgument {
}

impl ArgumentType for StringArgument {
fn parse(&self, reader: &mut StringReader) -> Result<Rc<dyn Any>, CommandSyntaxException> {
fn parse(&self, reader: &mut StringReader) -> Result<Arc<dyn Any>, CommandSyntaxException> {
let result = match self {
StringArgument::SingleWord => reader.read_unquoted_string().to_string(),
StringArgument::QuotablePhrase => reader.read_string()?,
Expand All @@ -27,7 +27,7 @@ impl ArgumentType for StringArgument {
text
}
};
Ok(Rc::new(result))
Ok(Arc::new(result))
}
}

Expand Down
4 changes: 2 additions & 2 deletions azalea-brigadier/src/builder/required_argument_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::argument_builder::{ArgumentBuilder, ArgumentBuilderType};
use crate::{
arguments::ArgumentType, exceptions::CommandSyntaxException, string_reader::StringReader,
};
use std::{any::Any, fmt::Debug, rc::Rc, sync::Arc};
use std::{any::Any, fmt::Debug, sync::Arc};

/// An argument node type. The `T` type parameter is the type of the argument,
/// which can be anything.
Expand All @@ -19,7 +19,7 @@ impl Argument {
}
}

pub fn parse(&self, reader: &mut StringReader) -> Result<Rc<dyn Any>, CommandSyntaxException> {
pub fn parse(&self, reader: &mut StringReader) -> Result<Arc<dyn Any>, CommandSyntaxException> {
self.parser.parse(reader)
}
}
Expand Down
2 changes: 1 addition & 1 deletion azalea-brigadier/src/context/command_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<S> CommandContext<S> {
!self.nodes.is_empty()
}

pub fn argument(&self, name: &str) -> Option<Rc<dyn Any>> {
pub fn argument(&self, name: &str) -> Option<Arc<dyn Any>> {
let argument = self.arguments.get(name);
argument.map(|a| a.result.clone())
}
Expand Down
4 changes: 2 additions & 2 deletions azalea-brigadier/src/context/parsed_argument.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::string_range::StringRange;
use std::{any::Any, rc::Rc};
use std::{any::Any, sync::Arc};

#[derive(Clone)]
pub struct ParsedArgument {
pub range: StringRange,
pub result: Rc<dyn Any>,
pub result: Arc<dyn Any>,
}
2 changes: 1 addition & 1 deletion azalea-buf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "Serialize and deserialize buffers from Minecraft."
edition = "2021"
license = "MIT"
name = "azalea-buf"
repository = "https://github.com/mat-1/azalea/tree/main/azalea-buf"
repository = "https://github.com/azalea-rs/azalea/tree/main/azalea-buf"
version = "0.8.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion azalea-buf/azalea-buf-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "#[derive(McBuf)]"
edition = "2021"
license = "MIT"
name = "azalea-buf-macros"
repository = "https://github.com/mat-1/azalea/tree/main/azalea-buf"
repository = "https://github.com/azalea-rs/azalea/tree/main/azalea-buf"
version = "0.8.0"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion azalea-chat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "Parse Minecraft chat messages."
edition = "2021"
license = "MIT"
name = "azalea-chat"
repository = "https://github.com/mat-1/azalea/tree/main/azalea-chat"
repository = "https://github.com/azalea-rs/azalea/tree/main/azalea-chat"
version = "0.8.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion azalea-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "A headless Minecraft client."
edition = "2021"
license = "MIT"
name = "azalea-client"
repository = "https://github.com/mat-1/azalea/tree/main/azalea-client"
repository = "https://github.com/azalea-rs/azalea/tree/main/azalea-client"
version = "0.8.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion azalea-client/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Client {
}

/// A component present on all local players that have an inventory.
#[derive(Component, Debug)]
#[derive(Component, Debug, Clone)]
pub struct InventoryComponent {
/// A component that contains the player's inventory menu. This is
/// guaranteed to be a `Menu::Player`.
Expand Down
49 changes: 46 additions & 3 deletions azalea-client/src/packet_handling/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,38 @@ pub fn process_packet_events(ecs: &mut World) {
ClientboundGamePacket::UpdateAttributes(_p) => {
// debug!("Got update attributes packet {p:?}");
}
ClientboundGamePacket::SetEntityMotion(_p) => {
// debug!("Got entity velocity packet {p:?}");
ClientboundGamePacket::SetEntityMotion(p) => {
// vanilla servers use this packet for knockback, but note that the Explode
// packet is also sometimes used by servers for knockback

let mut system_state: SystemState<(
Commands,
Query<(&EntityIdIndex, &InstanceHolder)>,
)> = SystemState::new(ecs);
let (mut commands, mut query) = system_state.get_mut(ecs);
let (entity_id_index, instance_holder) = query.get_mut(player_entity).unwrap();

let Some(entity) = entity_id_index.get(&MinecraftEntityId(p.id)) else {
warn!(
"Got set entity motion packet for unknown entity id {}",
p.id
);
continue;
};

commands.entity(entity).add(RelativeEntityUpdate {
partial_world: instance_holder.partial_instance.clone(),
update: Box::new(move |entity| {
let mut physics = entity.get_mut::<Physics>().unwrap();
physics.delta = Vec3 {
x: p.xa as f64 / 8000.,
y: p.ya as f64 / 8000.,
z: p.za as f64 / 8000.,
};
}),
});

system_state.apply(ecs);
}
ClientboundGamePacket::SetEntityLink(p) => {
debug!("Got set entity link packet {p:?}");
Expand Down Expand Up @@ -1154,7 +1184,20 @@ pub fn process_packet_events(ecs: &mut World) {
ClientboundGamePacket::Cooldown(_) => {}
ClientboundGamePacket::CustomChatCompletions(_) => {}
ClientboundGamePacket::DeleteChat(_) => {}
ClientboundGamePacket::Explode(_) => {}
ClientboundGamePacket::Explode(p) => {
trace!("Got explode packet {p:?}");
let mut system_state: SystemState<Query<&mut Physics>> = SystemState::new(ecs);
let mut query = system_state.get_mut(ecs);
let mut physics = query.get_mut(player_entity).unwrap();

physics.delta += Vec3 {
x: p.knockback_x as f64,
y: p.knockback_y as f64,
z: p.knockback_z as f64,
};

system_state.apply(ecs);
}
ClientboundGamePacket::ForgetLevelChunk(_) => {}
ClientboundGamePacket::HorseScreenOpen(_) => {}
ClientboundGamePacket::MapItemData(_) => {}
Expand Down
2 changes: 1 addition & 1 deletion azalea-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "Miscellaneous things in Azalea."
edition = "2021"
license = "MIT"
name = "azalea-core"
repository = "https://github.com/mat-1/azalea/tree/main/azalea-core"
repository = "https://github.com/azalea-rs/azalea/tree/main/azalea-core"
version = "0.8.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
5 changes: 5 additions & 0 deletions azalea-core/src/bitset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ impl From<Vec<u8>> for BitSet {
}

/// A list of bits with a known fixed size.
///
/// Note that this is primarily meant for fast serialization and deserialization
/// Minecraft, if you don't need that you should use the `fixedbitset` crate
/// since it's approximately 20% faster (since it stores the data as usizes
/// instead of u8s)
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct FixedBitSet<const N: usize>
where
Expand Down
2 changes: 1 addition & 1 deletion azalea-core/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl Vec3 {
f64::sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
}

/// Get the squared distance from this position to another position.
/// Get the distance from this position to another position.
/// Equivalent to `(self - other).length()`.
pub fn distance_to(&self, other: &Self) -> f64 {
(self - other).length()
Expand Down
2 changes: 1 addition & 1 deletion azalea-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ edition = "2021"
license = "MIT"
name = "azalea-crypto"
version = "0.8.0"
repository = "https://github.com/mat-1/azalea/tree/main/azalea-crypto"
repository = "https://github.com/azalea-rs/azalea/tree/main/azalea-crypto"

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

Expand Down
Loading

0 comments on commit 6a30a43

Please sign in to comment.