From a707e2eb82b74994a16083b31fa4576332cf1995 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Fri, 15 Dec 2023 11:26:40 -0600 Subject: Add mining to the pathfinder (#122) * basic pathfinder mining poc * mining descending and autotool * pathfinder mining descending * pathfinder fixes * allow disabling pathfinder miner and other fixes * small optimization to avoid chunk vec iter lookup sometimes * seeded rng in pathfinder bench * consistently use f32::INFINITY this brings performance much closer to how it was before * astar heuristic optimization from baritone * add downward_move * fix downward move execute * avoid liquids and falling blocks when mining * fix COST_HEURISTIC * fix to not path through flowing liquids * only reset pathfinder timeout while mining if the block is close enough * cache mining costs of block positions * fix mine_while_at_start and move PathfinderDebugParticles to its own module * add ReachBlockPosGoal in other news: azalea's sin/cos functions were broken this whole time and i never noticed * clippy and add things that i accidentally didn't commit * improve wording on doc for azalea::pathfinder --- azalea-client/src/inventory.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'azalea-client/src/inventory.rs') diff --git a/azalea-client/src/inventory.rs b/azalea-client/src/inventory.rs index 7bbefbee..527feae7 100644 --- a/azalea-client/src/inventory.rs +++ b/azalea-client/src/inventory.rs @@ -12,6 +12,7 @@ use azalea_inventory::{ use azalea_protocol::packets::game::{ serverbound_container_click_packet::ServerboundContainerClickPacket, serverbound_container_close_packet::ServerboundContainerClosePacket, + serverbound_set_carried_item_packet::ServerboundSetCarriedItemPacket, }; use azalea_registry::MenuKind; use bevy_app::{App, Plugin, Update}; @@ -40,9 +41,11 @@ impl Plugin for InventoryPlugin { .add_event::() .add_event::() .add_event::() + .add_event::() .add_systems( Update, ( + handle_set_selected_hotbar_slot_event, handle_menu_opened_event, handle_set_container_content_event, handle_container_click_event, @@ -734,3 +737,33 @@ fn handle_set_container_content_event( } } } + +#[derive(Event)] +pub struct SetSelectedHotbarSlotEvent { + pub entity: Entity, + /// The hotbar slot to select. This should be in the range 0..=8. + pub slot: u8, +} +fn handle_set_selected_hotbar_slot_event( + mut events: EventReader, + mut send_packet_events: EventWriter, + mut query: Query<&mut InventoryComponent>, +) { + for event in events.read() { + let mut inventory = query.get_mut(event.entity).unwrap(); + + // if the slot is already selected, don't send a packet + if inventory.selected_hotbar_slot == event.slot { + continue; + } + + inventory.selected_hotbar_slot = event.slot; + send_packet_events.send(SendPacketEvent { + entity: event.entity, + packet: ServerboundSetCarriedItemPacket { + slot: event.slot as u16, + } + .get(), + }); + } +} -- cgit v1.2.3