fix ping packet, explosion packet, and panic less

This commit is contained in:
mat 2024-01-08 00:12:54 -06:00
parent 0aa439d5ca
commit cfbfdd77b4
5 changed files with 27 additions and 13 deletions

View file

@ -74,9 +74,9 @@ fn travel(
jumping,
) in &mut query
{
let world_lock = instance_container
.get(world_name)
.expect("All entities should be in a valid world");
let Some(world_lock) = instance_container.get(world_name) else {
continue;
};
let world = world_lock.read();
// if !self.is_effective_ai() && !self.is_controlled_by_local_instance() {
// // this.calculateEntityAnimation(this, this instanceof FlyingAnimal);

View file

@ -1,9 +1,12 @@
use std::io::{Cursor, Write};
use std::{
io::{Cursor, Write},
str::FromStr,
};
use azalea_buf::{
BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable,
};
use azalea_core::position::BlockPos;
use azalea_core::{position::BlockPos, resource_location::ResourceLocation};
use azalea_protocol_macros::ClientboundGamePacket;
use azalea_registry::{ParticleKind, SoundEvent};
@ -59,7 +62,14 @@ impl McBufReadable for ClientboundExplodePacket {
let block_interaction = BlockInteraction::read_from(buf)?;
let small_explosion_particles = ParticleKind::read_from(buf)?;
let large_explosion_particles = ParticleKind::read_from(buf)?;
let explosion_sound = SoundEvent::read_from(buf)?;
let sound_event_resource_location = ResourceLocation::read_from(buf)?.to_string();
let explosion_sound =
SoundEvent::from_str(&sound_event_resource_location).map_err(|_| {
BufReadError::UnexpectedStringEnumVariant {
id: sound_event_resource_location,
}
})?;
Ok(Self {
x,
@ -108,7 +118,10 @@ impl McBufWritable for ClientboundExplodePacket {
self.block_interaction.write_into(buf)?;
self.small_explosion_particles.write_into(buf)?;
self.large_explosion_particles.write_into(buf)?;
self.explosion_sound.write_into(buf)?;
let sound_event_resource_location =
ResourceLocation::new(&self.explosion_sound.to_string());
sound_event_resource_location.write_into(buf)?;
Ok(())
}

View file

@ -3,6 +3,5 @@ use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
pub struct ClientboundPingPacket {
#[var]
pub id: u32,
}

View file

@ -5,7 +5,7 @@
//! - Run `cargo r --example testbot`
//! - Commands are prefixed with `!` in chat. You can send them either in public
//! chat or as a /msg.
//! - Some commands to try are `!goto`, `!killaura`, `!down`. Check the
//! - Some commands to try are `!goto`, `!killaura true`, `!down`. Check the
//! `commands` directory to see all of them.
#![feature(async_closure)]
@ -31,7 +31,7 @@ const ADDRESS: &str = "localhost";
/// Whether the bot should run /particle a ton of times to show where it's
/// pathfinding to. You should only have this on if the bot has operator
/// permissions, otherwise it'll just spam the server console unnecessarily.
const PATHFINDER_DEBUG_PARTICLES: bool = true;
const PATHFINDER_DEBUG_PARTICLES: bool = false;
#[tokio::main]
async fn main() {

View file

@ -208,9 +208,11 @@ fn goto_listener(
let thread_pool = AsyncComputeTaskPool::get();
for event in events.read() {
let (mut pathfinder, executing_path, position, instance_name, inventory) = query
.get_mut(event.entity)
.expect("Called goto on an entity that's not in the world");
let Ok((mut pathfinder, executing_path, position, instance_name, inventory)) =
query.get_mut(event.entity)
else {
continue;
};
if event.goal.success(BlockPos::from(position)) {
// we're already at the goal, nothing to do