aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-09-04 23:01:15 -0500
committermat <github@matdoes.dev>2022-09-04 23:01:15 -0500
commit4f00ddace08bd5ad17500a405f55554dff343be7 (patch)
tree8a8503fe4b9d0055b73952d2fb7f38941000f9d0
parent99fcad7bc4133c32627fe2e4751faad05b9b4ef1 (diff)
downloadazalea-drasl-4f00ddace08bd5ad17500a405f55554dff343be7.tar.xz
remove some debug stuff and fix recipe packet
-rw-r--r--azalea-buf/src/read.rs2
-rw-r--r--azalea-client/src/client.rs2
-rw-r--r--azalea-core/src/cursor3d.rs4
-rw-r--r--azalea-core/src/position.rs13
-rw-r--r--azalea-physics/src/collision/mod.rs15
-rw-r--r--azalea-physics/src/collision/shape.rs14
-rw-r--r--azalea-protocol/src/packets/game/clientbound_recipe_packet.rs57
-rw-r--r--azalea-world/src/lib.rs1
8 files changed, 64 insertions, 44 deletions
diff --git a/azalea-buf/src/read.rs b/azalea-buf/src/read.rs
index 4fea4b73..9ed416b9 100644
--- a/azalea-buf/src/read.rs
+++ b/azalea-buf/src/read.rs
@@ -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};
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index eae0a1b6..1e05ca9e 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -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();
}
diff --git a/azalea-core/src/cursor3d.rs b/azalea-core/src/cursor3d.rs
index fa265c8a..180301e3 100644
--- a/azalea-core/src/cursor3d.rs
+++ b/azalea-core/src/cursor3d.rs
@@ -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.");
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index 7451bc14..8c71676c 100644
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -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));
+ }
}
diff --git a/azalea-physics/src/collision/mod.rs b/azalea-physics/src/collision/mod.rs
index 794f707b..1f9064b3 100644
--- a/azalea-physics/src/collision/mod.rs
+++ b/azalea-physics/src/collision/mod.rs
@@ -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(())
}
}
diff --git a/azalea-physics/src/collision/shape.rs b/azalea-physics/src/collision/shape.rs
index c8428a08..d229a25d 100644
--- a/azalea-physics/src/collision/shape.rs
+++ b/azalea-physics/src/collision/shape.rs
@@ -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 {
diff --git a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs
index 29ad5800..dd7a162c 100644
--- a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs
@@ -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,
}
diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs
index 2d65ebc8..4f51d655 100644
--- a/azalea-world/src/lib.rs
+++ b/azalea-world/src/lib.rs
@@ -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)?;