Add inventory packets (#57)

Adds the inventory packets so we can use them with `packet_inspector`.
This commit is contained in:
Ryan Johnson 2022-09-14 14:18:04 -07:00 committed by GitHub
parent c73df2c09a
commit 7cd3b6cd2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 11 deletions

View file

@ -740,8 +740,8 @@ impl<C: Config> Client<C> {
})
}
C2sPlayPacket::RequestCommandCompletion(_) => {}
C2sPlayPacket::ButtonClick(_) => {}
C2sPlayPacket::ClickSlot(_) => {}
C2sPlayPacket::ClickContainerButton(_) => {}
C2sPlayPacket::ClickContainer(_) => {}
C2sPlayPacket::CloseHandledScreen(_) => {}
C2sPlayPacket::CustomPayload(_) => {}
C2sPlayPacket::BookUpdate(_) => {}

View file

@ -12,6 +12,7 @@ pub use byte_angle::ByteAngle;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use serde::de::DeserializeOwned;
use serde::Serialize;
pub use slot::Slot;
use uuid::Uuid;
pub use var_int::VarInt;
pub use var_long::VarLong;
@ -23,7 +24,7 @@ use crate::nbt;
mod byte_angle;
pub mod codec;
pub mod packets;
pub mod slot;
mod slot;
mod var_int;
mod var_long;

View file

@ -23,7 +23,7 @@ use crate::block_pos::BlockPos;
use crate::ident::Ident;
use crate::nbt::Compound;
use crate::protocol::{
BoundedArray, BoundedInt, BoundedString, ByteAngle, Decode, Encode, NbtBridge, RawBytes,
BoundedArray, BoundedInt, BoundedString, ByteAngle, Decode, Encode, NbtBridge, RawBytes, Slot,
VarInt, VarLong,
};
use crate::text::Text;

View file

@ -98,8 +98,7 @@ pub mod login {
}
pub mod play {
use super::super::*;
use crate::protocol::slot::Slot;
use super::*;
def_struct! {
TeleportConfirm {
@ -243,15 +242,31 @@ pub mod play {
}
def_struct! {
ButtonClick {
ClickContainerButton {
window_id: i8,
button_id: i8,
}
}
def_struct! {
ClickSlot {
// TODO
ClickContainer {
window_id: u8,
state_id: VarInt,
slot_idx: i16,
button: i8,
mode: ClickContainerMode,
}
}
def_enum! {
ClickContainerMode: VarInt {
Click = 0,
ShiftClick = 1,
Hotbar = 2,
CreativeMiddleClick = 3,
DropKey = 4,
Drag = 5,
DoubleClick = 6,
}
}
@ -708,8 +723,8 @@ pub mod play {
ClientStatus = 7,
ClientSettings = 8,
RequestCommandCompletion = 9,
ButtonClick = 10,
ClickSlot = 11,
ClickContainerButton = 10,
ClickContainer = 11,
CloseHandledScreen = 12,
CustomPayload = 13,
BookUpdate = 14,

View file

@ -227,6 +227,39 @@ pub mod play {
}
}
def_struct! {
SetContainerContent {
window_id: u8,
state_id: VarInt,
slots: Vec<Slot>,
carried_item: Slot,
}
}
def_struct! {
SetContainerProperty {
window_id: u8,
property: i16,
value: i16,
}
}
def_struct! {
SetContainerSlot {
window_id: i8,
state_id: VarInt,
slot_idx: i16,
slot_data: Slot,
}
}
def_struct! {
SetCooldown {
item_id: VarInt,
cooldown_ticks: VarInt,
}
}
def_enum! {
SoundCategory: VarInt {
Master = 0,
@ -567,6 +600,14 @@ pub mod play {
}
}
def_struct! {
OpenScreen {
window_id: VarInt,
window_type: VarInt,
window_title: Text,
}
}
def_struct! {
ChatMessage {
// TODO: more 1.19 stuff.
@ -834,6 +875,10 @@ pub mod play {
BlockUpdate = 9,
BossBar = 10,
ClearTitles = 13,
SetContainerContent = 17,
SetContainerProperty = 18,
SetContainerSlot = 19,
SetCooldown = 20,
PlaySoundId = 23,
Disconnect = 25,
EntityStatus = 26,
@ -845,6 +890,7 @@ pub mod play {
MoveRelative = 40,
RotateAndMoveRelative = 41,
Rotate = 42,
OpenScreen = 45,
ChatMessage = 51,
UpdatePlayerList = 55,
PlayerPositionLook = 57,