aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2023-05-03 20:57:27 -0500
committerGitHub <noreply@github.com>2023-05-03 20:57:27 -0500
commit634cb8d72c6608512aedba19e5cd669104bc35ea (patch)
treef8e76ce9eb43403d29cc0cbcf9a4f51522419dc2 /azalea-protocol/src/packets
parent1fb4418f2c9cbd004c64c2f23d2d0352ee12c0e5 (diff)
downloadazalea-drasl-634cb8d72c6608512aedba19e5cd669104bc35ea.tar.xz
Inventory (#48)
* start adding azalea-inventory * design more of how inventories are defined * start working on az-inv-macros * inventory macro works * start adding inventory codegen * update some deps * add inventory codegen * manually write inventory menus * put the inventories in Client * start on containersetcontent * inventory menu should hopefully work * checks in containersetcontent * format a comment * move some variant matches * inventory.rs * inventory stuff * more inventory stuff * inventory/container tracking works * start adding interact function * sequence number * start adding HitResultComponent * implement traverse_blocks * start adding clip * add clip function * update_hit_result_component * start trying to fix * fix * make some stuff simpler * clippy * lever * chest * container handle * fix ambiguity * fix some doc tests * move some container stuff from az-client to azalea * clicking container * start implementing simulate_click * keep working on simulate click * implement more of simulate_click this is really boring * inventory fixes * start implementing shift clicking * fix panic in azalea-chat i hope * shift clicking implemented * more inventory stuff * fix items not showing in containers sometimes * fix test * fix all warnings * remove a println --------- Co-authored-by: mat <git@matdoes.dev>
Diffstat (limited to 'azalea-protocol/src/packets')
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs8
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_container_set_data_packet.rs2
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_container_set_slot_packet.rs6
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_login_packet.rs4
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_merchant_offers_packet.rs8
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_open_screen_packet.rs2
-rw-r--r--azalea-protocol/src/packets/game/clientbound_player_info_update_packet.rs6
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_respawn_packet.rs4
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs6
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs7
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs19
-rwxr-xr-xazalea-protocol/src/packets/game/serverbound_container_click_packet.rs19
-rwxr-xr-xazalea-protocol/src/packets/game/serverbound_set_creative_mode_slot_packet.rs4
-rwxr-xr-xazalea-protocol/src/packets/game/serverbound_use_item_on_packet.rs14
14 files changed, 53 insertions, 56 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs b/azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs
index 0e9ce32b..4e08232d 100755
--- a/azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs
@@ -1,12 +1,12 @@
use azalea_buf::McBuf;
-use azalea_core::Slot;
+use azalea_inventory::ItemSlot;
use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
pub struct ClientboundContainerSetContentPacket {
- pub container_id: u8,
+ pub container_id: i8,
#[var]
pub state_id: u32,
- pub items: Vec<Slot>,
- pub carried_item: Slot,
+ pub items: Vec<ItemSlot>,
+ pub carried_item: ItemSlot,
}
diff --git a/azalea-protocol/src/packets/game/clientbound_container_set_data_packet.rs b/azalea-protocol/src/packets/game/clientbound_container_set_data_packet.rs
index e09c16d7..dc53a024 100755
--- a/azalea-protocol/src/packets/game/clientbound_container_set_data_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_container_set_data_packet.rs
@@ -3,7 +3,7 @@ use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
pub struct ClientboundContainerSetDataPacket {
- pub container_id: u8,
+ pub container_id: i8,
pub id: u16,
pub value: u16,
}
diff --git a/azalea-protocol/src/packets/game/clientbound_container_set_slot_packet.rs b/azalea-protocol/src/packets/game/clientbound_container_set_slot_packet.rs
index 0ed249a9..9b954fa0 100755
--- a/azalea-protocol/src/packets/game/clientbound_container_set_slot_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_container_set_slot_packet.rs
@@ -1,12 +1,12 @@
use azalea_buf::McBuf;
-use azalea_core::Slot;
+use azalea_inventory::ItemSlot;
use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
pub struct ClientboundContainerSetSlotPacket {
- pub container_id: u8,
+ pub container_id: i8,
#[var]
pub state_id: u32,
pub slot: u16,
- pub item_stack: Slot,
+ pub item_stack: ItemSlot,
}
diff --git a/azalea-protocol/src/packets/game/clientbound_login_packet.rs b/azalea-protocol/src/packets/game/clientbound_login_packet.rs
index a35951a7..bafead86 100755
--- a/azalea-protocol/src/packets/game/clientbound_login_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_login_packet.rs
@@ -1,6 +1,6 @@
use self::registry::RegistryHolder;
use azalea_buf::McBuf;
-use azalea_core::{GameType, GlobalPos, OptionalGameType, ResourceLocation};
+use azalea_core::{GameMode, GlobalPos, OptionalGameType, ResourceLocation};
use azalea_protocol_macros::ClientboundGamePacket;
/// The first packet sent by the server to the client after login.
@@ -11,7 +11,7 @@ use azalea_protocol_macros::ClientboundGamePacket;
pub struct ClientboundLoginPacket {
pub player_id: u32,
pub hardcore: bool,
- pub game_type: GameType,
+ pub game_type: GameMode,
pub previous_game_type: OptionalGameType,
pub levels: Vec<ResourceLocation>,
pub registry_holder: RegistryHolder,
diff --git a/azalea-protocol/src/packets/game/clientbound_merchant_offers_packet.rs b/azalea-protocol/src/packets/game/clientbound_merchant_offers_packet.rs
index 21ac8b2e..4253ace4 100755
--- a/azalea-protocol/src/packets/game/clientbound_merchant_offers_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_merchant_offers_packet.rs
@@ -1,5 +1,5 @@
use azalea_buf::McBuf;
-use azalea_core::Slot;
+use azalea_inventory::ItemSlot;
use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
@@ -17,9 +17,9 @@ pub struct ClientboundMerchantOffersPacket {
#[derive(Clone, Debug, McBuf)]
pub struct MerchantOffer {
- pub base_cost_a: Slot,
- pub result: Slot,
- pub cost_b: Slot,
+ pub base_cost_a: ItemSlot,
+ pub result: ItemSlot,
+ pub cost_b: ItemSlot,
pub out_of_stock: bool,
pub uses: u32,
pub max_uses: u32,
diff --git a/azalea-protocol/src/packets/game/clientbound_open_screen_packet.rs b/azalea-protocol/src/packets/game/clientbound_open_screen_packet.rs
index 9b8b02a1..582cac17 100755
--- a/azalea-protocol/src/packets/game/clientbound_open_screen_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_open_screen_packet.rs
@@ -6,6 +6,6 @@ use azalea_protocol_macros::ClientboundGamePacket;
pub struct ClientboundOpenScreenPacket {
#[var]
pub container_id: u32,
- pub menu_type: azalea_registry::Menu,
+ pub menu_type: azalea_registry::MenuKind,
pub title: FormattedText,
}
diff --git a/azalea-protocol/src/packets/game/clientbound_player_info_update_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_info_update_packet.rs
index dc518c9c..1dad147f 100644
--- a/azalea-protocol/src/packets/game/clientbound_player_info_update_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_player_info_update_packet.rs
@@ -3,7 +3,7 @@ use azalea_buf::{
BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable,
};
use azalea_chat::FormattedText;
-use azalea_core::{FixedBitSet, GameType};
+use azalea_core::{FixedBitSet, GameMode};
use azalea_protocol_macros::ClientboundGamePacket;
use std::{
collections::HashMap,
@@ -24,7 +24,7 @@ pub struct PlayerInfoEntry {
pub profile: GameProfile,
pub listed: bool,
pub latency: i32,
- pub game_mode: GameType,
+ pub game_mode: GameMode,
pub display_name: Option<FormattedText>,
pub chat_session: Option<RemoteChatSessionData>,
}
@@ -40,7 +40,7 @@ pub struct InitializeChatAction {
}
#[derive(Clone, Debug, McBuf)]
pub struct UpdateGameModeAction {
- pub game_mode: GameType,
+ pub game_mode: GameMode,
}
#[derive(Clone, Debug, McBuf)]
pub struct UpdateListedAction {
diff --git a/azalea-protocol/src/packets/game/clientbound_respawn_packet.rs b/azalea-protocol/src/packets/game/clientbound_respawn_packet.rs
index 58488124..03cc2917 100755
--- a/azalea-protocol/src/packets/game/clientbound_respawn_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_respawn_packet.rs
@@ -1,5 +1,5 @@
use azalea_buf::McBuf;
-use azalea_core::{GameType, GlobalPos, OptionalGameType, ResourceLocation};
+use azalea_core::{GameMode, GlobalPos, OptionalGameType, ResourceLocation};
use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
@@ -7,7 +7,7 @@ pub struct ClientboundRespawnPacket {
pub dimension_type: ResourceLocation,
pub dimension: ResourceLocation,
pub seed: u64,
- pub player_game_type: GameType,
+ pub player_game_type: GameMode,
pub previous_player_game_type: OptionalGameType,
pub is_debug: bool,
pub is_flat: bool,
diff --git a/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs
index 11472591..0acdc687 100755
--- a/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs
@@ -1,6 +1,6 @@
use azalea_buf::{BufReadError, McBuf};
use azalea_buf::{McBufReadable, McBufWritable};
-use azalea_core::Slot;
+use azalea_inventory::ItemSlot;
use azalea_protocol_macros::ClientboundGamePacket;
use std::io::Cursor;
@@ -13,7 +13,7 @@ pub struct ClientboundSetEquipmentPacket {
#[derive(Clone, Debug)]
pub struct EquipmentSlots {
- pub slots: Vec<(EquipmentSlot, Slot)>,
+ pub slots: Vec<(EquipmentSlot, ItemSlot)>,
}
impl McBufReadable for EquipmentSlots {
@@ -28,7 +28,7 @@ impl McBufReadable for EquipmentSlots {
id: equipment_byte.into(),
}
})?;
- let item = Slot::read_from(buf)?;
+ let item = ItemSlot::read_from(buf)?;
slots.push((equipment_slot, item));
if equipment_byte & 128 == 0 {
break;
diff --git a/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs
index dcc6332a..76f1412c 100755
--- a/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs
@@ -1,6 +1,7 @@
use azalea_buf::McBuf;
use azalea_chat::FormattedText;
-use azalea_core::{ResourceLocation, Slot};
+use azalea_core::ResourceLocation;
+use azalea_inventory::ItemSlot;
use azalea_protocol_macros::ClientboundGamePacket;
use std::collections::HashMap;
use std::io::Cursor;
@@ -25,7 +26,7 @@ pub struct Advancement {
pub struct DisplayInfo {
pub title: FormattedText,
pub description: FormattedText,
- pub icon: Slot,
+ pub icon: ItemSlot,
pub frame: FrameType,
pub show_toast: bool,
pub hidden: bool,
@@ -130,7 +131,7 @@ mod tests {
display: Some(DisplayInfo {
title: FormattedText::from("title".to_string()),
description: FormattedText::from("description".to_string()),
- icon: Slot::Empty,
+ icon: ItemSlot::Empty,
frame: FrameType::Task,
show_toast: true,
hidden: false,
diff --git a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
index 318adb7f..94fe31c1 100755
--- a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
@@ -1,7 +1,8 @@
use azalea_buf::{
BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable,
};
-use azalea_core::{ResourceLocation, Slot};
+use azalea_core::ResourceLocation;
+use azalea_inventory::ItemSlot;
use azalea_protocol_macros::ClientboundGamePacket;
use azalea_registry::RecipeSerializer;
@@ -26,7 +27,7 @@ pub struct ShapelessRecipe {
pub group: String,
pub category: CraftingBookCategory,
pub ingredients: Vec<Ingredient>,
- pub result: Slot,
+ pub result: ItemSlot,
}
#[derive(Clone, Debug)]
pub struct ShapedRecipe {
@@ -35,7 +36,7 @@ pub struct ShapedRecipe {
pub group: String,
pub category: CraftingBookCategory,
pub ingredients: Vec<Ingredient>,
- pub result: Slot,
+ pub result: ItemSlot,
pub show_notification: bool,
}
@@ -71,7 +72,7 @@ impl McBufReadable for ShapedRecipe {
for _ in 0..width * height {
ingredients.push(Ingredient::read_from(buf)?);
}
- let result = Slot::read_from(buf)?;
+ let result = ItemSlot::read_from(buf)?;
let show_notification = bool::read_from(buf)?;
Ok(ShapedRecipe {
@@ -91,7 +92,7 @@ pub struct CookingRecipe {
pub group: String,
pub category: CraftingBookCategory,
pub ingredient: Ingredient,
- pub result: Slot,
+ pub result: ItemSlot,
pub experience: f32,
#[var]
pub cooking_time: u32,
@@ -100,13 +101,13 @@ pub struct CookingRecipe {
pub struct StoneCutterRecipe {
pub group: String,
pub ingredient: Ingredient,
- pub result: Slot,
+ pub result: ItemSlot,
}
#[derive(Clone, Debug, McBuf)]
pub struct SmithingRecipe {
pub base: Ingredient,
pub addition: Ingredient,
- pub result: Slot,
+ pub result: ItemSlot,
}
#[derive(Clone, Debug, McBuf)]
@@ -119,7 +120,7 @@ pub struct SmithingTransformRecipe {
pub template: Ingredient,
pub base: Ingredient,
pub addition: Ingredient,
- pub result: Slot,
+ pub result: ItemSlot,
}
#[derive(Clone, Debug, McBuf)]
@@ -159,7 +160,7 @@ pub enum RecipeData {
#[derive(Clone, Debug, McBuf)]
pub struct Ingredient {
- pub allowed: Vec<Slot>,
+ pub allowed: Vec<ItemSlot>,
}
impl McBufWritable for Recipe {
diff --git a/azalea-protocol/src/packets/game/serverbound_container_click_packet.rs b/azalea-protocol/src/packets/game/serverbound_container_click_packet.rs
index 768d3f94..119af220 100755
--- a/azalea-protocol/src/packets/game/serverbound_container_click_packet.rs
+++ b/azalea-protocol/src/packets/game/serverbound_container_click_packet.rs
@@ -1,5 +1,5 @@
use azalea_buf::McBuf;
-use azalea_core::Slot;
+use azalea_inventory::{operations::ClickType, ItemSlot};
use azalea_protocol_macros::ServerboundGamePacket;
use std::collections::HashMap;
@@ -8,20 +8,9 @@ pub struct ServerboundContainerClickPacket {
pub container_id: u8,
#[var]
pub state_id: u32,
- pub slot_num: u16,
+ pub slot_num: i16,
pub button_num: u8,
pub click_type: ClickType,
- pub changed_slots: HashMap<u16, Slot>,
- pub carried_item: Slot,
-}
-
-#[derive(McBuf, Clone, Copy, Debug)]
-pub enum ClickType {
- Pickup = 0,
- QuickMove = 1,
- Swap = 2,
- Clone = 3,
- Throw = 4,
- QuickCraft = 5,
- PickupAll = 6,
+ pub changed_slots: HashMap<u16, ItemSlot>,
+ pub carried_item: ItemSlot,
}
diff --git a/azalea-protocol/src/packets/game/serverbound_set_creative_mode_slot_packet.rs b/azalea-protocol/src/packets/game/serverbound_set_creative_mode_slot_packet.rs
index 254950de..7730bf5a 100755
--- a/azalea-protocol/src/packets/game/serverbound_set_creative_mode_slot_packet.rs
+++ b/azalea-protocol/src/packets/game/serverbound_set_creative_mode_slot_packet.rs
@@ -1,9 +1,9 @@
use azalea_buf::McBuf;
-use azalea_core::Slot;
+use azalea_inventory::ItemSlot;
use azalea_protocol_macros::ServerboundGamePacket;
#[derive(Clone, Debug, McBuf, ServerboundGamePacket)]
pub struct ServerboundSetCreativeModeSlotPacket {
pub slot_num: u16,
- pub item_stack: Slot,
+ pub item_stack: ItemSlot,
}
diff --git a/azalea-protocol/src/packets/game/serverbound_use_item_on_packet.rs b/azalea-protocol/src/packets/game/serverbound_use_item_on_packet.rs
index c7a32a8f..50cbe914 100755
--- a/azalea-protocol/src/packets/game/serverbound_use_item_on_packet.rs
+++ b/azalea-protocol/src/packets/game/serverbound_use_item_on_packet.rs
@@ -7,20 +7,26 @@ use std::io::{Cursor, Write};
#[derive(Clone, Debug, McBuf, ServerboundGamePacket)]
pub struct ServerboundUseItemOnPacket {
pub hand: InteractionHand,
- pub block_hit: BlockHitResult,
+ pub block_hit: BlockHit,
#[var]
pub sequence: u32,
}
#[derive(Clone, Debug)]
-pub struct BlockHitResult {
+pub struct BlockHit {
+ /// The block that we clicked.
pub block_pos: BlockPos,
+ /// The face of the block that was clicked.
pub direction: Direction,
+ /// The exact coordinates of the world where the block was clicked. In the
+ /// network, this is transmitted as the difference between the location and
+ /// block position.
pub location: Vec3,
+ /// Whether the player's head is inside of a block.
pub inside: bool,
}
-impl McBufWritable for BlockHitResult {
+impl McBufWritable for BlockHit {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
self.block_pos.write_into(buf)?;
self.direction.write_into(buf)?;
@@ -41,7 +47,7 @@ impl McBufWritable for BlockHitResult {
}
}
-impl McBufReadable for BlockHitResult {
+impl McBufReadable for BlockHit {
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let block_pos = BlockPos::read_from(buf)?;
let direction = Direction::read_from(buf)?;