Skip to content

Commit

Permalink
0.6.2 - Idle Position
Browse files Browse the repository at this point in the history
  • Loading branch information
ShayBox committed Nov 8, 2024
1 parent b83d12b commit eb06210
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 40 deletions.
88 changes: 54 additions & 34 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shaysbot"
version = "0.6.1"
version = "0.6.2"
authors = ["Shayne Hartford <shaybox@shaybox.com>"]
edition = "2021"
description = "My personal Minecraft bot using Azalea"
Expand Down
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,16 @@ pub struct SwarmState;
/// Will return `Err` if `ClientBuilder::start` fails.
#[allow(clippy::future_not_send)]
pub async fn start() -> anyhow::Result<()> {
let settings = Settings::load().unwrap_or_default();
let trapdoors = Trapdoors::load().unwrap_or_default();
let settings = Settings::load().unwrap_or_else(|error| {
eprintln!("Error loading settings: {error}");
Settings::default()
});

let trapdoors = Trapdoors::load().unwrap_or_else(|error| {
eprintln!("Error loading trapdoors: {error}");
Trapdoors::default()
});

let address = settings.server_address.clone();
let token = settings.discord_token.clone();
let account = if settings.online_mode {
Expand Down
31 changes: 28 additions & 3 deletions src/plugins/auto_pearl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use azalea::{
};
use uuid::Uuid;

use crate::Settings;

/// Automatically pull stasis chamber pearls
pub struct AutoPearlPlugin;

Expand Down Expand Up @@ -105,13 +107,15 @@ pub struct PearlPullEvent {
}

pub fn handle_pearl_pull_event(
mut pearl_pull_events: EventReader<PearlPullEvent>,
mut goto_events: EventWriter<GotoEvent>,
mut pearl_pending_events: ResMut<PendingPearlEvents>,
mut pearl_pull_events: EventReader<PearlPullEvent>,
mut send_packet_events: EventWriter<SendPacketEvent>,
mut query: Query<(&Pathfinder, &TabList)>,
mut query: Query<(&Pathfinder, &TabList, &InstanceHolder)>,
settings: Res<Settings>,
) {
for event in pearl_pull_events.read() {
let Ok((pathfinder, tab_list)) = query.get_mut(event.entity) else {
let Ok((pathfinder, tab_list, holder)) = query.get_mut(event.entity) else {
continue;
};

Expand All @@ -125,6 +129,7 @@ pub fn handle_pearl_pull_event(
continue;
}

// Flip the trapdoor
let packet = ServerboundGamePacket::UseItemOn(ServerboundUseItemOnPacket {
hand: InteractionHand::MainHand,
block_hit: BlockHit {
Expand All @@ -144,6 +149,26 @@ pub fn handle_pearl_pull_event(
entity: event.entity,
packet,
});

// Return to the idle position
#[allow(clippy::cast_possible_truncation)]
let pos = BlockPos {
x: settings.idle_pos.x as i32,
y: settings.idle_pos.y as i32,
z: settings.idle_pos.z as i32,
};

let goal = ReachBlockPosGoal {
chunk_storage: holder.instance.read().chunks.clone(),
pos,
};

goto_events.send(GotoEvent {
entity: event.entity,
goal: Arc::new(goal),
successors_fn: default_move,
allow_mining: false,
});
}
}

Expand Down
Loading

0 comments on commit eb06210

Please sign in to comment.