Add Serverbound Set Player On Ground

This commit is contained in:
Snowiiii 2024-08-25 12:06:09 +02:00
parent 020c71a973
commit ddd3f1e781
8 changed files with 25 additions and 7 deletions

View File

@ -119,7 +119,7 @@ impl ByteBuffer {
} }
} }
pub fn put_uuid(&mut self, v: uuid::Uuid) { pub fn put_uuid(&mut self, v: &uuid::Uuid) {
// thats the vanilla way // thats the vanilla way
let pair = v.as_u64_pair(); let pair = v.as_u64_pair();
self.put_u64(pair.0); self.put_u64(pair.0);

View File

@ -4,7 +4,7 @@ use crate::{bytebuf::ByteBuffer, ClientPacket, Property};
#[packet(0x02)] #[packet(0x02)]
pub struct CLoginSuccess<'a> { pub struct CLoginSuccess<'a> {
pub uuid: uuid::Uuid, pub uuid: &'a uuid::Uuid,
pub username: &'a str, // 16 pub username: &'a str, // 16
pub properties: &'a [Property], pub properties: &'a [Property],
pub strict_error_handling: bool, pub strict_error_handling: bool,
@ -12,7 +12,7 @@ pub struct CLoginSuccess<'a> {
impl<'a> CLoginSuccess<'a> { impl<'a> CLoginSuccess<'a> {
pub fn new( pub fn new(
uuid: uuid::Uuid, uuid: &'a uuid::Uuid,
username: &'a str, username: &'a str,
properties: &'a [Property], properties: &'a [Property],
strict_error_handling: bool, strict_error_handling: bool,

View File

@ -25,7 +25,7 @@ impl<'a> ClientPacket for CPlayerInfoUpdate<'a> {
fn write(&self, bytebuf: &mut ByteBuffer) { fn write(&self, bytebuf: &mut ByteBuffer) {
bytebuf.put_i8(self.actions); bytebuf.put_i8(self.actions);
bytebuf.put_list::<Player>(self.players, |p, v| { bytebuf.put_list::<Player>(self.players, |p, v| {
p.put_uuid(v.uuid); p.put_uuid(&v.uuid);
for action in &v.actions { for action in &v.actions {
match action { match action {
PlayerAction::AddPlayer { name, properties } => { PlayerAction::AddPlayer { name, properties } => {

View File

@ -7,6 +7,7 @@ mod s_interact;
mod s_ping_request; mod s_ping_request;
mod s_player_action; mod s_player_action;
mod s_player_command; mod s_player_command;
mod s_player_ground;
mod s_player_position; mod s_player_position;
mod s_player_position_rotation; mod s_player_position_rotation;
mod s_player_rotation; mod s_player_rotation;
@ -24,6 +25,7 @@ pub use s_interact::*;
pub use s_ping_request::*; pub use s_ping_request::*;
pub use s_player_action::*; pub use s_player_action::*;
pub use s_player_command::*; pub use s_player_command::*;
pub use s_player_ground::*;
pub use s_player_position::*; pub use s_player_position::*;
pub use s_player_position_rotation::*; pub use s_player_position_rotation::*;
pub use s_player_rotation::*; pub use s_player_rotation::*;

View File

@ -0,0 +1,8 @@
use pumpkin_macros::packet;
use serde::Deserialize;
#[derive(Deserialize)]
#[packet(0x1D)]
pub struct SSetPlayerGround {
pub on_ground: bool,
}

View File

@ -175,7 +175,7 @@ impl Client {
} }
if let Some(profile) = self.gameprofile.as_ref().cloned() { if let Some(profile) = self.gameprofile.as_ref().cloned() {
let packet = CLoginSuccess::new(profile.id, &profile.name, &profile.properties, false); let packet = CLoginSuccess::new(&profile.id, &profile.name, &profile.properties, false);
self.send_packet(&packet); self.send_packet(&packet);
} else { } else {
self.kick("game profile is none"); self.kick("game profile is none");

View File

@ -10,7 +10,7 @@ use num_traits::FromPrimitive;
use pumpkin_core::text::TextComponent; use pumpkin_core::text::TextComponent;
use pumpkin_entity::EntityId; use pumpkin_entity::EntityId;
use pumpkin_inventory::WindowType; use pumpkin_inventory::WindowType;
use pumpkin_protocol::server::play::SCloseContainer; use pumpkin_protocol::server::play::{SCloseContainer, SSetPlayerGround};
use pumpkin_protocol::{ use pumpkin_protocol::{
client::play::{ client::play::{
Animation, CAcknowledgeBlockChange, CBlockUpdate, CEntityAnimation, CEntityVelocity, Animation, CAcknowledgeBlockChange, CBlockUpdate, CEntityAnimation, CEntityVelocity,
@ -178,6 +178,10 @@ impl Player {
handle_command(&mut CommandSender::Player(self), &command.command); handle_command(&mut CommandSender::Player(self), &command.command);
} }
pub fn handle_player_ground(&mut self, _server: &mut Server, ground: SSetPlayerGround) {
self.on_ground = ground.on_ground;
}
pub fn handle_player_command(&mut self, _server: &mut Server, command: SPlayerCommand) { pub fn handle_player_command(&mut self, _server: &mut Server, command: SPlayerCommand) {
if command.entity_id != self.entity.entity_id.into() { if command.entity_id != self.entity.entity_id.into() {
return; return;

View File

@ -11,7 +11,7 @@ use pumpkin_protocol::{
server::play::{ server::play::{
SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract,
SPlayPingRequest, SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayPingRequest, SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation,
SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSwingArm, SUseItemOn, SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSetPlayerGround, SSwingArm, SUseItemOn,
}, },
ConnectionState, RawPacket, ServerPacket, VarInt, ConnectionState, RawPacket, ServerPacket, VarInt,
}; };
@ -192,6 +192,10 @@ impl Player {
self.handle_rotation(server, SPlayerRotation::read(bytebuf)?); self.handle_rotation(server, SPlayerRotation::read(bytebuf)?);
Ok(()) Ok(())
} }
SSetPlayerGround::PACKET_ID => {
self.handle_player_ground(server, SSetPlayerGround::read(bytebuf)?);
Ok(())
}
SPlayerCommand::PACKET_ID => { SPlayerCommand::PACKET_ID => {
self.handle_player_command(server, SPlayerCommand::read(bytebuf)?); self.handle_player_command(server, SPlayerCommand::read(bytebuf)?);
Ok(()) Ok(())