mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
remove some debug stuff and fix recipe packet
This commit is contained in:
parent
99fcad7bc4
commit
4f00ddace0
8 changed files with 64 additions and 44 deletions
|
@ -1,6 +1,6 @@
|
|||
use super::{UnsizedByteArray, MAX_STRING_LENGTH};
|
||||
use byteorder::{ReadBytesExt, BE};
|
||||
use std::{backtrace::Backtrace, collections::HashMap, hash::Hash, io::Read};
|
||||
use std::{collections::HashMap, hash::Hash, io::Read};
|
||||
use thiserror::Error;
|
||||
use tokio::io::{AsyncRead, AsyncReadExt};
|
||||
|
||||
|
|
|
@ -568,7 +568,7 @@ impl Client {
|
|||
println!("Got remove entities packet {:?}", p);
|
||||
}
|
||||
ClientboundGamePacket::ClientboundPlayerChatPacket(p) => {
|
||||
println!("Got player chat packet {:?}", p);
|
||||
// println!("Got player chat packet {:?}", p);
|
||||
tx.send(Event::Chat(ChatPacket::Player(Box::new(p.clone()))))
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
@ -72,10 +72,6 @@ impl Cursor3d {
|
|||
end_y: i32,
|
||||
end_z: i32,
|
||||
) -> Self {
|
||||
println!(
|
||||
"making cursor3d with origin: {}, {}, {} and end: {}, {}, {}",
|
||||
origin_x, origin_y, origin_z, end_x, end_y, end_z
|
||||
);
|
||||
let width = (end_x - origin_x + 1)
|
||||
.try_into()
|
||||
.expect("Impossible width.");
|
||||
|
|
|
@ -302,7 +302,7 @@ const X_OFFSET: u64 = PACKED_Y_LENGTH + PACKED_Z_LENGTH;
|
|||
|
||||
impl McBufReadable for BlockPos {
|
||||
fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> {
|
||||
let val = u64::read_from(buf)?;
|
||||
let val = i64::read_from(buf)?;
|
||||
println!("reading blockpos from {}", val);
|
||||
let x = (val << (64 - X_OFFSET - PACKED_X_LENGTH) >> (64 - PACKED_X_LENGTH)) as i32;
|
||||
let y = (val << (64 - PACKED_Y_LENGTH) >> (64 - PACKED_Y_LENGTH)) as i32;
|
||||
|
@ -362,6 +362,8 @@ impl McBufWritable for ChunkSectionPos {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::io::Cursor;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
|
@ -399,4 +401,13 @@ mod tests {
|
|||
let chunk_pos = ChunkPos::from(&entity_pos);
|
||||
assert_eq!(chunk_pos, ChunkPos::new(1, -2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_blockpos_from() {
|
||||
let mut buf = Cursor::new(Vec::new());
|
||||
13743895338965u64.write_into(&mut buf).unwrap();
|
||||
buf.set_position(0);
|
||||
let block_pos = BlockPos::read_from(&mut buf).unwrap();
|
||||
assert_eq!(block_pos, BlockPos::new(49, -43, -3));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,6 @@ impl HasCollision for Dimension {
|
|||
// }
|
||||
fn collide(&self, movement: &Vec3, entity: &EntityData) -> Vec3 {
|
||||
let entity_bounding_box = entity.bounding_box;
|
||||
println!("collide: entity_bounding_box: {:?}", entity_bounding_box);
|
||||
// TODO: get_entity_collisions
|
||||
// let entity_collisions = dimension.get_entity_collisions(self, entity_bounding_box.expand_towards(movement));
|
||||
let entity_collisions = Vec::new();
|
||||
|
@ -107,14 +106,10 @@ impl MovableEntity for EntityMut<'_> {
|
|||
|
||||
// movement = this.maybeBackOffFromEdge(movement, moverType);
|
||||
|
||||
println!("move_entity {:?}", movement);
|
||||
|
||||
let collide_result = { self.dimension.collide(movement, self) };
|
||||
|
||||
let move_distance = collide_result.length_sqr();
|
||||
|
||||
println!("move_entity move_distance: {}", move_distance);
|
||||
|
||||
if move_distance > EPSILON {
|
||||
// TODO: fall damage
|
||||
|
||||
|
@ -128,8 +123,6 @@ impl MovableEntity for EntityMut<'_> {
|
|||
};
|
||||
|
||||
self.dimension.set_entity_pos(self.id, new_pos)?;
|
||||
|
||||
println!("move_entity set_entity_pos {:?}", new_pos)
|
||||
}
|
||||
|
||||
let x_collision = movement.x != collide_result.x;
|
||||
|
@ -139,11 +132,6 @@ impl MovableEntity for EntityMut<'_> {
|
|||
let on_ground = vertical_collision && movement.y < 0.;
|
||||
// self.on_ground = on_ground;
|
||||
|
||||
println!(
|
||||
"move_entity {} {} {}",
|
||||
x_collision, z_collision, vertical_collision
|
||||
);
|
||||
|
||||
// TODO: minecraft checks for a "minor" horizontal collision here
|
||||
|
||||
let _block_pos_below = self.on_pos_legacy();
|
||||
|
@ -152,7 +140,6 @@ impl MovableEntity for EntityMut<'_> {
|
|||
// .get_block_state(&block_pos_below)
|
||||
// .expect("Couldn't get block state below");
|
||||
|
||||
println!("move_entity 4");
|
||||
// self.check_fall_damage(collide_result.y, on_ground, block_state_below, block_pos_below);
|
||||
|
||||
// if self.isRemoved() { return; }
|
||||
|
@ -196,8 +183,6 @@ impl MovableEntity for EntityMut<'_> {
|
|||
// this.setRemainingFireTicks(-this.getFireImmuneTicks());
|
||||
// }
|
||||
|
||||
println!("move_entity 5");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,12 +47,6 @@ pub trait VoxelShape {
|
|||
return empty_shape();
|
||||
}
|
||||
|
||||
println!(
|
||||
"making new voxel shape {:?} {:?} {:?}",
|
||||
self.get_coords(Axis::X),
|
||||
self.get_coords(Axis::Y),
|
||||
self.get_coords(Axis::Z)
|
||||
);
|
||||
|
||||
Box::new(ArrayVoxelShape::new(
|
||||
self.shape(),
|
||||
|
@ -68,12 +62,6 @@ pub trait VoxelShape {
|
|||
|
||||
fn find_index(&self, axis: Axis, coord: f64) -> i32 {
|
||||
let r = binary_search(0, (self.shape().size(axis) + 1) as i32, &|t| {
|
||||
println!(
|
||||
"checking {} ({}) against {}",
|
||||
t,
|
||||
self.get(axis, t as usize),
|
||||
coord
|
||||
);
|
||||
coord < self.get(axis, t as usize)
|
||||
}) - 1;
|
||||
r
|
||||
|
@ -123,7 +111,6 @@ pub trait VoxelShape {
|
|||
);
|
||||
|
||||
let var19 = self.shape().size(x_axis);
|
||||
println!("movement: {}", movement);
|
||||
if movement > 0. {
|
||||
for var20 in var14 + 1..(var19 as i32) {
|
||||
for var21 in var15..var16 {
|
||||
|
@ -144,7 +131,6 @@ pub trait VoxelShape {
|
|||
}
|
||||
}
|
||||
} else if movement < 0. {
|
||||
println!("hmmm var13={}", var13);
|
||||
if var13 > 0 {
|
||||
for var20 in (var13 - 1)..=0 {
|
||||
for var21 in var15..var16 {
|
||||
|
|
|
@ -1,13 +1,56 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_buf::{
|
||||
BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable,
|
||||
};
|
||||
use azalea_core::ResourceLocation;
|
||||
use packet_macros::ClientboundGamePacket;
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
|
||||
#[derive(Clone, Debug, ClientboundGamePacket)]
|
||||
pub struct ClientboundRecipePacket {
|
||||
pub action: State,
|
||||
pub settings: RecipeBookSettings,
|
||||
pub recipes: Vec<ResourceLocation>,
|
||||
pub to_highlight: Vec<ResourceLocation>,
|
||||
}
|
||||
|
||||
impl McBufWritable for ClientboundRecipePacket {
|
||||
fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
match self.action {
|
||||
State::Init { .. } => 0,
|
||||
State::Add => 1,
|
||||
State::Remove => 2,
|
||||
}
|
||||
.var_write_into(buf)?;
|
||||
self.settings.write_into(buf)?;
|
||||
self.recipes.write_into(buf)?;
|
||||
if let State::Init { to_highlight } = &self.action {
|
||||
to_highlight.write_into(buf)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl McBufReadable for ClientboundRecipePacket {
|
||||
fn read_from(buf: &mut impl std::io::Read) -> Result<Self, azalea_buf::BufReadError> {
|
||||
let action_id = u32::var_read_from(buf)?;
|
||||
let settings = RecipeBookSettings::read_from(buf)?;
|
||||
let recipes = Vec::<ResourceLocation>::read_from(buf)?;
|
||||
let action = match action_id {
|
||||
0 => State::Init {
|
||||
to_highlight: Vec::<ResourceLocation>::read_from(buf)?,
|
||||
},
|
||||
1 => State::Add,
|
||||
2 => State::Remove,
|
||||
_ => {
|
||||
return Err(BufReadError::UnexpectedEnumVariant {
|
||||
id: action_id as i32,
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
Ok(ClientboundRecipePacket {
|
||||
action: action,
|
||||
settings: settings,
|
||||
recipes: recipes,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, McBuf)]
|
||||
|
@ -25,9 +68,9 @@ pub struct RecipeBookSettings {
|
|||
pub smoker_filtering_craftable: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Copy, McBuf)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum State {
|
||||
Init = 0,
|
||||
Add = 1,
|
||||
Remove = 2,
|
||||
Init { to_highlight: Vec<ResourceLocation> },
|
||||
Add,
|
||||
Remove,
|
||||
}
|
||||
|
|
|
@ -70,7 +70,6 @@ impl Dimension {
|
|||
}
|
||||
|
||||
pub fn set_entity_pos(&mut self, entity_id: u32, new_pos: Vec3) -> Result<(), MoveEntityError> {
|
||||
println!("set_entity_pos({}, {:?})", entity_id, new_pos);
|
||||
let mut entity = self
|
||||
.entity_mut(entity_id)
|
||||
.ok_or(MoveEntityError::EntityDoesNotExist)?;
|
||||
|
|
Loading…
Add table
Reference in a new issue