aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/inventory.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2023-12-15 11:26:40 -0600
committerGitHub <noreply@github.com>2023-12-15 11:26:40 -0600
commita707e2eb82b74994a16083b31fa4576332cf1995 (patch)
treedb6c2ac94dd73590befd68a9b1b0ef960410b0df /azalea-client/src/inventory.rs
parent59e140ddd655c7dc6e35109b91286118c51bcc06 (diff)
downloadazalea-drasl-a707e2eb82b74994a16083b31fa4576332cf1995.tar.xz
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
Diffstat (limited to 'azalea-client/src/inventory.rs')
-rw-r--r--azalea-client/src/inventory.rs33
1 files changed, 33 insertions, 0 deletions
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::<CloseContainerEvent>()
.add_event::<ContainerClickEvent>()
.add_event::<SetContainerContentEvent>()
+ .add_event::<SetSelectedHotbarSlotEvent>()
.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<SetSelectedHotbarSlotEvent>,
+ mut send_packet_events: EventWriter<SendPacketEvent>,
+ 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(),
+ });
+ }
+}