diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2024-11-27 19:31:40 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-27 19:31:40 -0600 |
| commit | 08958c2278b15ebeac8a964f392ebb792e479b61 (patch) | |
| tree | 4ae3664cea38d7fd1a8f1e95ed06fac04ffe519e /azalea | |
| parent | 139d77d3c2b0922fba5e9d4fa2bd9819d78bd773 (diff) | |
| download | azalea-drasl-08958c2278b15ebeac8a964f392ebb792e479b61.tar.xz | |
Refactor azalea-protocol (#190)
* start updating to 1.21.4
* fix block codegen and stop using block data from burger
* rename packet related modules and structs to be simpler
* ItemSlot -> ItemStack for more consistency with mojmap
* .get() -> .into_packet()
* simplify declare_state_packets by removing packet ids
* rename read_from and write_into to azalea_read and azalea_write
* rename McBufReadable and McBufWritable to AzaleaRead and AzaleaWrite
* McBuf -> AzBuf
* remove most uses of into_variant
* update codegen and use resourcelocation names for packets
* implement #[limit(i)] attribute for AzBuf derive macro
* fixes for 1.21.4
* fix examples
* update some physics code and fix ChatType
* remove unused imports in codegen
* re-add some things to migrate.py and update +mc version numbers automatically
* downgrade to 1.21.3 lol
Diffstat (limited to 'azalea')
| -rw-r--r-- | azalea/Cargo.toml | 2 | ||||
| -rw-r--r-- | azalea/examples/steal.rs | 4 | ||||
| -rw-r--r-- | azalea/src/accept_resource_packs.rs | 30 | ||||
| -rw-r--r-- | azalea/src/auto_tool.rs | 8 | ||||
| -rw-r--r-- | azalea/src/container.rs | 6 | ||||
| -rw-r--r-- | azalea/src/pathfinder/debug.rs | 2 | ||||
| -rw-r--r-- | azalea/src/pathfinder/goals.rs | 2 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 2 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/basic.rs | 12 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/mod.rs | 2 |
10 files changed, 34 insertions, 36 deletions
diff --git a/azalea/Cargo.toml b/azalea/Cargo.toml index 2e2dd345..c0953f54 100644 --- a/azalea/Cargo.toml +++ b/azalea/Cargo.toml @@ -4,7 +4,7 @@ edition = "2021" license = "MIT" name = "azalea" repository = "https://github.com/azalea-rs/azalea/tree/main/azalea" -version = "0.10.3+mc1.21.1" +version = "0.10.3+mc1.21.3" [package.metadata.release] pre-release-replacements = [ diff --git a/azalea/examples/steal.rs b/azalea/examples/steal.rs index b0586f19..f64fb8f3 100644 --- a/azalea/examples/steal.rs +++ b/azalea/examples/steal.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use azalea::{prelude::*, BlockPos}; use azalea_inventory::operations::QuickMoveClick; -use azalea_inventory::ItemSlot; +use azalea_inventory::ItemStack; use parking_lot::Mutex; #[tokio::main] @@ -59,7 +59,7 @@ async fn handle(mut bot: Client, event: Event, state: State) -> anyhow::Result<( .enumerate() { println!("Checking slot {index}: {slot:?}"); - if let ItemSlot::Present(item) = slot { + if let ItemStack::Present(item) = slot { if item.kind == azalea::registry::Item::Diamond { println!("clicking slot ^"); chest.click(QuickMoveClick::Left { slot: index as u16 }); diff --git a/azalea/src/accept_resource_packs.rs b/azalea/src/accept_resource_packs.rs index c9765c77..f62d5ec0 100644 --- a/azalea/src/accept_resource_packs.rs +++ b/azalea/src/accept_resource_packs.rs @@ -3,9 +3,7 @@ use azalea_client::inventory::InventorySet; use azalea_client::packet_handling::game::SendPacketEvent; use azalea_client::packet_handling::{death_event_on_0_health, game::ResourcePackEvent}; use azalea_client::respawn::perform_respawn; -use azalea_protocol::packets::game::serverbound_resource_pack_packet::{ - self, ServerboundResourcePackPacket, -}; +use azalea_protocol::packets::game::s_resource_pack::{self, ServerboundResourcePack}; use bevy_app::Update; use bevy_ecs::prelude::*; @@ -32,21 +30,19 @@ fn accept_resource_pack( mut send_packet_events: EventWriter<SendPacketEvent>, ) { for event in events.read() { - send_packet_events.send(SendPacketEvent { - entity: event.entity, - packet: ServerboundResourcePackPacket { + send_packet_events.send(SendPacketEvent::new( + event.entity, + ServerboundResourcePack { id: event.id, - action: serverbound_resource_pack_packet::Action::Accepted, - } - .get(), - }); - send_packet_events.send(SendPacketEvent { - entity: event.entity, - packet: ServerboundResourcePackPacket { + action: s_resource_pack::Action::Accepted, + }, + )); + send_packet_events.send(SendPacketEvent::new( + event.entity, + ServerboundResourcePack { id: event.id, - action: serverbound_resource_pack_packet::Action::SuccessfullyLoaded, - } - .get(), - }); + action: s_resource_pack::Action::SuccessfullyLoaded, + }, + )); } } diff --git a/azalea/src/auto_tool.rs b/azalea/src/auto_tool.rs index e5a627ba..441f9791 100644 --- a/azalea/src/auto_tool.rs +++ b/azalea/src/auto_tool.rs @@ -1,7 +1,7 @@ use azalea_block::{Block, BlockState}; use azalea_client::{inventory::Inventory, Client}; use azalea_entity::{FluidOnEyes, Physics}; -use azalea_inventory::{ItemSlot, Menu}; +use azalea_inventory::{ItemStack, Menu}; use azalea_registry::{DataComponentKind, Fluid}; #[derive(Debug)] @@ -80,7 +80,7 @@ pub fn accurate_best_tool_in_hotbar_for_block( for (i, item_slot) in hotbar_slots.iter().enumerate() { let this_item_speed; match item_slot { - ItemSlot::Empty => { + ItemStack::Empty => { this_item_speed = Some(azalea_entity::mining::get_mine_progress( block.as_ref(), azalea_registry::Item::Air, @@ -89,7 +89,7 @@ pub fn accurate_best_tool_in_hotbar_for_block( physics, )); } - ItemSlot::Present(item_slot) => { + ItemStack::Present(item_slot) => { // lazy way to avoid checking durability since azalea doesn't have durability // data yet if item_slot @@ -119,7 +119,7 @@ pub fn accurate_best_tool_in_hotbar_for_block( // now check every item for (i, item_slot) in hotbar_slots.iter().enumerate() { - if let ItemSlot::Present(item_slot) = item_slot { + if let ItemStack::Present(item_slot) = item_slot { let this_item_speed = azalea_entity::mining::get_mine_progress( block.as_ref(), item_slot.kind, diff --git a/azalea/src/container.rs b/azalea/src/container.rs index 980210ae..df020dbe 100644 --- a/azalea/src/container.rs +++ b/azalea/src/container.rs @@ -7,7 +7,7 @@ use azalea_client::{ Client, }; use azalea_core::position::BlockPos; -use azalea_inventory::{operations::ClickOperation, ItemSlot, Menu}; +use azalea_inventory::{operations::ClickOperation, ItemStack, Menu}; use azalea_protocol::packets::game::ClientboundGamePacket; use bevy_app::{App, Plugin, Update}; use bevy_ecs::{component::Component, prelude::EventReader, system::Commands}; @@ -168,7 +168,7 @@ impl ContainerHandleRef { /// Returns the item slots in the container, not including the player's /// inventory. If the container is closed, this will return `None`. - pub fn contents(&self) -> Option<Vec<ItemSlot>> { + pub fn contents(&self) -> Option<Vec<ItemStack>> { self.menu().map(|menu| menu.contents()) } @@ -222,7 +222,7 @@ impl ContainerHandle { /// Returns the item slots in the container, not including the player's /// inventory. If the container is closed, this will return `None`. - pub fn contents(&self) -> Option<Vec<ItemSlot>> { + pub fn contents(&self) -> Option<Vec<ItemStack>> { self.0.contents() } diff --git a/azalea/src/pathfinder/debug.rs b/azalea/src/pathfinder/debug.rs index a5e51cdf..ca08cbc5 100644 --- a/azalea/src/pathfinder/debug.rs +++ b/azalea/src/pathfinder/debug.rs @@ -60,7 +60,7 @@ pub fn debug_render_path_with_particles( let start_vec3 = start.center(); let end_vec3 = end.center(); - let step_count = (start_vec3.distance_to_sqr(&end_vec3).sqrt() * 4.0) as usize; + let step_count = (start_vec3.distance_squared_to(&end_vec3).sqrt() * 4.0) as usize; let target_block_state = chunks.get_block_state(&movement.target).unwrap_or_default(); let above_target_block_state = chunks diff --git a/azalea/src/pathfinder/goals.rs b/azalea/src/pathfinder/goals.rs index 7e33f7d8..531e4036 100644 --- a/azalea/src/pathfinder/goals.rs +++ b/azalea/src/pathfinder/goals.rs @@ -200,7 +200,7 @@ impl Goal for ReachBlockPosGoal { let max_pick_range = 6; let actual_pick_range = 4.5; - let distance = (self.pos - n).length_sqr(); + let distance = (self.pos - n).length_squared(); if distance > max_pick_range * max_pick_range { return false; } diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index 611ad5c5..88ae5da0 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -453,7 +453,7 @@ pub fn timeout_movement( // don't timeout if we're mining if let Some(mining) = mining { // also make sure we're close enough to the block that's being mined - if mining.pos.distance_to_sqr(&BlockPos::from(position)) < 6_i32.pow(2) { + if mining.pos.distance_squared_to(&BlockPos::from(position)) < 6_i32.pow(2) { // also reset the last_node_reached_at so we don't timeout after we finish // mining executing_path.last_node_reached_at = Instant::now(); diff --git a/azalea/src/pathfinder/moves/basic.rs b/azalea/src/pathfinder/moves/basic.rs index bb931caf..89ba9acc 100644 --- a/azalea/src/pathfinder/moves/basic.rs +++ b/azalea/src/pathfinder/moves/basic.rs @@ -228,9 +228,10 @@ fn execute_descend_move(mut ctx: ExecuteCtx) { let start_center = start.center(); let center = target.center(); - let horizontal_distance_from_target = (center - position).horizontal_distance_sqr().sqrt(); - let horizontal_distance_from_start = - (start.center() - position).horizontal_distance_sqr().sqrt(); + let horizontal_distance_from_target = (center - position).horizontal_distance_squared().sqrt(); + let horizontal_distance_from_start = (start.center() - position) + .horizontal_distance_squared() + .sqrt(); let dest_ahead = Vec3::new( start_center.x + (center.x - start_center.x) * 1.5, @@ -401,8 +402,9 @@ fn execute_downward_move(mut ctx: ExecuteCtx) { let target_center = target.center(); - let horizontal_distance_from_target = - (target_center - position).horizontal_distance_sqr().sqrt(); + let horizontal_distance_from_target = (target_center - position) + .horizontal_distance_squared() + .sqrt(); if horizontal_distance_from_target > 0.25 { ctx.look_at(target_center); diff --git a/azalea/src/pathfinder/moves/mod.rs b/azalea/src/pathfinder/moves/mod.rs index 28974132..1a435b5f 100644 --- a/azalea/src/pathfinder/moves/mod.rs +++ b/azalea/src/pathfinder/moves/mod.rs @@ -157,7 +157,7 @@ impl ExecuteCtx<'_, '_, '_, '_, '_, '_, '_> { /// of the current node first. pub fn mine_while_at_start(&mut self, block: BlockPos) -> bool { let horizontal_distance_from_start = (self.start.center() - self.position) - .horizontal_distance_sqr() + .horizontal_distance_squared() .sqrt(); let at_start_position = BlockPos::from(self.position) == self.start && horizontal_distance_from_start < 0.25; |
