Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Added some data packets." #46

Merged
merged 6 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 61 additions & 36 deletions crates/proto/src/gamepacket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ use std::io::{Cursor, Write};
use std::sync::Arc;

use crate::packets::add_actor_packet::AddActorPacket;
use crate::packets::add_painting_packet::AddPaintingPacket;
use crate::packets::animate::AnimatePacket;
use crate::packets::camera_packet::CameraPacket;
use crate::packets::chunk_radius_updated::ChunkRadiusUpdatedPacket;
use crate::packets::client_cache_status::ClientCacheStatusPacket;
use crate::packets::command_request_packet::CommandRequestPacket;
use crate::packets::container_close_packet::ContainerClosePacket;
use crate::packets::container_open_packet::ContainerOpenPacket;
use crate::packets::correct_player_move_prediction_packet::CorrectPlayerMovePredictionPacket;
use crate::packets::debug_info_packet::DebugInfoPacket;
use crate::packets::disconnect::DisconnectPacket;
use crate::packets::emote_list::EmoteListPacket;
use crate::packets::handshake_server_to_client::HandshakeServerToClientPacket;
use crate::packets::interact::InteractPacket;
use crate::packets::inventory_content_packet::InventoryContentPacket;
use crate::packets::level_chunk::LevelChunkPacket;
use crate::packets::login::LoginPacket;
use crate::packets::mob_equipment_packet::MobEquipmentPacket;
use crate::packets::modal_form_request::ModalFormRequestPacket;
use crate::packets::modal_form_response::ModalFormResponsePacket;
use crate::packets::network_settings::NetworkSettingsPacket;
Expand All @@ -24,14 +30,18 @@ use crate::packets::packet_violation_warning::PacketViolationWarningPacket;
use crate::packets::play_status::PlayStatusPacket;
use crate::packets::player_action::PlayerActionPacket;
use crate::packets::player_auth_input::PlayerAuthInputPacket;
use crate::packets::player_hotbar_packet::PlayerHotbarPacket;
use crate::packets::player_move::MovePlayerPacket;
use crate::packets::remove_actor_packet::RemoveEntityPacket;
use crate::packets::request_chunk_radius::RequestChunkRadiusPacket;
use crate::packets::resource_packs_info::ResourcePacksInfoPacket;
use crate::packets::resource_packs_response::ResourcePacksResponsePacket;
use crate::packets::resource_packs_stack::ResourcePacksStackPacket;
use crate::packets::server_player_post_move_position_packet::ServerPlayerPostMovePositionPacket;
use crate::packets::server_settings_request::ServerSettingsRequestPacket;
use crate::packets::server_settings_response::ServerSettingsResponsePacket;
use crate::packets::set_local_player_as_initialized::SetLocalPlayerAsInitializedPacket;
use crate::packets::set_time_packet::SetTimePacket;
use crate::packets::set_title_packet::SetTitlePacket;
use crate::packets::start_game::StartGamePacket;
use crate::packets::text_message::TextMessagePacket;
Expand All @@ -52,18 +62,19 @@ pub enum GamePacket {
ResourcePackStack(ResourcePacksStackPacket),
ResourcePackClientResponse(ResourcePacksResponsePacket),
TextMessage(TextMessagePacket),
SetTime(),
SetTime(SetTimePacket),
StartGame(StartGamePacket),
AddPlayer(),
AddEntity(AddActorPacket),
RemoveEntity(),
RemoveEntity(RemoveEntityPacket),
AddItemEntity(),
ServerPlayerPostMovePositionPacket(ServerPlayerPostMovePositionPacket),
TakeItemEntity(),
MoveEntity(),
MovePlayer(MovePlayerPacket),
RiderJump(),
UpdateBlock(),
AddPainting(),
AddPainting(AddPaintingPacket),
TickSync(),
LevelSoundEventOld(),
LevelEvent(),
Expand All @@ -72,7 +83,7 @@ pub enum GamePacket {
MobEffect(),
UpdateAttributes(),
InventoryTransaction(),
MobEquipment(),
MobEquipment(MobEquipmentPacket),
MobArmorEquipment(),
Interact(InteractPacket),
BlockPickRequest(),
Expand All @@ -86,10 +97,10 @@ pub enum GamePacket {
SetSpawnPosition(),
Animate(AnimatePacket),
Respawn(),
ContainerOpen(),
ContainerOpen(ContainerOpenPacket),
ContainerClose(ContainerClosePacket),
PlayerHotbar(),
InventoryContent(),
PlayerHotbar(PlayerHotbarPacket),
InventoryContent(InventoryContentPacket),
InventorySlot(),
ContainerSetData(),
CraftingData(),
Expand All @@ -113,7 +124,7 @@ pub enum GamePacket {
ChunkRadiusUpdate(ChunkRadiusUpdatedPacket),
ItemFrameDropItem(),
GameRulesChanged(),
Camera(),
Camera(CameraPacket),
BossEvent(),
ShowCredits(),
AvailableCommands(),
Expand Down Expand Up @@ -182,6 +193,7 @@ pub enum GamePacket {
ItemStackResponse(),
UpdatePlayerGameType(),
EmoteList(EmoteListPacket),
DebugInfoPacket(DebugInfoPacket),
PacketViolationWarning(PacketViolationWarningPacket),
CorrectPlayerMovePredictionPacket(CorrectPlayerMovePredictionPacket),
ItemComponent(),
Expand Down Expand Up @@ -211,6 +223,7 @@ impl GamePacket {
const AddEntityID: u16 = 13;
const RemoveEntityID: u16 = 14;
const AddItemEntityID: u16 = 15;
const ServerPlayerPostMovePositionPacketID: u16 = 16;
const TakeItemEntityID: u16 = 17;
const MoveEntityID: u16 = 18;
const MovePlayerID: u16 = 19;
Expand Down Expand Up @@ -335,6 +348,7 @@ impl GamePacket {
const ItemStackResponseID: u16 = 148;
const UpdatePlayerGameTypeID: u16 = 151;
const EmoteListID: u16 = 152;
const DebugInfoPacketID: u16 = 155;
const PacketViolationWarningID: u16 = 156;
const CorrectPlayerMovePredictionPacketID: u16 = 161;
const ItemComponentID: u16 = 162;
Expand Down Expand Up @@ -431,8 +445,8 @@ impl GamePacket {
GamePacket::TextMessage(pk) => {
ser_packet!(stream, GamePacket::TextMessageID, pk)
}
GamePacket::SetTime() => {
unimplemented!()
GamePacket::SetTime(pk) => {
ser_packet!(stream, GamePacket::SetTimeID, pk)
}
GamePacket::StartGame(pk) => {
ser_packet!(stream, GamePacket::StartGameID, pk)
Expand All @@ -443,12 +457,15 @@ impl GamePacket {
GamePacket::AddEntity(pk) => {
ser_packet!(stream, GamePacket::AddEntityID, pk)
}
GamePacket::RemoveEntity() => {
unimplemented!()
GamePacket::RemoveEntity(pk) => {
ser_packet!(stream, GamePacket::RemoveEntityID, pk)
}
GamePacket::AddItemEntity() => {
unimplemented!()
}
GamePacket::ServerPlayerPostMovePositionPacket(pk) => {
ser_packet!(stream, GamePacket::ServerPlayerPostMovePositionPacketID, pk)
}
GamePacket::TakeItemEntity() => {
unimplemented!()
}
Expand All @@ -464,8 +481,8 @@ impl GamePacket {
GamePacket::UpdateBlock() => {
unimplemented!()
}
GamePacket::AddPainting() => {
unimplemented!()
GamePacket::AddPainting(pk) => {
ser_packet!(stream, GamePacket::AddPaintingID, pk)
}
GamePacket::TickSync() => {
unimplemented!()
Expand All @@ -491,8 +508,8 @@ impl GamePacket {
GamePacket::InventoryTransaction() => {
unimplemented!()
}
GamePacket::MobEquipment() => {
unimplemented!()
GamePacket::MobEquipment(pk) => {
ser_packet!(stream, GamePacket::MobEquipmentID, pk)
}
GamePacket::MobArmorEquipment() => {
unimplemented!()
Expand Down Expand Up @@ -533,17 +550,17 @@ impl GamePacket {
GamePacket::Respawn() => {
unimplemented!()
}
GamePacket::ContainerOpen() => {
unimplemented!()
GamePacket::ContainerOpen(pk) => {
ser_packet!(stream, GamePacket::ContainerOpenID, pk)
}
GamePacket::ContainerClose(pk) => {
ser_packet!(stream, GamePacket::ContainerCloseID, pk)
}
GamePacket::PlayerHotbar() => {
unimplemented!()
GamePacket::PlayerHotbar(pk) => {
ser_packet!(stream, GamePacket::PlayerHotbarID, pk)
}
GamePacket::InventoryContent() => {
unimplemented!()
GamePacket::InventoryContent(pk) => {
ser_packet!(stream, GamePacket::InventoryContentID, pk)
}
GamePacket::InventorySlot() => {
unimplemented!()
Expand Down Expand Up @@ -614,8 +631,8 @@ impl GamePacket {
GamePacket::GameRulesChanged() => {
unimplemented!()
}
GamePacket::Camera() => {
unimplemented!()
GamePacket::Camera(pk) => {
ser_packet!(stream, GamePacket::CameraID, pk)
}
GamePacket::BossEvent() => {
unimplemented!()
Expand Down Expand Up @@ -821,6 +838,9 @@ impl GamePacket {
GamePacket::EmoteList(pk) => {
ser_packet!(stream, GamePacket::EmoteListID, pk)
}
GamePacket::DebugInfoPacket(pk) => {
ser_packet!(stream, GamePacket::DebugInfoPacketID, pk)
}
GamePacket::PacketViolationWarning(pk) => {
ser_packet!(stream, GamePacket::PacketViolationWarningID, pk)
}
Expand Down Expand Up @@ -910,20 +930,24 @@ impl GamePacket {
GamePacket::TextMessageID => {
GamePacket::TextMessage(de_packet!(stream, TextMessagePacket))
}
GamePacket::SetTimeID => {
unimplemented!()
}
GamePacket::SetTimeID => GamePacket::SetTime(de_packet!(stream, SetTimePacket)),
GamePacket::StartGameID => GamePacket::StartGame(de_packet!(stream, StartGamePacket)),
GamePacket::AddPlayerID => {
unimplemented!()
}
GamePacket::AddEntityID => GamePacket::AddEntity(de_packet!(stream, AddActorPacket)),
GamePacket::RemoveEntityID => {
unimplemented!()
GamePacket::RemoveEntity(de_packet!(stream, RemoveEntityPacket))
}
GamePacket::AddItemEntityID => {
unimplemented!()
}
GamePacket::ServerPlayerPostMovePositionPacketID => {
GamePacket::ServerPlayerPostMovePositionPacket(de_packet!(
stream,
ServerPlayerPostMovePositionPacket
))
}
GamePacket::TakeItemEntityID => {
unimplemented!()
}
Expand All @@ -940,7 +964,7 @@ impl GamePacket {
unimplemented!()
}
GamePacket::AddPaintingID => {
unimplemented!()
GamePacket::AddPainting(de_packet!(stream, AddPaintingPacket))
}
GamePacket::TickSyncID => {
unimplemented!()
Expand All @@ -967,7 +991,7 @@ impl GamePacket {
unimplemented!()
}
GamePacket::MobEquipmentID => {
unimplemented!()
GamePacket::MobEquipment(de_packet!(stream, MobEquipmentPacket))
}
GamePacket::MobArmorEquipmentID => {
unimplemented!()
Expand Down Expand Up @@ -1005,16 +1029,16 @@ impl GamePacket {
unimplemented!()
}
GamePacket::ContainerOpenID => {
unimplemented!()
GamePacket::ContainerOpen(de_packet!(stream, ContainerOpenPacket))
}
GamePacket::ContainerCloseID => {
GamePacket::ContainerClose(de_packet!(stream, ContainerClosePacket))
}
GamePacket::PlayerHotbarID => {
unimplemented!()
GamePacket::PlayerHotbar(de_packet!(stream, PlayerHotbarPacket))
}
GamePacket::InventoryContentID => {
unimplemented!()
GamePacket::InventoryContent(de_packet!(stream, InventoryContentPacket))
}
GamePacket::InventorySlotID => {
unimplemented!()
Expand Down Expand Up @@ -1085,9 +1109,7 @@ impl GamePacket {
GamePacket::GameRulesChangedID => {
unimplemented!()
}
GamePacket::CameraID => {
unimplemented!()
}
GamePacket::CameraID => GamePacket::Camera(de_packet!(stream, CameraPacket)),
GamePacket::BossEventID => {
unimplemented!()
}
Expand Down Expand Up @@ -1288,6 +1310,9 @@ impl GamePacket {
unimplemented!()
}
GamePacket::EmoteListID => GamePacket::EmoteList(de_packet!(stream, EmoteListPacket)),
GamePacket::DebugInfoPacketID => {
GamePacket::DebugInfoPacket(de_packet!(stream, DebugInfoPacket))
}
GamePacket::PacketViolationWarningID => {
GamePacket::PacketViolationWarning(de_packet!(stream, PacketViolationWarningPacket))
}
Expand Down
15 changes: 15 additions & 0 deletions crates/proto/src/packets/add_painting_packet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use bedrockrs_core::{
int::{LE, VAR},
Vec3,
};
use bedrockrs_proto_derive::ProtoCodec;
use bedrockrs_shared::{actor_runtime_id::ActorRuntimeID, actor_unique_id::ActorUniqueID};

#[derive(ProtoCodec, Debug, Clone)]
pub struct AddPaintingPacket {
pub target_actor_id: ActorUniqueID,
pub target_runtime_id: ActorRuntimeID,
pub position: Vec3<LE<f32>>,
pub direction: VAR<i32>,
pub motif: String,
}
8 changes: 8 additions & 0 deletions crates/proto/src/packets/camera_packet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use bedrockrs_proto_derive::ProtoCodec;
use bedrockrs_shared::actor_unique_id::ActorUniqueID;

#[derive(ProtoCodec, Debug, Clone)]
pub struct CameraPacket {
pub camera_id: ActorUniqueID,
pub target_player_id: ActorUniqueID,
}
13 changes: 13 additions & 0 deletions crates/proto/src/packets/container_open_packet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use bedrockrs_proto_derive::ProtoCodec;
use bedrockrs_shared::actor_unique_id::ActorUniqueID;

use crate::types::{
container_id::ContainerID, container_type::ContainerType, network_block_pos::NetworkBlockPos,
};
#[derive(ProtoCodec, Debug, Clone)]
pub struct ContainerOpenPacket {
pub container_id: ContainerID,
pub container_type: ContainerType,
pub position: NetworkBlockPos,
pub target_actor_id: ActorUniqueID,
}
8 changes: 8 additions & 0 deletions crates/proto/src/packets/debug_info_packet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use bedrockrs_proto_derive::ProtoCodec;
use bedrockrs_shared::actor_unique_id::ActorUniqueID;

#[derive(ProtoCodec, Debug, Clone)]
pub struct DebugInfoPacket {
pub actor_id: ActorUniqueID,
pub data: String,
}
11 changes: 11 additions & 0 deletions crates/proto/src/packets/inventory_content_packet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use bedrockrs_core::int::VAR;
use bedrockrs_proto_derive::ProtoCodec;

use crate::types::network_item_stack_descriptor::NetworkItemStackDescriptor;

#[derive(ProtoCodec, Debug, Clone)]
pub struct InventoryContentPacket {
pub inventory_id: VAR<u32>,
#[len_repr(VAR::<u32>)]
pub slots: Vec<NetworkItemStackDescriptor>,
}
13 changes: 13 additions & 0 deletions crates/proto/src/packets/mob_equipment_packet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use bedrockrs_core::int::VAR;
use bedrockrs_proto_derive::ProtoCodec;

use crate::types::network_item_stack_descriptor::NetworkItemStackDescriptor;

#[derive(ProtoCodec, Debug, Clone)]
pub struct MobEquipmentPacket {
pub runtime_id: VAR<i32>,
pub item_stack_descriptor: NetworkItemStackDescriptor,
pub slot: u8,
pub selected_slot: u8,
pub container: u8,
}
Loading
Loading