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

1.20.5 #127

Merged
merged 16 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 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.20.5`._

> [!WARNING]
> Azalea is still very unfinished, though most crates are in a somewhat useable state
Expand Down
20 changes: 18 additions & 2 deletions azalea-block/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1917,14 +1917,21 @@ make_block_states! {
},
"cracked" => Cracked(bool),
"crafting" => Crafting(bool),
"trial_spawner_state" => State {
"ominous" => Ominous(bool),
"trial_spawner_state" => TrialSpawnerState {
Inactive,
WaitingForPlayers,
Active,
WaitingForRewardEjection,
EjectingReward,
Cooldown,
},
"vault_state" => VaultState {
Inactive,
Active,
Unlocking,
Ejecting,
},
},
Blocks => {
air => BlockBehavior::new(), {},
Expand Down Expand Up @@ -5376,7 +5383,16 @@ make_block_states! {
triggered: Triggered(false),
},
trial_spawner => BlockBehavior::new().requires_correct_tool_for_drops().strength(50.0, 50.0), {
trial_spawner_state: State::Inactive,
ominous: Ominous(false),
trial_spawner_state: TrialSpawnerState::Inactive,
},
vault => BlockBehavior::new(), {
facing: FacingCardinal::North,
ominous: Ominous(false),
vault_state: VaultState::Inactive,
},
heavy_core => BlockBehavior::new(), {
waterlogged: Waterlogged(false),
},
}
}
38 changes: 24 additions & 14 deletions azalea-buf/azalea-buf-macros/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,34 @@ fn read_named_fields(

pub fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenStream {
match data {
syn::Data::Struct(syn::DataStruct { fields, .. }) => {
let syn::Fields::Named(FieldsNamed { named, .. }) = fields else {
panic!("#[derive(McBuf)] can only be used on structs with named fields")
};

let (read_fields, read_field_names) = read_named_fields(named);
syn::Data::Struct(syn::DataStruct { fields, .. }) => match fields {
syn::Fields::Named(FieldsNamed { named, .. }) => {
let (read_fields, read_field_names) = read_named_fields(named);

quote! {
impl azalea_buf::McBufReadable for #ident {
fn read_from(buf: &mut std::io::Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> {
#(#read_fields)*
Ok(#ident {
#(#read_field_names: #read_field_names),*
})
quote! {
impl azalea_buf::McBufReadable for #ident {
fn read_from(buf: &mut std::io::Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> {
#(#read_fields)*
Ok(Self {
#(#read_field_names: #read_field_names),*
})
}
}
}
}
syn::Fields::Unit => {
quote! {
impl azalea_buf::McBufReadable for #ident {
fn read_from(buf: &mut std::io::Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> {
Ok(Self)
}
}
}
}
}
_ => {
panic!("#[derive(McBuf)] can only be used on structs with named fields")
}
},
syn::Data::Enum(syn::DataEnum { variants, .. }) => {
let mut match_contents = quote!();
let mut variant_discrim: u32 = 0;
Expand Down
36 changes: 23 additions & 13 deletions azalea-buf/azalea-buf-macros/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,33 @@ fn write_named_fields(

pub fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::TokenStream {
match data {
syn::Data::Struct(syn::DataStruct { fields, .. }) => {
let syn::Fields::Named(FieldsNamed { named, .. }) = fields else {
panic!("#[derive(McBuf)] can only be used on structs with named fields")
};

let write_fields =
write_named_fields(named, Some(&Ident::new("self", Span::call_site())));
syn::Data::Struct(syn::DataStruct { fields, .. }) => match fields {
syn::Fields::Named(FieldsNamed { named, .. }) => {
let write_fields =
write_named_fields(named, Some(&Ident::new("self", Span::call_site())));

quote! {
impl azalea_buf::McBufWritable for #ident {
fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
#write_fields
Ok(())
quote! {
impl azalea_buf::McBufWritable for #ident {
fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
#write_fields
Ok(())
}
}
}
}
}
syn::Fields::Unit => {
quote! {
impl azalea_buf::McBufWritable for #ident {
fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
Ok(())
}
}
}
}
_ => {
panic!("#[derive(McBuf)] can only be used on structs with named fields")
}
},
syn::Data::Enum(syn::DataEnum { variants, .. }) => {
// remember whether it's a data variant so we can do an optimization later
let mut is_data_enum = false;
Expand Down
20 changes: 9 additions & 11 deletions azalea-buf/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,6 @@ fn read_utf_with_len(buf: &mut Cursor<&[u8]>, max_length: u32) -> Result<String,
Ok(string)
}

// fast varints modified from https://github.com/luojia65/mc-varint/blob/master/src/lib.rs#L67
/// Read a single varint from the reader and return the value, along with the
/// number of bytes read
// pub async fn read_varint_async(
// reader: &mut (dyn AsyncRead + Unpin + Send),
// ) -> Result<i32, BufReadError> { let mut buffer = [0]; let mut ans = 0; for i
// in 0..5 { reader.read_exact(&mut buffer).await?; ans |= ((buffer[0] &
// 0b0111_1111) as i32) << (7 * i); if buffer[0] & 0b1000_0000 == 0 { break; }
// } Ok(ans)
// }

pub trait McBufReadable
where
Self: Sized,
Expand Down Expand Up @@ -373,3 +362,12 @@ impl McBufReadable for simdnbt::owned::Nbt {
Ok(simdnbt::owned::Nbt::read_unnamed(buf)?)
}
}

impl<T> McBufReadable for Box<T>
where
T: McBufReadable,
{
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
Ok(Box::new(T::read_from(buf)?))
}
}
9 changes: 9 additions & 0 deletions azalea-buf/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,12 @@ impl McBufWritable for simdnbt::owned::Nbt {
buf.write_all(&data)
}
}

impl<T> McBufWritable for Box<T>
where
T: McBufWritable,
{
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
T::write_into(&**self, buf)
}
}
5 changes: 2 additions & 3 deletions azalea-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ bevy_ecs = "0.13.2"
bevy_log = { version = "0.13.2", optional = true }
bevy_tasks = "0.13.2"
bevy_time = "0.13.2"
azalea-inventory = { path = "../azalea-inventory", version = "0.9.0" }
derive_more = { version = "0.99.17", features = ["deref", "deref_mut"] }
futures = "0.3.30"
tracing = "0.1.40"
Expand All @@ -39,11 +38,11 @@ regex = "1.10.4"
thiserror = "^1.0.58"
tokio = { version = "^1.37.0", features = ["sync"] }
uuid = "^1.8.0"
azalea-entity = { version = "0.9.0", path = "../azalea-entity" }
serde_json = "1.0.116"
serde = "1.0.198"
minecraft_folder_path = "0.1.2"
socks5-impl = "0.5.12"
azalea-entity = { version = "0.9.0", path = "../azalea-entity" }
azalea-inventory = { version = "0.9.0", path = "../azalea-inventory" }

[features]
default = ["log"]
Expand Down
17 changes: 15 additions & 2 deletions azalea-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ impl Client {
run_schedule_sender.clone(),
);

let instance = Instance::default();
let instance_holder = crate::local_player::InstanceHolder::new(
entity,
// default to an empty world, it'll be set correctly later when we
// get the login packet
Arc::new(RwLock::new(instance)),
);

ecs.entity_mut(entity).insert((
// these stay when we switch to the game state
LocalPlayerBundle {
Expand All @@ -318,6 +326,7 @@ impl Client {
local_player_events: LocalPlayerEvents(tx),
game_profile: GameProfileComponent(game_profile),
client_information: crate::ClientInformation::default(),
instance_holder,
},
InConfigurationState,
));
Expand Down Expand Up @@ -394,7 +403,7 @@ impl Client {
match packet {
ClientboundLoginPacket::Hello(p) => {
debug!("Got encryption request");
let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap();
let e = azalea_crypto::encrypt(&p.public_key, &p.challenge).unwrap();

if let Some(access_token) = &account.access_token {
// keep track of the number of times we tried
Expand Down Expand Up @@ -436,7 +445,7 @@ impl Client {
conn.write(
ServerboundKeyPacket {
key_bytes: e.encrypted_public_key,
encrypted_challenge: e.encrypted_nonce,
encrypted_challenge: e.encrypted_challenge,
}
.get(),
)
Expand Down Expand Up @@ -466,6 +475,9 @@ impl Client {
// replying to custom query is done in
// packet_handling::login::process_packet_events
}
ClientboundLoginPacket::CookieRequest(p) => {
debug!("Got cookie request {:?}", p);
}
}
};

Expand Down Expand Up @@ -666,6 +678,7 @@ pub struct LocalPlayerBundle {
pub local_player_events: LocalPlayerEvents,
pub game_profile: GameProfileComponent,
pub client_information: ClientInformation,
pub instance_holder: InstanceHolder,
}

/// A bundle for the components that are present on a local player that is
Expand Down
13 changes: 2 additions & 11 deletions azalea-client/src/interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use azalea_protocol::packets::game::{
serverbound_swing_packet::ServerboundSwingPacket,
serverbound_use_item_on_packet::{BlockHit, ServerboundUseItemOnPacket},
};
use azalea_registry::DataComponentKind;
use azalea_world::{Instance, InstanceContainer, InstanceName};
use bevy_app::{App, Plugin, Update};
use bevy_ecs::{
Expand All @@ -28,7 +29,6 @@ use bevy_ecs::{
system::{Commands, Query, Res},
};
use derive_more::{Deref, DerefMut};
use simdnbt::owned::NbtList;
use tracing::warn;

use crate::{
Expand Down Expand Up @@ -269,20 +269,11 @@ pub fn check_block_can_be_broken_by_item_in_adventure_mode(
// minecraft caches the last checked block but that's kind of an unnecessary
// optimization and makes the code too complicated

let Some(can_destroy) = item
.nbt
.compound("tag")
.and_then(|nbt| nbt.list("CanDestroy"))
else {
let Some(_can_destroy) = item.components.get(DataComponentKind::CanBreak) else {
// no CanDestroy tag
return false;
};

let NbtList::String(_can_destroy) = can_destroy else {
// CanDestroy tag must be a list of strings
return false;
};

false

// for block_predicate in can_destroy {
Expand Down
Loading
Loading