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

Pr/player action packet #36

Closed
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
9 changes: 5 additions & 4 deletions proto/src/gamepacket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::packets::network_settings::NetworkSettingsPacket;
use crate::packets::network_settings_request::NetworkSettingsRequestPacket;
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::request_chunk_radius::RequestChunkRadiusPacket;
use crate::packets::resource_packs_info::ResourcePacksInfoPacket;
Expand Down Expand Up @@ -70,7 +71,7 @@ pub enum GamePacket {
Interact(InteractPacket),
BlockPickRequest(),
EntityPickRequest(),
PlayerAction(),
PlayerAction(PlayerActionPacket),
HurtArmor(),
SetEntityData(),
SetEntityMotion(),
Expand Down Expand Up @@ -495,8 +496,8 @@ impl GamePacket {
GamePacket::EntityPickRequest() => {
unimplemented!()
}
GamePacket::PlayerAction() => {
unimplemented!()
GamePacket::PlayerAction(pk) => {
ser_packet!(stream, GamePacket::PlayerActionID, pk)
}
GamePacket::HurtArmor() => {
unimplemented!()
Expand Down Expand Up @@ -975,7 +976,7 @@ impl GamePacket {
unimplemented!()
}
GamePacket::PlayerActionID => {
unimplemented!()
GamePacket::PlayerAction(de_packet!(stream, PlayerActionPacket))
}
GamePacket::HurtArmorID => {
unimplemented!()
Expand Down
3 changes: 2 additions & 1 deletion proto/src/packets/level_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bedrockrs_proto_core::ProtoCodec;
pub struct LevelChunkPacket {
pub chunk_position: ChunkPos,
pub dimension_id: VAR<i32>,
pub sub_chunk_count: VAR<i32>,
pub sub_chunk_count: VAR<u32>,
pub cache_enabled: bool,
pub serialized_chunk_data: Vec<u8>,

Expand Down Expand Up @@ -38,6 +38,7 @@ impl ProtoCodec for LevelChunkPacket {
unimplemented!()
}

VAR::<u32>::new(self.serialized_chunk_data.len().try_into().unwrap()).proto_serialize(stream)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrap makes me upset :c

this code here does the same without unwrap

let len = self.serialized_chunk_data
   .len()
   .try_into()
   .map_err(|e| ProtoCodecError::FromIntError(e))?;

VAR::<u32>::new(len).proto_serialize(stream)?;

stream.extend_from_slice(&self.serialized_chunk_data);

return Ok(());
Expand Down
1 change: 1 addition & 0 deletions proto/src/packets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ pub mod server_settings_response;
pub mod modal_form_request;
pub mod modal_form_response;
pub mod text_message;
pub mod player_action;
pub mod animate;
55 changes: 55 additions & 0 deletions proto/src/packets/player_action.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use bedrockrs_core::int::{VAR, LE};
use bedrockrs_proto_derive::ProtoCodec;
use crate::types::network_block_pos::NetworkBlockPos;
use bedrockrs_shared::actor_runtime_id::ActorRuntimeID;

pub enum PlayerActionType {
Unknown = -1,
StartDestroyBlock = 0,
AbortDestroyBlock,
StopDestroyBlock,
GetUpdatedBlock,
DropItem,
StartSleeping,
StopSleeping,
Respawn,
StartJump,
StartSprinting,
StopSprinting,
StartSneaking,
StopSneaking,
CreativeDestroyBlock,
ChangeDimensionAck,
StartGliding,
StopGlibiding,
DenyDestroyBlock,
CrackBlock,
ChangeSkin,
DeprecatedUpdatedEnchantingSeed,
StartSwimming,
StopSwimming,
StartSpinAttack,
StopSpinAttack,
InteractWithBlock,
PredictDestroyBlock,
ContinueDestroyBlock,
StartItemUseOn,
StopItemUseOn,
HandledTeleport,
MissedSwing,
StartCrawling,
StopCrawling,
StartFlying,
StopFlying,
ClientAckServerData,
Count
}

#[derive(ProtoCodec, Debug, Clone)]
pub struct PlayerActionPacket {
pub player_runtime_id: ActorRuntimeID,
pub action: VAR<i32>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you turn this into an enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk what the fields r, if ya were about to push this, maybe just close pr for now and u push ur stuff

Copy link
Member

@theaddonn theaddonn Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working on a similar packet, just confused them...
tho here are the possible types:
image
you can create a simple enum with them and use the ProtoCodec derive macro

pub block_pos: NetworkBlockPos,
pub result_pos: NetworkBlockPos,
pub face: VAR<i32>
}
4 changes: 2 additions & 2 deletions proto/src/types/chunk_pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub struct ChunkPos {
impl ChunkPos {
pub fn new(x: i32, z: i32) -> Self {
ChunkPos {
x: VAR::new(x),
z: VAR::new(z)
x: VAR::<i32>::new(x),
z: VAR::<i32>::new(z)
}
}
}