diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-12-15 11:26:40 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-15 11:26:40 -0600 |
| commit | a707e2eb82b74994a16083b31fa4576332cf1995 (patch) | |
| tree | db6c2ac94dd73590befd68a9b1b0ef960410b0df /azalea-client/src | |
| parent | 59e140ddd655c7dc6e35109b91286118c51bcc06 (diff) | |
| download | azalea-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')
| -rw-r--r-- | azalea-client/src/interact.rs | 6 | ||||
| -rw-r--r-- | azalea-client/src/inventory.rs | 33 | ||||
| -rw-r--r-- | azalea-client/src/mining.rs | 15 |
3 files changed, 50 insertions, 4 deletions
diff --git a/azalea-client/src/interact.rs b/azalea-client/src/interact.rs index c8332d20..026e94ca 100644 --- a/azalea-client/src/interact.rs +++ b/azalea-client/src/interact.rs @@ -193,7 +193,7 @@ pub fn update_hit_result_component( }; let instance = instance_lock.read(); - let hit_result = pick(look_direction, &eye_position, &instance, pick_range); + let hit_result = pick(look_direction, &eye_position, &instance.chunks, pick_range); if let Some(mut hit_result_ref) = hit_result_ref { **hit_result_ref = hit_result; } else { @@ -212,13 +212,13 @@ pub fn update_hit_result_component( pub fn pick( look_direction: &LookDirection, eye_position: &Vec3, - instance: &Instance, + chunks: &azalea_world::ChunkStorage, pick_range: f64, ) -> BlockHitResult { let view_vector = view_vector(look_direction); let end_position = eye_position + &(view_vector * pick_range); azalea_physics::clip::clip( - &instance.chunks, + chunks, ClipContext { from: *eye_position, to: end_position, 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(), + }); + } +} diff --git a/azalea-client/src/mining.rs b/azalea-client/src/mining.rs index d1bc169e..d2e66ca8 100644 --- a/azalea-client/src/mining.rs +++ b/azalea-client/src/mining.rs @@ -200,7 +200,20 @@ fn handle_start_mining_block_with_direction_event( .get_block_state(&event.position) .unwrap_or_default(); *sequence_number += 1; - let block_is_solid = !target_block_state.is_air(); + let target_registry_block = azalea_registry::Block::from(target_block_state); + + // we can't break blocks if they don't have a bounding box + + // TODO: So right now azalea doesn't differenciate between different types of + // bounding boxes. See ClipContext::block_shape for more info. Ideally this + // should just call ClipContext::block_shape and check if it's empty. + let block_is_solid = !target_block_state.is_air() + // this is a hack to make sure we can't break water or lava + && !matches!( + target_registry_block, + azalea_registry::Block::Water | azalea_registry::Block::Lava + ); + if block_is_solid && **mine_progress == 0. { // interact with the block (like note block left click) here attack_block_events.send(AttackBlockEvent { |
