pub struct RadiusGoal {
pub pos: Vec3,
pub radius: f32,
}Expand description
Get within the given radius of the given position.
Fields§
§pos: Vec3§radius: f32Implementations§
Source§impl RadiusGoal
impl RadiusGoal
Sourcepub fn new(pos: Vec3, radius: f32) -> Self
pub fn new(pos: Vec3, radius: f32) -> Self
Examples found in repository?
azalea/examples/steal.rs (line 69)
42async fn steal(bot: Client, state: State) -> eyre::Result<()> {
43 {
44 let mut is_stealing = state.is_stealing.lock();
45 if *is_stealing {
46 bot.chat("Already stealing");
47 return Ok(());
48 }
49 *is_stealing = true;
50 }
51
52 state.checked_chests.lock().clear();
53
54 loop {
55 let chest_block = bot
56 .world()?
57 .read()
58 .find_blocks(bot.position()?, &BlockKind::Chest.into())
59 .find(
60 // find the closest chest that hasn't been checked
61 |block_pos| !state.checked_chests.lock().contains(block_pos),
62 );
63 let Some(chest_block) = chest_block else {
64 break;
65 };
66
67 state.checked_chests.lock().push(chest_block);
68
69 bot.goto(RadiusGoal::new(chest_block.center(), 3.)).await;
70
71 let Some(chest) = bot.open_container_at(chest_block).await? else {
72 println!("Couldn't open chest at {chest_block:?}");
73 continue;
74 };
75
76 println!("Getting contents of chest at {chest_block:?}");
77 for (index, slot) in chest.contents().unwrap_or_default().iter().enumerate() {
78 println!("Checking slot {index}: {slot:?}");
79 let ItemStack::Present(item) = slot else {
80 continue;
81 };
82 if item.kind == ItemKind::Diamond {
83 println!("clicking slot ^");
84 chest.left_click(index);
85 }
86 }
87 }
88
89 bot.chat("Done");
90
91 *state.is_stealing.lock() = false;
92
93 Ok(())
94}More examples
azalea/examples/testbot/main.rs (line 201)
132async fn handle(bot: Client, event: azalea::Event, state: State) -> eyre::Result<()> {
133 let swarm = bot.resource::<SwarmState>();
134
135 match event {
136 azalea::Event::Init => {
137 bot.set_client_information(ClientInformation {
138 view_distance: 32,
139 ..Default::default()
140 })?;
141 if swarm.args.pathfinder_debug_particles {
142 bot.ecs
143 .write()
144 .entity_mut(bot.entity)
145 .insert(PathfinderDebugParticles);
146 }
147 }
148 azalea::Event::Chat(chat) => {
149 let (Some(username), content) = chat.split_sender_and_content() else {
150 return Ok(());
151 };
152 if username != swarm.args.owner_username {
153 return Ok(());
154 }
155
156 println!("{:?}", chat.message());
157
158 let command = if chat.is_whisper() {
159 Some(content)
160 } else {
161 content.strip_prefix('!').map(|s| s.to_owned())
162 };
163 if let Some(command) = command {
164 match swarm.commands.execute(
165 command,
166 Mutex::new(CommandSource {
167 bot: bot.clone(),
168 chat: chat.clone(),
169 state: state.clone(),
170 }),
171 ) {
172 Ok(Ok(_)) => {}
173 Ok(Err(err)) => {
174 eprintln!("azalea error: {err:?}");
175 let command_source = CommandSource {
176 bot,
177 chat: chat.clone(),
178 state: state.clone(),
179 };
180 command_source.reply(format!("azalea error: {err:?}"));
181 }
182 Err(err) => {
183 eprintln!("{err:?}");
184 let command_source = CommandSource {
185 bot,
186 chat: chat.clone(),
187 state: state.clone(),
188 };
189 command_source.reply(format!("{err:?}"));
190 }
191 }
192 }
193 }
194 azalea::Event::Tick => {
195 killaura::tick(bot.clone(), state.clone())?;
196
197 if bot.ticks_connected().is_multiple_of(5) {
198 if let Some(following) = &*state.following_entity.lock()
199 && following.is_alive()
200 {
201 let goal = RadiusGoal::new(following.position()?, 3.);
202 if bot.is_calculating_path() {
203 // keep waiting
204 } else if !goal.success(bot.position()?.into()) || bot.is_executing_path() {
205 bot.start_goto_with_opts(
206 goal,
207 PathfinderOpts::new()
208 .retry_on_no_path(false)
209 .max_timeout(Duration::from_secs(1)),
210 );
211 } else {
212 following.look_at()?;
213 }
214 }
215 }
216 }
217 azalea::Event::Login => {
218 println!("Got login event")
219 }
220 _ => {}
221 }
222
223 Ok(())
224}Trait Implementations§
Source§impl Clone for RadiusGoal
impl Clone for RadiusGoal
Source§fn clone(&self) -> RadiusGoal
fn clone(&self) -> RadiusGoal
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RadiusGoal
impl Debug for RadiusGoal
Source§impl Default for RadiusGoal
impl Default for RadiusGoal
Source§fn default() -> RadiusGoal
fn default() -> RadiusGoal
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for RadiusGoal
impl<'de> Deserialize<'de> for RadiusGoal
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Goal for RadiusGoal
impl Goal for RadiusGoal
Source§impl PartialEq for RadiusGoal
impl PartialEq for RadiusGoal
Source§fn eq(&self, other: &RadiusGoal) -> bool
fn eq(&self, other: &RadiusGoal) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for RadiusGoal
impl Serialize for RadiusGoal
impl Copy for RadiusGoal
impl StructuralPartialEq for RadiusGoal
Auto Trait Implementations§
impl Freeze for RadiusGoal
impl RefUnwindSafe for RadiusGoal
impl Send for RadiusGoal
impl Sync for RadiusGoal
impl Unpin for RadiusGoal
impl UnsafeUnpin for RadiusGoal
impl UnwindSafe for RadiusGoal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Converts this type into the system output type.
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
§impl<T> TypeData for T
impl<T> TypeData for T
§fn clone_type_data(&self) -> Box<dyn TypeData>
fn clone_type_data(&self) -> Box<dyn TypeData>
Creates a type-erased clone of this value.