aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/common
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2024-12-19 02:31:08 +0000
committermat <git@matdoes.dev>2024-12-19 02:52:41 +0000
commite268c4929177e540baa9d2bb29bc171f49cc7a25 (patch)
tree10146e529088ab823452a5971c0a37a8886b2a68 /azalea-protocol/src/common
parent1f06a1540f46d8087907566d7c6c1ab397c517ec (diff)
downloadazalea-drasl-e268c4929177e540baa9d2bb29bc171f49cc7a25.tar.xz
fix incorrect packets
Diffstat (limited to 'azalea-protocol/src/common')
-rw-r--r--azalea-protocol/src/common/mod.rs2
-rw-r--r--azalea-protocol/src/common/movements.rs71
-rw-r--r--azalea-protocol/src/common/recipe.rs101
3 files changed, 174 insertions, 0 deletions
diff --git a/azalea-protocol/src/common/mod.rs b/azalea-protocol/src/common/mod.rs
index da535b48..9258e538 100644
--- a/azalea-protocol/src/common/mod.rs
+++ b/azalea-protocol/src/common/mod.rs
@@ -1,4 +1,6 @@
//! Some serializable data types that are used by several packets.
pub mod client_information;
+pub mod movements;
+pub mod recipe;
pub mod server_links;
diff --git a/azalea-protocol/src/common/movements.rs b/azalea-protocol/src/common/movements.rs
new file mode 100644
index 00000000..7672703f
--- /dev/null
+++ b/azalea-protocol/src/common/movements.rs
@@ -0,0 +1,71 @@
+use std::io::{self, Cursor, Write};
+
+use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError};
+use azalea_core::{bitset::FixedBitSet, position::Vec3};
+use azalea_entity::LookDirection;
+
+/// The updated position, velocity, and rotations for an entity.
+///
+/// Often, this field comes alongside a [`RelativeMovements`] field, which
+/// specifies which parts of this struct should be treated as relative.
+#[derive(AzBuf, Clone, Debug)]
+pub struct PositionMoveRotation {
+ pub pos: Vec3,
+ /// The updated delta movement (velocity).
+ pub delta: Vec3,
+ pub look_direction: LookDirection,
+}
+
+#[derive(Debug, Clone)]
+pub struct RelativeMovements {
+ pub x: bool,
+ pub y: bool,
+ pub z: bool,
+ pub y_rot: bool,
+ pub x_rot: bool,
+ pub delta_x: bool,
+ pub delta_y: bool,
+ pub delta_z: bool,
+ pub rotate_delta: bool,
+}
+
+impl AzaleaRead for RelativeMovements {
+ fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
+ // yes minecraft seriously wastes that many bits, smh
+ let set = FixedBitSet::<{ 32_usize.div_ceil(8) }>::azalea_read(buf)?;
+ Ok(RelativeMovements {
+ x: set.index(0),
+ y: set.index(1),
+ z: set.index(2),
+ y_rot: set.index(3),
+ x_rot: set.index(4),
+ delta_x: set.index(5),
+ delta_y: set.index(6),
+ delta_z: set.index(7),
+ rotate_delta: set.index(8),
+ })
+ }
+}
+
+impl AzaleaWrite for RelativeMovements {
+ fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
+ let mut set = FixedBitSet::<{ 32_usize.div_ceil(8) }>::new();
+ let mut set_bit = |index: usize, value: bool| {
+ if value {
+ set.set(index);
+ }
+ };
+
+ set_bit(0, self.x);
+ set_bit(1, self.y);
+ set_bit(2, self.z);
+ set_bit(3, self.y_rot);
+ set_bit(4, self.x_rot);
+ set_bit(5, self.delta_x);
+ set_bit(6, self.delta_y);
+ set_bit(7, self.delta_z);
+ set_bit(8, self.rotate_delta);
+
+ set.azalea_write(buf)
+ }
+}
diff --git a/azalea-protocol/src/common/recipe.rs b/azalea-protocol/src/common/recipe.rs
new file mode 100644
index 00000000..15d40cca
--- /dev/null
+++ b/azalea-protocol/src/common/recipe.rs
@@ -0,0 +1,101 @@
+use azalea_buf::AzBuf;
+use azalea_core::resource_location::ResourceLocation;
+use azalea_inventory::ItemStack;
+use azalea_registry::HolderSet;
+
+/// [`azalea_registry::RecipeDisplay`]
+#[derive(Clone, Debug, AzBuf)]
+pub enum RecipeDisplayData {
+ Shapeless(ShapelessCraftingRecipeDisplay),
+ Shaped(ShapedCraftingRecipeDisplay),
+ Furnace(FurnaceRecipeDisplay),
+ Stonecutter(StonecutterRecipeDisplay),
+ Smithing(SmithingRecipeDisplay),
+}
+
+#[derive(Clone, Debug, AzBuf)]
+pub struct ShapelessCraftingRecipeDisplay {
+ pub ingredients: Vec<SlotDisplayData>,
+ pub result: SlotDisplayData,
+ pub crafting_station: SlotDisplayData,
+}
+#[derive(Clone, Debug, AzBuf)]
+pub struct ShapedCraftingRecipeDisplay {
+ #[var]
+ pub width: u32,
+ #[var]
+ pub height: u32,
+ pub ingredients: Vec<SlotDisplayData>,
+ pub result: SlotDisplayData,
+ pub crafting_station: SlotDisplayData,
+}
+#[derive(Clone, Debug, AzBuf)]
+pub struct FurnaceRecipeDisplay {
+ pub ingredient: SlotDisplayData,
+ pub fuel: SlotDisplayData,
+ pub result: SlotDisplayData,
+ pub crafting_station: SlotDisplayData,
+ #[var]
+ pub duration: u32,
+ pub experience: f32,
+}
+#[derive(Clone, Debug, AzBuf)]
+pub struct StonecutterRecipeDisplay {
+ pub input: SlotDisplayData,
+ pub result: SlotDisplayData,
+ pub crafting_station: SlotDisplayData,
+}
+#[derive(Clone, Debug, AzBuf)]
+pub struct SmithingRecipeDisplay {
+ pub template: SlotDisplayData,
+ pub base: SlotDisplayData,
+ pub addition: SlotDisplayData,
+ pub result: SlotDisplayData,
+ pub crafting_station: SlotDisplayData,
+}
+
+#[derive(Clone, Debug, PartialEq, AzBuf)]
+pub struct Ingredient {
+ pub allowed: HolderSet<azalea_registry::Item, ResourceLocation>,
+}
+
+/// [`azalea_registry::SlotDisplay`]
+#[derive(Clone, Debug, PartialEq, AzBuf)]
+pub enum SlotDisplayData {
+ Empty,
+ AnyFuel,
+ Item(ItemStackDisplay),
+ ItemStack(ItemStackSlotDisplay),
+ Tag(ResourceLocation),
+ SmithingTrim(Box<SmithingTrimDemoSlotDisplay>),
+ WithRemainder(Box<WithRemainderSlotDisplay>),
+ Composite(CompositeSlotDisplay),
+}
+
+#[derive(Clone, Debug, PartialEq, AzBuf)]
+pub struct ItemStackDisplay {
+ pub item: azalea_registry::Item,
+}
+#[derive(Clone, Debug, PartialEq, AzBuf)]
+pub struct ItemStackSlotDisplay {
+ pub stack: ItemStack,
+}
+#[derive(Clone, Debug, PartialEq, AzBuf)]
+pub struct TagSlotDisplay {
+ pub tag: azalea_registry::Item,
+}
+#[derive(Clone, Debug, PartialEq, AzBuf)]
+pub struct SmithingTrimDemoSlotDisplay {
+ pub base: SlotDisplayData,
+ pub material: SlotDisplayData,
+ pub pattern: SlotDisplayData,
+}
+#[derive(Clone, Debug, PartialEq, AzBuf)]
+pub struct WithRemainderSlotDisplay {
+ pub input: SlotDisplayData,
+ pub remainder: SlotDisplayData,
+}
+#[derive(Clone, Debug, PartialEq, AzBuf)]
+pub struct CompositeSlotDisplay {
+ pub contents: Vec<SlotDisplayData>,
+}