Fixed: Clientbound Entity Metadata
This commit is contained in:
parent
2909cad081
commit
50051d9dc9
@ -7,14 +7,16 @@ use crate::VarInt;
|
|||||||
#[packet(0x58)]
|
#[packet(0x58)]
|
||||||
pub struct CSetEntityMetadata {
|
pub struct CSetEntityMetadata {
|
||||||
entity_id: VarInt,
|
entity_id: VarInt,
|
||||||
metadata: Vec<Metadata>,
|
metadata: Metadata,
|
||||||
|
end: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CSetEntityMetadata {
|
impl CSetEntityMetadata {
|
||||||
pub fn new(entity_id: VarInt, metadata: Vec<Metadata>) -> Self {
|
pub fn new(entity_id: VarInt, metadata: Metadata) -> Self {
|
||||||
Self {
|
Self {
|
||||||
entity_id,
|
entity_id,
|
||||||
metadata,
|
metadata,
|
||||||
|
end: 255,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -200,6 +200,7 @@ impl Client {
|
|||||||
_server: &mut Server,
|
_server: &mut Server,
|
||||||
client_information: SClientInformation,
|
client_information: SClientInformation,
|
||||||
) {
|
) {
|
||||||
|
dbg!("got client settings");
|
||||||
self.config = Some(PlayerConfig {
|
self.config = Some(PlayerConfig {
|
||||||
locale: client_information.locale,
|
locale: client_information.locale,
|
||||||
view_distance: client_information.view_distance,
|
view_distance: client_information.view_distance,
|
||||||
|
|||||||
@ -73,7 +73,7 @@ impl Client {
|
|||||||
|
|
||||||
server.broadcast_packet(
|
server.broadcast_packet(
|
||||||
self,
|
self,
|
||||||
CUpdateEntityPos::new(
|
&CUpdateEntityPos::new(
|
||||||
entity_id.into(),
|
entity_id.into(),
|
||||||
(x * 4096.0 - lastx * 4096.0) as i16,
|
(x * 4096.0 - lastx * 4096.0) as i16,
|
||||||
(y * 4096.0 - lasty * 4096.0) as i16,
|
(y * 4096.0 - lasty * 4096.0) as i16,
|
||||||
@ -120,7 +120,7 @@ impl Client {
|
|||||||
|
|
||||||
server.broadcast_packet(
|
server.broadcast_packet(
|
||||||
self,
|
self,
|
||||||
CUpdateEntityPosRot::new(
|
&CUpdateEntityPosRot::new(
|
||||||
entity_id.into(),
|
entity_id.into(),
|
||||||
(x * 4096.0 - lastx * 4096.0) as i16,
|
(x * 4096.0 - lastx * 4096.0) as i16,
|
||||||
(y * 4096.0 - lasty * 4096.0) as i16,
|
(y * 4096.0 - lasty * 4096.0) as i16,
|
||||||
@ -130,7 +130,7 @@ impl Client {
|
|||||||
on_ground,
|
on_ground,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
server.broadcast_packet(self, CHeadRot::new(entity_id.into(), head_yaw as u8));
|
server.broadcast_packet(self, &CHeadRot::new(entity_id.into(), head_yaw as u8));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_rotation(&mut self, server: &mut Server, rotation: SPlayerRotation) {
|
pub fn handle_rotation(&mut self, server: &mut Server, rotation: SPlayerRotation) {
|
||||||
@ -151,9 +151,9 @@ impl Client {
|
|||||||
|
|
||||||
server.broadcast_packet(
|
server.broadcast_packet(
|
||||||
self,
|
self,
|
||||||
CUpdateEntityRot::new(entity_id.into(), yaw as u8, pitch as u8, on_ground),
|
&CUpdateEntityRot::new(entity_id.into(), yaw as u8, pitch as u8, on_ground),
|
||||||
);
|
);
|
||||||
server.broadcast_packet(self, CHeadRot::new(entity_id.into(), head_yaw as u8));
|
server.broadcast_packet(self, &CHeadRot::new(entity_id.into(), head_yaw as u8));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_chat_command(&mut self, _server: &mut Server, command: SChatCommand) {
|
pub fn handle_chat_command(&mut self, _server: &mut Server, command: SChatCommand) {
|
||||||
@ -191,14 +191,11 @@ impl Client {
|
|||||||
|
|
||||||
pub fn handle_chat_message(&mut self, server: &mut Server, chat_message: SChatMessage) {
|
pub fn handle_chat_message(&mut self, server: &mut Server, chat_message: SChatMessage) {
|
||||||
let message = chat_message.message;
|
let message = chat_message.message;
|
||||||
server.broadcast_packet(
|
self.send_packet(&COpenScreen::new(
|
||||||
self,
|
|
||||||
COpenScreen::new(
|
|
||||||
VarInt(0),
|
VarInt(0),
|
||||||
VarInt(WindowType::CraftingTable as i32),
|
VarInt(WindowType::CraftingTable as i32),
|
||||||
TextComponent::from("Test Crafter"),
|
TextComponent::from("Test Crafter"),
|
||||||
),
|
));
|
||||||
);
|
|
||||||
// TODO: filter message & validation
|
// TODO: filter message & validation
|
||||||
let gameprofile = self.gameprofile.as_ref().unwrap();
|
let gameprofile = self.gameprofile.as_ref().unwrap();
|
||||||
dbg!("got message");
|
dbg!("got message");
|
||||||
|
|||||||
@ -17,7 +17,8 @@ use pumpkin_protocol::{
|
|||||||
config::CPluginMessage,
|
config::CPluginMessage,
|
||||||
play::{
|
play::{
|
||||||
CChunkDataUpdateLight, CGameEvent, CLogin, CPlayerAbilities, CPlayerInfoUpdate,
|
CChunkDataUpdateLight, CGameEvent, CLogin, CPlayerAbilities, CPlayerInfoUpdate,
|
||||||
CRemoveEntities, CRemovePlayerInfo, CSpawnEntity, PlayerAction,
|
CRemoveEntities, CRemovePlayerInfo, CSetEntityMetadata, CSpawnEntity, Metadata,
|
||||||
|
PlayerAction,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
uuid::UUID,
|
uuid::UUID,
|
||||||
@ -130,8 +131,11 @@ impl Server {
|
|||||||
if client.is_player() {
|
if client.is_player() {
|
||||||
let id = client.player.as_ref().unwrap().entity_id();
|
let id = client.player.as_ref().unwrap().entity_id();
|
||||||
let uuid = client.gameprofile.as_ref().unwrap().id;
|
let uuid = client.gameprofile.as_ref().unwrap().id;
|
||||||
self.broadcast_packet(&mut client, CRemovePlayerInfo::new(1.into(), &[UUID(uuid)]));
|
self.broadcast_packet_expect(
|
||||||
self.broadcast_packet(&mut client, CRemoveEntities::new(&[id.into()]))
|
&mut client,
|
||||||
|
&CRemovePlayerInfo::new(1.into(), &[UUID(uuid)]),
|
||||||
|
);
|
||||||
|
self.broadcast_packet_expect(&mut client, &CRemoveEntities::new(&[id.into()]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +191,7 @@ impl Server {
|
|||||||
// also send his info to everyone else
|
// also send his info to everyone else
|
||||||
self.broadcast_packet(
|
self.broadcast_packet(
|
||||||
client,
|
client,
|
||||||
CPlayerInfoUpdate::new(
|
&CPlayerInfoUpdate::new(
|
||||||
0x01 | 0x08,
|
0x01 | 0x08,
|
||||||
&[pumpkin_protocol::client::play::Player {
|
&[pumpkin_protocol::client::play::Player {
|
||||||
uuid: gameprofile.id,
|
uuid: gameprofile.id,
|
||||||
@ -272,30 +276,32 @@ impl Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// entity meta data
|
// entity meta data
|
||||||
/* if let Some(config) = &client.config {
|
if let Some(config) = &client.config {
|
||||||
self.broadcast_packet(
|
self.broadcast_packet(
|
||||||
client,
|
client,
|
||||||
CSetEntityMetadata::new(entity_id.into(), vec![Metadata::new(18, VarInt(0), 0)]),
|
&CSetEntityMetadata::new(
|
||||||
|
entity_id.into(),
|
||||||
|
Metadata::new(17, VarInt(0), config.skin_parts),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// Server::spawn_test_chunk(client);
|
// Server::spawn_test_chunk(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends a Packet to all Players
|
/// Sends a Packet to all Players
|
||||||
pub fn broadcast_packet<P>(&mut self, from: &mut Client, packet: P)
|
pub fn broadcast_packet<P>(&mut self, from: &mut Client, packet: &P)
|
||||||
where
|
where
|
||||||
P: ClientPacket,
|
P: ClientPacket,
|
||||||
{
|
{
|
||||||
// we can't borrow twice at same time
|
// we can't borrow twice at same time
|
||||||
from.send_packet(&packet);
|
from.send_packet(packet);
|
||||||
for (_, client) in self.current_clients.iter().filter(|c| c.0 != &from.token) {
|
for (_, client) in self.current_clients.iter().filter(|c| c.0 != &from.token) {
|
||||||
// Check if client is a player
|
// Check if client is a player
|
||||||
let mut client = client.borrow_mut();
|
let mut client = client.borrow_mut();
|
||||||
if client.is_player() {
|
if client.is_player() {
|
||||||
// we need to clone, Because we send a new packet to every client
|
// we need to clone, Because we send a new packet to every client
|
||||||
client.send_packet(&packet);
|
client.send_packet(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user