Rename packets

Use yarn packet names (with some exceptions) for better consistency. We should also avoid using Mojang names for things in the future.
This commit is contained in:
Ryan 2022-07-29 04:49:08 -07:00
parent c8fe351dd3
commit 959e2b2deb
7 changed files with 303 additions and 295 deletions

View file

@ -18,8 +18,8 @@ use valence::protocol::packets::login::c2s::{EncryptionResponse, LoginStart};
use valence::protocol::packets::login::s2c::{LoginSuccess, S2cLoginPacket}; use valence::protocol::packets::login::s2c::{LoginSuccess, S2cLoginPacket};
use valence::protocol::packets::play::c2s::C2sPlayPacket; use valence::protocol::packets::play::c2s::C2sPlayPacket;
use valence::protocol::packets::play::s2c::S2cPlayPacket; use valence::protocol::packets::play::s2c::S2cPlayPacket;
use valence::protocol::packets::status::c2s::{PingRequest, StatusRequest}; use valence::protocol::packets::status::c2s::{QueryPing, QueryRequest};
use valence::protocol::packets::status::s2c::{PongResponse, StatusResponse}; use valence::protocol::packets::status::s2c::{QueryPong, QueryResponse};
use valence::protocol::packets::{DecodePacket, EncodePacket}; use valence::protocol::packets::{DecodePacket, EncodePacket};
use valence::protocol::{Encode, VarInt}; use valence::protocol::{Encode, VarInt};
@ -121,14 +121,14 @@ async fn handle_connection(client: TcpStream, cli: Cli) -> anyhow::Result<()> {
match handshake.next_state { match handshake.next_state {
HandshakeNextState::Status => { HandshakeNextState::Status => {
cli.rw_packet::<StatusRequest>(&mut client_read, &mut server_write) cli.rw_packet::<QueryRequest>(&mut client_read, &mut server_write)
.await?; .await?;
cli.rw_packet::<StatusResponse>(&mut server_read, &mut client_write) cli.rw_packet::<QueryResponse>(&mut server_read, &mut client_write)
.await?; .await?;
cli.rw_packet::<PingRequest>(&mut client_read, &mut server_write) cli.rw_packet::<QueryPing>(&mut client_read, &mut server_write)
.await?; .await?;
cli.rw_packet::<PongResponse>(&mut server_read, &mut client_write) cli.rw_packet::<QueryPong>(&mut server_read, &mut client_write)
.await?; .await?;
} }
HandshakeNextState::Login => { HandshakeNextState::Login => {
@ -150,7 +150,7 @@ async fn handle_connection(client: TcpStream, cli: Cli) -> anyhow::Result<()> {
s2c = passthrough(server_read.into_inner(), client_write) => s2c, s2c = passthrough(server_read.into_inner(), client_write) => s2c,
}; };
} }
S2cLoginPacket::SetCompression(pkt) => { S2cLoginPacket::LoginCompression(pkt) => {
let threshold = pkt.threshold.0 as u32; let threshold = pkt.threshold.0 as u32;
client_read.enable_compression(threshold); client_read.enable_compression(threshold);
server_read.enable_compression(threshold); server_read.enable_compression(threshold);
@ -159,7 +159,7 @@ async fn handle_connection(client: TcpStream, cli: Cli) -> anyhow::Result<()> {
.await?; .await?;
} }
S2cLoginPacket::LoginSuccess(_) => {} S2cLoginPacket::LoginSuccess(_) => {}
S2cLoginPacket::Disconnect(_) => return Ok(()), S2cLoginPacket::LoginDisconnect(_) => return Ok(()),
S2cLoginPacket::LoginPluginRequest(_) => { S2cLoginPacket::LoginPluginRequest(_) => {
bail!("got login plugin request. Don't know how to proceed.") bail!("got login plugin request. Don't know how to proceed.")
} }

View file

@ -18,7 +18,7 @@ pub use crate::chunk_pos::ChunkPos;
use crate::config::Config; use crate::config::Config;
use crate::dimension::DimensionId; use crate::dimension::DimensionId;
use crate::protocol_inner::packets::play::s2c::{ use crate::protocol_inner::packets::play::s2c::{
BlockUpdate, LevelChunkHeightmaps, LevelChunkWithLight, S2cPlayPacket, SectionBlocksUpdate, BlockUpdate, ChunkDataHeightmaps, ChunkData, S2cPlayPacket, ChunkSectionUpdate,
}; };
use crate::protocol_inner::{Encode, Nbt, VarInt, VarLong}; use crate::protocol_inner::{Encode, Nbt, VarInt, VarLong};
use crate::server::SharedServer; use crate::server::SharedServer;
@ -272,17 +272,17 @@ impl<C: Config> Chunk<C> {
/// Gets the chunk data packet for this chunk with the given position. This /// Gets the chunk data packet for this chunk with the given position. This
/// does not include unapplied changes. /// does not include unapplied changes.
pub(crate) fn chunk_data_packet(&self, pos: ChunkPos) -> LevelChunkWithLight { pub(crate) fn chunk_data_packet(&self, pos: ChunkPos) -> ChunkData {
let mut blocks_and_biomes = Vec::new(); let mut blocks_and_biomes = Vec::new();
for sect in self.sections.iter() { for sect in self.sections.iter() {
blocks_and_biomes.extend_from_slice(&sect.compact_data); blocks_and_biomes.extend_from_slice(&sect.compact_data);
} }
LevelChunkWithLight { ChunkData {
chunk_x: pos.x, chunk_x: pos.x,
chunk_z: pos.z, chunk_z: pos.z,
heightmaps: Nbt(LevelChunkHeightmaps { heightmaps: Nbt(ChunkDataHeightmaps {
motion_blocking: self.heightmap.clone(), motion_blocking: self.heightmap.clone(),
}), }),
blocks_and_biomes, blocks_and_biomes,
@ -346,7 +346,7 @@ impl<C: Config> Chunk<C> {
| (pos.z as i64 & 0x3fffff) << 20 | (pos.z as i64 & 0x3fffff) << 20
| (sect_y as i64 + min_y.div_euclid(16) as i64) & 0xfffff; | (sect_y as i64 + min_y.div_euclid(16) as i64) & 0xfffff;
packet(BlockChangePacket::Multi(SectionBlocksUpdate { packet(BlockChangePacket::Multi(ChunkSectionUpdate {
chunk_section_position, chunk_section_position,
invert_trust_edges: false, invert_trust_edges: false,
blocks, blocks,
@ -407,7 +407,7 @@ impl<C: Config> Chunk<C> {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) enum BlockChangePacket { pub(crate) enum BlockChangePacket {
Single(BlockUpdate), Single(BlockUpdate),
Multi(SectionBlocksUpdate), Multi(ChunkSectionUpdate),
} }
impl From<BlockChangePacket> for S2cPlayPacket { impl From<BlockChangePacket> for S2cPlayPacket {

View file

@ -25,16 +25,16 @@ use crate::player_textures::SignedPlayerTextures;
use crate::protocol_inner::packets::play::c2s::{ use crate::protocol_inner::packets::play::c2s::{
C2sPlayPacket, DiggingStatus, InteractKind, PlayerCommandId, C2sPlayPacket, DiggingStatus, InteractKind, PlayerCommandId,
}; };
pub use crate::protocol_inner::packets::play::s2c::SetTitleAnimationTimes as TitleAnimationTimes; pub use crate::protocol_inner::packets::play::s2c::TitleAnimationTimes as TitleAnimationTimes;
use crate::protocol_inner::packets::play::s2c::{ use crate::protocol_inner::packets::play::s2c::{
Animate, BiomeRegistry, BlockChangeAck, ChatType, ChatTypeChat, ChatTypeNarration, EntityAnimation, BiomeRegistry, PlayerActionResponse, ChatType, ChatTypeChat, ChatTypeNarration,
ChatTypeRegistry, ChatTypeRegistryEntry, ClearTitles, DimensionTypeRegistry, ChatTypeRegistry, ChatTypeRegistryEntry, ClearTitles, DimensionTypeRegistry,
DimensionTypeRegistryEntry, Disconnect, EntityStatus, ForgetLevelChunk, GameEvent, DimensionTypeRegistryEntry, Disconnect, EntityStatus, UnloadChunk, GameStateChange,
GameEventReason, KeepAlive, Login, MoveEntityPosition, MoveEntityPositionAndRotation, GameStateChangeReason, KeepAlive, GameJoin, MoveRelative, RotateAndMoveRelative,
MoveEntityRotation, PlayerPosition, PlayerPositionFlags, RegistryCodec, RemoveEntities, Rotate, PlayerPositionLook, PlayerPositionLookFlags, RegistryCodec, EntitiesDestroy,
Respawn, RotateHead, S2cPlayPacket, SetChunkCacheCenter, SetChunkCacheRadius, PlayerRespawn, EntitySetHeadYaw, S2cPlayPacket, ChunkRenderDistanceCenter, ChunkLoadDistance,
SetEntityMetadata, SetEntityMotion, SetSubtitleText, SetTitleText, SpawnPosition, SystemChat, EntityTrackerUpdate, EntityVelocityUpdate, UpdateSubtitle, UpdateTitle, PlayerSpawnPosition, GameMessage,
TeleportEntity, UpdateAttributes, UpdateAttributesProperty, EntityPosition, EntityAttributes, EntityAttributesProperty,
}; };
use crate::protocol_inner::{BoundedInt, ByteAngle, Nbt, RawBytes, VarInt}; use crate::protocol_inner::{BoundedInt, ByteAngle, Nbt, RawBytes, VarInt};
use crate::server::{C2sPacketChannels, NewClientData, SharedServer}; use crate::server::{C2sPacketChannels, NewClientData, SharedServer};
@ -460,10 +460,10 @@ impl<C: Config> Client<C> {
let title = title.into(); let title = title.into();
let subtitle = subtitle.into(); let subtitle = subtitle.into();
self.send_packet(SetTitleText { text: title }); self.send_packet(UpdateTitle { text: title });
if !subtitle.is_empty() { if !subtitle.is_empty() {
self.send_packet(SetSubtitleText { self.send_packet(UpdateSubtitle {
subtitle_text: subtitle, subtitle_text: subtitle,
}); });
} }
@ -565,7 +565,7 @@ impl<C: Config> Client<C> {
} }
/// Gets if hardcore mode is enabled. /// Gets if hardcore mode is enabled.
pub fn is_hardcore(&mut self) -> bool { pub fn is_hardcore(&self) -> bool {
self.flags.hardcore() self.flags.hardcore()
} }
@ -669,7 +669,7 @@ impl<C: Config> Client<C> {
} }
match pkt { match pkt {
C2sPlayPacket::AcceptTeleportation(p) => { C2sPlayPacket::TeleportConfirm(p) => {
if self.pending_teleports == 0 { if self.pending_teleports == 0 {
log::warn!("unexpected teleport confirmation from {}", self.username()); log::warn!("unexpected teleport confirmation from {}", self.username());
self.disconnect_no_reason(); self.disconnect_no_reason();
@ -691,16 +691,16 @@ impl<C: Config> Client<C> {
self.disconnect_no_reason(); self.disconnect_no_reason();
} }
} }
C2sPlayPacket::BlockEntityTagQuery(_) => {} C2sPlayPacket::QueryBlockNbt(_) => {}
C2sPlayPacket::ChangeDifficulty(_) => {} C2sPlayPacket::UpdateDifficulty(_) => {}
C2sPlayPacket::ChatCommand(_) => {} C2sPlayPacket::CommandExecution(_) => {}
C2sPlayPacket::Chat(p) => self.events.push_back(Event::ChatMessage { C2sPlayPacket::ChatMessage(p) => self.events.push_back(Event::ChatMessage {
message: p.message.0, message: p.message.0,
timestamp: Duration::from_millis(p.timestamp), timestamp: Duration::from_millis(p.timestamp),
}), }),
C2sPlayPacket::ChatPreview(_) => {} C2sPlayPacket::RequestChatPreview(_) => {}
C2sPlayPacket::ClientCommand(_) => {} C2sPlayPacket::ClientStatus(_) => {}
C2sPlayPacket::ClientInformation(p) => { C2sPlayPacket::ClientSettings(p) => {
let old = self.settings.replace(Settings { let old = self.settings.replace(Settings {
locale: p.locale.0, locale: p.locale.0,
view_distance: p.view_distance.0, view_distance: p.view_distance.0,
@ -713,13 +713,14 @@ impl<C: Config> Client<C> {
self.events.push_back(Event::SettingsChanged(old)); self.events.push_back(Event::SettingsChanged(old));
} }
C2sPlayPacket::CommandSuggestion(_) => {} C2sPlayPacket::RequestCommandCompletion(_) => {}
C2sPlayPacket::ContainerButtonClick(_) => {} C2sPlayPacket::ButtonClick(_) => {}
C2sPlayPacket::ContainerClose(_) => {} C2sPlayPacket::ClickSlot(_) => {}
C2sPlayPacket::CloseHandledScreen(_) => {}
C2sPlayPacket::CustomPayload(_) => {} C2sPlayPacket::CustomPayload(_) => {}
C2sPlayPacket::EditBook(_) => {} C2sPlayPacket::BookUpdate(_) => {}
C2sPlayPacket::EntityTagQuery(_) => {} C2sPlayPacket::QueryEntityNbt(_) => {}
C2sPlayPacket::Interact(p) => { C2sPlayPacket::PlayerInteractEntity(p) => {
if let Some(id) = entities.get_with_network_id(p.entity_id.0) { if let Some(id) = entities.get_with_network_id(p.entity_id.0) {
// TODO: verify that the client has line of sight to the targeted entity and // TODO: verify that the client has line of sight to the targeted entity and
// that the distance is <=4 blocks. // that the distance is <=4 blocks.
@ -755,7 +756,7 @@ impl<C: Config> Client<C> {
self.flags.set_got_keepalive(true); self.flags.set_got_keepalive(true);
} }
} }
C2sPlayPacket::LockDifficulty(_) => {} C2sPlayPacket::UpdateDifficultyLock(_) => {}
C2sPlayPacket::MovePlayerPosition(p) => { C2sPlayPacket::MovePlayerPosition(p) => {
handle_movement_packet(self, false, p.position, self.yaw, self.pitch, p.on_ground) handle_movement_packet(self, false, p.position, self.yaw, self.pitch, p.on_ground)
} }
@ -765,7 +766,7 @@ impl<C: Config> Client<C> {
C2sPlayPacket::MovePlayerRotation(p) => { C2sPlayPacket::MovePlayerRotation(p) => {
handle_movement_packet(self, false, self.new_position, p.yaw, p.pitch, p.on_ground) handle_movement_packet(self, false, self.new_position, p.yaw, p.pitch, p.on_ground)
} }
C2sPlayPacket::MovePlayerStatusOnly(p) => handle_movement_packet( C2sPlayPacket::MovePlayerOnGround(p) => handle_movement_packet(
self, self,
false, false,
self.new_position, self.new_position,
@ -783,15 +784,15 @@ impl<C: Config> Client<C> {
self.flags.on_ground(), self.flags.on_ground(),
); );
} }
C2sPlayPacket::PaddleBoat(p) => { C2sPlayPacket::BoatPaddleState(p) => {
self.events.push_back(Event::SteerBoat { self.events.push_back(Event::SteerBoat {
left_paddle_turning: p.left_paddle_turning, left_paddle_turning: p.left_paddle_turning,
right_paddle_turning: p.right_paddle_turning, right_paddle_turning: p.right_paddle_turning,
}); });
} }
C2sPlayPacket::PickItem(_) => {} C2sPlayPacket::PickFromInventory(_) => {}
C2sPlayPacket::PlaceRecipe(_) => {} C2sPlayPacket::CraftRequest(_) => {}
C2sPlayPacket::PlayerAbilities(_) => {} C2sPlayPacket::UpdatePlayerAbilities(_) => {}
C2sPlayPacket::PlayerAction(p) => { C2sPlayPacket::PlayerAction(p) => {
// TODO: verify dug block is within the correct distance from the client. // TODO: verify dug block is within the correct distance from the client.
// TODO: verify that the broken block is allowed to be broken? // TODO: verify that the broken block is allowed to be broken?
@ -875,25 +876,25 @@ impl<C: Config> Client<C> {
}); });
} }
C2sPlayPacket::PlayerInput(_) => {} C2sPlayPacket::PlayerInput(_) => {}
C2sPlayPacket::Pong(_) => {} C2sPlayPacket::PlayPong(_) => {}
C2sPlayPacket::RecipeBookChangeSettings(_) => {} C2sPlayPacket::RecipeBookChangeSettings(_) => {}
C2sPlayPacket::RecipeBookSeenRecipe(_) => {} C2sPlayPacket::RecipeBookSeenRecipe(_) => {}
C2sPlayPacket::RenameItem(_) => {} C2sPlayPacket::RenameItem(_) => {}
C2sPlayPacket::ResourcePack(_) => {} C2sPlayPacket::ResourcePackStatus(_) => {}
C2sPlayPacket::SeenAdvancements(_) => {} C2sPlayPacket::AdvancementTab(_) => {}
C2sPlayPacket::SelectTrade(_) => {} C2sPlayPacket::SelectMerchantTrade(_) => {}
C2sPlayPacket::SetBeacon(_) => {} C2sPlayPacket::UpdateBeacon(_) => {}
C2sPlayPacket::SetCarriedItem(_) => {} C2sPlayPacket::UpdateSelectedSlot(_) => {}
C2sPlayPacket::SetCommandBlock(_) => {} C2sPlayPacket::UpdateCommandBlock(_) => {}
C2sPlayPacket::SetCommandBlockMinecart(_) => {} C2sPlayPacket::UpdateCommandBlockMinecart(_) => {}
C2sPlayPacket::SetCreativeModeSlot(_) => {} C2sPlayPacket::UpdateCreativeModeSlot(_) => {}
C2sPlayPacket::SetJigsawBlock(_) => {} C2sPlayPacket::UpdateJigsaw(_) => {}
C2sPlayPacket::SetStructureBlock(_) => {} C2sPlayPacket::UpdateStructureBlock(_) => {}
C2sPlayPacket::SignUpdate(_) => {} C2sPlayPacket::UpdateSign(_) => {}
C2sPlayPacket::Swing(p) => self.events.push_back(Event::ArmSwing(p.hand)), C2sPlayPacket::HandSwing(p) => self.events.push_back(Event::ArmSwing(p.hand)),
C2sPlayPacket::TeleportToEntity(_) => {} C2sPlayPacket::SpectatorTeleport(_) => {}
C2sPlayPacket::UseItemOn(_) => {} C2sPlayPacket::PlayerInteractBlock(_) => {}
C2sPlayPacket::UseItem(_) => {} C2sPlayPacket::PlayerInteractItem(_) => {}
} }
} }
@ -938,7 +939,7 @@ impl<C: Config> Client<C> {
dimension_names.push(ident!("{LIBRARY_NAMESPACE}:dummy_dimension")); dimension_names.push(ident!("{LIBRARY_NAMESPACE}:dummy_dimension"));
self.send_packet(Login { self.send_packet(GameJoin {
entity_id: 0, // EntityId 0 is reserved for clients. entity_id: 0, // EntityId 0 is reserved for clients.
is_hardcore: self.flags.hardcore(), is_hardcore: self.flags.hardcore(),
gamemode: self.new_game_mode, gamemode: self.new_game_mode,
@ -976,7 +977,7 @@ impl<C: Config> Client<C> {
// TODO: clear player list. // TODO: clear player list.
// Client bug workaround: send the client to a dummy dimension first. // Client bug workaround: send the client to a dummy dimension first.
self.send_packet(Respawn { self.send_packet(PlayerRespawn {
dimension_type_name: ident!("{LIBRARY_NAMESPACE}:dimension_type_0"), dimension_type_name: ident!("{LIBRARY_NAMESPACE}:dimension_type_0"),
dimension_name: ident!("{LIBRARY_NAMESPACE}:dummy_dimension"), dimension_name: ident!("{LIBRARY_NAMESPACE}:dummy_dimension"),
hashed_seed: 0, hashed_seed: 0,
@ -988,7 +989,7 @@ impl<C: Config> Client<C> {
last_death_location: None, last_death_location: None,
}); });
self.send_packet(Respawn { self.send_packet(PlayerRespawn {
dimension_type_name: ident!( dimension_type_name: ident!(
"{LIBRARY_NAMESPACE}:dimension_type_{}", "{LIBRARY_NAMESPACE}:dimension_type_{}",
world.meta.dimension().0 world.meta.dimension().0
@ -1013,8 +1014,8 @@ impl<C: Config> Client<C> {
if self.old_game_mode != self.new_game_mode { if self.old_game_mode != self.new_game_mode {
self.old_game_mode = self.new_game_mode; self.old_game_mode = self.new_game_mode;
self.send_packet(GameEvent { self.send_packet(GameStateChange {
reason: GameEventReason::ChangeGameMode, reason: GameStateChangeReason::ChangeGameMode,
value: self.new_game_mode as i32 as f32, value: self.new_game_mode as i32 as f32,
}); });
} }
@ -1029,9 +1030,9 @@ impl<C: Config> Client<C> {
if self.flags.attack_speed_modified() { if self.flags.attack_speed_modified() {
self.flags.set_attack_speed_modified(false); self.flags.set_attack_speed_modified(false);
self.send_packet(UpdateAttributes { self.send_packet(EntityAttributes {
entity_id: VarInt(0), entity_id: VarInt(0),
properties: vec![UpdateAttributesProperty { properties: vec![EntityAttributesProperty {
key: ident!("generic.attack_speed"), key: ident!("generic.attack_speed"),
value: self.attack_speed, value: self.attack_speed,
modifiers: Vec::new(), modifiers: Vec::new(),
@ -1042,9 +1043,9 @@ impl<C: Config> Client<C> {
if self.flags.movement_speed_modified() { if self.flags.movement_speed_modified() {
self.flags.set_movement_speed_modified(false); self.flags.set_movement_speed_modified(false);
self.send_packet(UpdateAttributes { self.send_packet(EntityAttributes {
entity_id: VarInt(0), entity_id: VarInt(0),
properties: vec![UpdateAttributesProperty { properties: vec![EntityAttributesProperty {
key: ident!("generic.movement_speed"), key: ident!("generic.movement_speed"),
value: self.movement_speed, value: self.movement_speed,
modifiers: Vec::new(), modifiers: Vec::new(),
@ -1056,7 +1057,7 @@ impl<C: Config> Client<C> {
if self.flags.modified_spawn_position() { if self.flags.modified_spawn_position() {
self.flags.set_modified_spawn_position(false); self.flags.set_modified_spawn_position(false);
self.send_packet(SpawnPosition { self.send_packet(PlayerSpawnPosition {
location: self.spawn_position, location: self.spawn_position,
angle: self.spawn_position_yaw, angle: self.spawn_position_yaw,
}) })
@ -1066,7 +1067,7 @@ impl<C: Config> Client<C> {
if self.old_max_view_distance != self.new_max_view_distance { if self.old_max_view_distance != self.new_max_view_distance {
self.old_max_view_distance = self.new_max_view_distance; self.old_max_view_distance = self.new_max_view_distance;
if self.created_tick != current_tick { if self.created_tick != current_tick {
self.send_packet(SetChunkCacheRadius { self.send_packet(ChunkLoadDistance {
view_distance: BoundedInt(VarInt(self.new_max_view_distance as i32)), view_distance: BoundedInt(VarInt(self.new_max_view_distance as i32)),
}) })
} }
@ -1099,7 +1100,7 @@ impl<C: Config> Client<C> {
let new_section = self.new_position.map(|n| (n / 16.0).floor() as i32); let new_section = self.new_position.map(|n| (n / 16.0).floor() as i32);
if old_section != new_section { if old_section != new_section {
self.send_packet(SetChunkCacheCenter { self.send_packet(ChunkRenderDistanceCenter {
chunk_x: VarInt(new_section.x), chunk_x: VarInt(new_section.x),
chunk_z: VarInt(new_section.z), chunk_z: VarInt(new_section.z),
}) })
@ -1128,7 +1129,7 @@ impl<C: Config> Client<C> {
send_packet( send_packet(
&mut self.send, &mut self.send,
ForgetLevelChunk { UnloadChunk {
chunk_x: pos.x, chunk_x: pos.x,
chunk_z: pos.z, chunk_z: pos.z,
}, },
@ -1150,7 +1151,7 @@ impl<C: Config> Client<C> {
for seq in self.dug_blocks.drain(..) { for seq in self.dug_blocks.drain(..) {
send_packet( send_packet(
&mut self.send, &mut self.send,
BlockChangeAck { PlayerActionResponse {
sequence: VarInt(seq), sequence: VarInt(seq),
}, },
) )
@ -1163,11 +1164,11 @@ impl<C: Config> Client<C> {
if self.flags.teleported_this_tick() { if self.flags.teleported_this_tick() {
self.flags.set_teleported_this_tick(false); self.flags.set_teleported_this_tick(false);
self.send_packet(PlayerPosition { self.send_packet(PlayerPositionLook {
position: self.new_position, position: self.new_position,
yaw: self.yaw, yaw: self.yaw,
pitch: self.pitch, pitch: self.pitch,
flags: PlayerPositionFlags::new(false, false, false, false, false), flags: PlayerPositionLookFlags::new(false, false, false, false, false),
teleport_id: VarInt((self.teleport_id_counter - 1) as i32), teleport_id: VarInt((self.teleport_id_counter - 1) as i32),
dismount_vehicle: false, dismount_vehicle: false,
}); });
@ -1178,7 +1179,7 @@ impl<C: Config> Client<C> {
if self.flags.velocity_modified() { if self.flags.velocity_modified() {
self.flags.set_velocity_modified(false); self.flags.set_velocity_modified(false);
self.send_packet(SetEntityMotion { self.send_packet(EntityVelocityUpdate {
entity_id: VarInt(0), entity_id: VarInt(0),
velocity: velocity_to_packet_units(self.velocity), velocity: velocity_to_packet_units(self.velocity),
}); });
@ -1188,7 +1189,7 @@ impl<C: Config> Client<C> {
for msg in self.msgs_to_send.drain(..) { for msg in self.msgs_to_send.drain(..) {
send_packet( send_packet(
&mut self.send, &mut self.send,
SystemChat { GameMessage {
chat: msg, chat: msg,
kind: VarInt(0), kind: VarInt(0),
}, },
@ -1217,7 +1218,7 @@ impl<C: Config> Client<C> {
{ {
send_packet( send_packet(
&mut self.send, &mut self.send,
MoveEntityPositionAndRotation { RotateAndMoveRelative {
entity_id: VarInt(id.to_network_id()), entity_id: VarInt(id.to_network_id()),
delta: (position_delta * 4096.0).as_(), delta: (position_delta * 4096.0).as_(),
yaw: ByteAngle::from_degrees(entity.yaw()), yaw: ByteAngle::from_degrees(entity.yaw()),
@ -1229,7 +1230,7 @@ impl<C: Config> Client<C> {
if entity.position() != entity.old_position() && !needs_teleport { if entity.position() != entity.old_position() && !needs_teleport {
send_packet( send_packet(
&mut self.send, &mut self.send,
MoveEntityPosition { MoveRelative {
entity_id: VarInt(id.to_network_id()), entity_id: VarInt(id.to_network_id()),
delta: (position_delta * 4096.0).as_(), delta: (position_delta * 4096.0).as_(),
on_ground: entity.on_ground(), on_ground: entity.on_ground(),
@ -1240,7 +1241,7 @@ impl<C: Config> Client<C> {
if flags.yaw_or_pitch_modified() { if flags.yaw_or_pitch_modified() {
send_packet( send_packet(
&mut self.send, &mut self.send,
MoveEntityRotation { Rotate {
entity_id: VarInt(id.to_network_id()), entity_id: VarInt(id.to_network_id()),
yaw: ByteAngle::from_degrees(entity.yaw()), yaw: ByteAngle::from_degrees(entity.yaw()),
pitch: ByteAngle::from_degrees(entity.pitch()), pitch: ByteAngle::from_degrees(entity.pitch()),
@ -1253,7 +1254,7 @@ impl<C: Config> Client<C> {
if needs_teleport { if needs_teleport {
send_packet( send_packet(
&mut self.send, &mut self.send,
TeleportEntity { EntityPosition {
entity_id: VarInt(id.to_network_id()), entity_id: VarInt(id.to_network_id()),
position: entity.position(), position: entity.position(),
yaw: ByteAngle::from_degrees(entity.yaw()), yaw: ByteAngle::from_degrees(entity.yaw()),
@ -1266,7 +1267,7 @@ impl<C: Config> Client<C> {
if flags.velocity_modified() { if flags.velocity_modified() {
send_packet( send_packet(
&mut self.send, &mut self.send,
SetEntityMotion { EntityVelocityUpdate {
entity_id: VarInt(id.to_network_id()), entity_id: VarInt(id.to_network_id()),
velocity: velocity_to_packet_units(entity.velocity()), velocity: velocity_to_packet_units(entity.velocity()),
}, },
@ -1276,7 +1277,7 @@ impl<C: Config> Client<C> {
if flags.head_yaw_modified() { if flags.head_yaw_modified() {
send_packet( send_packet(
&mut self.send, &mut self.send,
RotateHead { EntitySetHeadYaw {
entity_id: VarInt(id.to_network_id()), entity_id: VarInt(id.to_network_id()),
head_yaw: ByteAngle::from_degrees(entity.head_yaw()), head_yaw: ByteAngle::from_degrees(entity.head_yaw()),
}, },
@ -1294,7 +1295,7 @@ impl<C: Config> Client<C> {
}); });
if !entities_to_unload.is_empty() { if !entities_to_unload.is_empty() {
self.send_packet(RemoveEntities { self.send_packet(EntitiesDestroy {
entities: entities_to_unload, entities: entities_to_unload,
}); });
} }
@ -1306,7 +1307,7 @@ impl<C: Config> Client<C> {
if !data.is_empty() { if !data.is_empty() {
data.push(0xff); data.push(0xff);
self.send_packet(SetEntityMetadata { self.send_packet(EntityTrackerUpdate {
entity_id: VarInt(0), entity_id: VarInt(0),
metadata: RawBytes(data), metadata: RawBytes(data),
}); });
@ -1377,7 +1378,7 @@ fn send_entity_events(send_opt: &mut SendOpt, entity_id: i32, events: &[EntityEv
), ),
StatusOrAnimation::Animation(code) => send_packet( StatusOrAnimation::Animation(code) => send_packet(
send_opt, send_opt,
Animate { EntityAnimation {
entity_id: VarInt(entity_id), entity_id: VarInt(entity_id),
animation: code, animation: code,
}, },

View file

@ -13,7 +13,7 @@ use vek::{Aabb, Vec3};
use crate::config::Config; use crate::config::Config;
use crate::protocol_inner::packets::play::s2c::{ use crate::protocol_inner::packets::play::s2c::{
AddEntity, AddExperienceOrb, AddPlayer, S2cPlayPacket, SetEntityMetadata, EntitySpawn, ExperienceOrbSpawn, PlayerSpawn, S2cPlayPacket, EntityTrackerUpdate,
}; };
use crate::protocol_inner::{ByteAngle, RawBytes, VarInt}; use crate::protocol_inner::{ByteAngle, RawBytes, VarInt};
use crate::slotmap::{Key, SlotMap}; use crate::slotmap::{Key, SlotMap};
@ -556,10 +556,10 @@ impl<C: Config> Entity<C> {
pub(crate) fn initial_tracked_data_packet( pub(crate) fn initial_tracked_data_packet(
&self, &self,
this_id: EntityId, this_id: EntityId,
) -> Option<SetEntityMetadata> { ) -> Option<EntityTrackerUpdate> {
self.variants self.variants
.initial_tracked_data() .initial_tracked_data()
.map(|meta| SetEntityMetadata { .map(|meta| EntityTrackerUpdate {
entity_id: VarInt(this_id.to_network_id()), entity_id: VarInt(this_id.to_network_id()),
metadata: RawBytes(meta), metadata: RawBytes(meta),
}) })
@ -572,10 +572,10 @@ impl<C: Config> Entity<C> {
pub(crate) fn updated_tracked_data_packet( pub(crate) fn updated_tracked_data_packet(
&self, &self,
this_id: EntityId, this_id: EntityId,
) -> Option<SetEntityMetadata> { ) -> Option<EntityTrackerUpdate> {
self.variants self.variants
.updated_tracked_data() .updated_tracked_data()
.map(|meta| SetEntityMetadata { .map(|meta| EntityTrackerUpdate {
entity_id: VarInt(this_id.to_network_id()), entity_id: VarInt(this_id.to_network_id()),
metadata: RawBytes(meta), metadata: RawBytes(meta),
}) })
@ -585,20 +585,20 @@ impl<C: Config> Entity<C> {
match &self.variants { match &self.variants {
EntityEnum::Marker(_) => None, EntityEnum::Marker(_) => None,
EntityEnum::ExperienceOrb(_) => { EntityEnum::ExperienceOrb(_) => {
Some(EntitySpawnPacket::ExperienceOrb(AddExperienceOrb { Some(EntitySpawnPacket::ExperienceOrb(ExperienceOrbSpawn {
entity_id: VarInt(this_id.to_network_id()), entity_id: VarInt(this_id.to_network_id()),
position: self.new_position, position: self.new_position,
count: 0, // TODO count: 0, // TODO
})) }))
} }
EntityEnum::Player(_) => Some(EntitySpawnPacket::Player(AddPlayer { EntityEnum::Player(_) => Some(EntitySpawnPacket::Player(PlayerSpawn {
entity_id: VarInt(this_id.to_network_id()), entity_id: VarInt(this_id.to_network_id()),
player_uuid: self.uuid, player_uuid: self.uuid,
position: self.new_position, position: self.new_position,
yaw: ByteAngle::from_degrees(self.yaw), yaw: ByteAngle::from_degrees(self.yaw),
pitch: ByteAngle::from_degrees(self.pitch), pitch: ByteAngle::from_degrees(self.pitch),
})), })),
_ => Some(EntitySpawnPacket::Entity(AddEntity { _ => Some(EntitySpawnPacket::Entity(EntitySpawn {
entity_id: VarInt(this_id.to_network_id()), entity_id: VarInt(this_id.to_network_id()),
object_uuid: self.uuid, object_uuid: self.uuid,
kind: VarInt(self.kind() as i32), kind: VarInt(self.kind() as i32),
@ -619,9 +619,9 @@ pub(crate) fn velocity_to_packet_units(vel: Vec3<f32>) -> Vec3<i16> {
} }
pub(crate) enum EntitySpawnPacket { pub(crate) enum EntitySpawnPacket {
Entity(AddEntity), Entity(EntitySpawn),
ExperienceOrb(AddExperienceOrb), ExperienceOrb(ExperienceOrbSpawn),
Player(AddPlayer), Player(PlayerSpawn),
} }
impl From<EntitySpawnPacket> for S2cPlayPacket { impl From<EntitySpawnPacket> for S2cPlayPacket {

View file

@ -9,7 +9,7 @@ use uuid::Uuid;
use crate::client::GameMode; use crate::client::GameMode;
use crate::player_textures::SignedPlayerTextures; use crate::player_textures::SignedPlayerTextures;
use crate::protocol_inner::packets::play::s2c::{ use crate::protocol_inner::packets::play::s2c::{
PlayerInfo, PlayerInfoAddPlayer, S2cPlayPacket, TabList, PlayerListAddPlayer, PlayerListHeaderFooter, S2cPlayPacket, UpdatePlayerList,
}; };
use crate::protocol_inner::packets::Property; use crate::protocol_inner::packets::Property;
use crate::protocol_inner::VarInt; use crate::protocol_inner::VarInt;
@ -164,7 +164,7 @@ impl PlayerList {
let add_player: Vec<_> = self let add_player: Vec<_> = self
.entries .entries
.iter() .iter()
.map(|(&uuid, e)| PlayerInfoAddPlayer { .map(|(&uuid, e)| PlayerListAddPlayer {
uuid, uuid,
username: e.username.clone().into(), username: e.username.clone().into(),
properties: { properties: {
@ -186,12 +186,12 @@ impl PlayerList {
.collect(); .collect();
if !add_player.is_empty() { if !add_player.is_empty() {
packet(PlayerInfo::AddPlayer(add_player).into()); packet(UpdatePlayerList::AddPlayer(add_player).into());
} }
if self.header != Text::default() || self.footer != Text::default() { if self.header != Text::default() || self.footer != Text::default() {
packet( packet(
TabList { PlayerListHeaderFooter {
header: self.header.clone(), header: self.header.clone(),
footer: self.footer.clone(), footer: self.footer.clone(),
} }
@ -202,7 +202,7 @@ impl PlayerList {
pub(crate) fn diff_packets(&self, mut packet: impl FnMut(S2cPlayPacket)) { pub(crate) fn diff_packets(&self, mut packet: impl FnMut(S2cPlayPacket)) {
if !self.removed.is_empty() { if !self.removed.is_empty() {
packet(PlayerInfo::RemovePlayer(self.removed.iter().cloned().collect()).into()); packet(UpdatePlayerList::RemovePlayer(self.removed.iter().cloned().collect()).into());
} }
let mut add_player = Vec::new(); let mut add_player = Vec::new();
@ -221,7 +221,7 @@ impl PlayerList {
}); });
} }
add_player.push(PlayerInfoAddPlayer { add_player.push(PlayerListAddPlayer {
uuid, uuid,
username: e.username.clone().into(), username: e.username.clone().into(),
properties, properties,
@ -248,24 +248,24 @@ impl PlayerList {
} }
if !add_player.is_empty() { if !add_player.is_empty() {
packet(PlayerInfo::AddPlayer(add_player).into()); packet(UpdatePlayerList::AddPlayer(add_player).into());
} }
if !game_mode.is_empty() { if !game_mode.is_empty() {
packet(PlayerInfo::UpdateGameMode(game_mode).into()); packet(UpdatePlayerList::UpdateGameMode(game_mode).into());
} }
if !ping.is_empty() { if !ping.is_empty() {
packet(PlayerInfo::UpdateLatency(ping).into()); packet(UpdatePlayerList::UpdateLatency(ping).into());
} }
if !display_name.is_empty() { if !display_name.is_empty() {
packet(PlayerInfo::UpdateDisplayName(display_name).into()); packet(UpdatePlayerList::UpdateDisplayName(display_name).into());
} }
if self.modified_header_or_footer { if self.modified_header_or_footer {
packet( packet(
TabList { PlayerListHeaderFooter {
header: self.header.clone(), header: self.header.clone(),
footer: self.footer.clone(), footer: self.footer.clone(),
} }

View file

@ -448,13 +448,13 @@ pub mod status {
use super::super::*; use super::super::*;
def_struct! { def_struct! {
StatusResponse 0x00 { QueryResponse 0x00 {
json_response: String json_response: String
} }
} }
def_struct! { def_struct! {
PongResponse 0x01 { QueryPong 0x01 {
/// Should be the same as the payload from ping. /// Should be the same as the payload from ping.
payload: u64 payload: u64
} }
@ -465,11 +465,11 @@ pub mod status {
use super::super::*; use super::super::*;
def_struct! { def_struct! {
StatusRequest 0x00 {} QueryRequest 0x00 {}
} }
def_struct! { def_struct! {
PingRequest 0x01 { QueryPing 0x01 {
payload: u64 payload: u64
} }
} }
@ -482,7 +482,7 @@ pub mod login {
use super::super::*; use super::super::*;
def_struct! { def_struct! {
Disconnect 0x00 { LoginDisconnect 0x00 {
reason: Text, reason: Text,
} }
} }
@ -506,7 +506,7 @@ pub mod login {
} }
def_struct! { def_struct! {
SetCompression 0x03 { LoginCompression 0x03 {
threshold: VarInt threshold: VarInt
} }
} }
@ -521,10 +521,10 @@ pub mod login {
def_packet_group! { def_packet_group! {
S2cLoginPacket { S2cLoginPacket {
Disconnect, LoginDisconnect,
EncryptionRequest, EncryptionRequest,
LoginSuccess, LoginSuccess,
SetCompression, LoginCompression,
LoginPluginRequest, LoginPluginRequest,
} }
} }
@ -584,7 +584,7 @@ pub mod play {
use super::super::*; use super::super::*;
def_struct! { def_struct! {
AddEntity 0x00 { EntitySpawn 0x00 {
entity_id: VarInt, entity_id: VarInt,
object_uuid: Uuid, object_uuid: Uuid,
kind: VarInt, kind: VarInt,
@ -598,7 +598,7 @@ pub mod play {
} }
def_struct! { def_struct! {
AddExperienceOrb 0x01 { ExperienceOrbSpawn 0x01 {
entity_id: VarInt, entity_id: VarInt,
position: Vec3<f64>, position: Vec3<f64>,
count: i16, count: i16,
@ -606,7 +606,7 @@ pub mod play {
} }
def_struct! { def_struct! {
AddPlayer 0x02 { PlayerSpawn 0x02 {
entity_id: VarInt, entity_id: VarInt,
player_uuid: Uuid, player_uuid: Uuid,
position: Vec3<f64>, position: Vec3<f64>,
@ -616,20 +616,20 @@ pub mod play {
} }
def_struct! { def_struct! {
Animate 0x03 { EntityAnimation 0x03 {
entity_id: VarInt, entity_id: VarInt,
animation: u8, animation: u8,
} }
} }
def_struct! { def_struct! {
BlockChangeAck 0x05 { PlayerActionResponse 0x05 {
sequence: VarInt, sequence: VarInt,
} }
} }
def_struct! { def_struct! {
BlockDestruction 0x06 { BlockBreakingProgress 0x06 {
entity_id: VarInt, entity_id: VarInt,
location: BlockPos, location: BlockPos,
destroy_stage: BoundedInt<u8, 0, 10>, destroy_stage: BoundedInt<u8, 0, 10>,
@ -637,7 +637,7 @@ pub mod play {
} }
def_struct! { def_struct! {
BlockEntityData 0x07 { BlockEntityUpdate 0x07 {
location: BlockPos, location: BlockPos,
kind: VarInt, // TODO: use enum here kind: VarInt, // TODO: use enum here
data: nbt::Blob, data: nbt::Blob,
@ -661,32 +661,32 @@ pub mod play {
} }
def_struct! { def_struct! {
BossEvent 0x0a { BossBar 0x0a {
uuid: Uuid, uuid: Uuid,
action: BossEventAction, action: BossBarAction,
} }
} }
def_enum! { def_enum! {
BossEventAction: VarInt { BossBarAction: VarInt {
Add: BossEventActionAdd = 0, Add: BossBarActionAdd = 0,
// TODO // TODO
} }
} }
def_struct! { def_struct! {
BossEventActionAdd { BossBarActionAdd {
title: Text, title: Text,
health: f32, health: f32,
color: BossEventColor, color: BossBarColor,
division: BossEventDivision, division: BossBarDivision,
/// TODO: bitmask /// TODO: bitmask
flags: u8, flags: u8,
} }
} }
def_enum! { def_enum! {
BossEventColor: VarInt { BossBarColor: VarInt {
Pink = 0, Pink = 0,
Blue = 1, Blue = 1,
Red = 2, Red = 2,
@ -698,7 +698,7 @@ pub mod play {
} }
def_enum! { def_enum! {
BossEventDivision: VarInt { BossBarDivision: VarInt {
NoDivision = 0, NoDivision = 0,
SixNotches = 1, SixNotches = 1,
TenNotches = 2, TenNotches = 2,
@ -708,7 +708,7 @@ pub mod play {
} }
def_struct! { def_struct! {
ChangeDifficulty 0x0b { SetDifficulty 0x0b {
difficulty: Difficulty, difficulty: Difficulty,
locked: bool, locked: bool,
} }
@ -743,21 +743,21 @@ pub mod play {
} }
def_struct! { def_struct! {
ForgetLevelChunk 0x1a { UnloadChunk 0x1a {
chunk_x: i32, chunk_x: i32,
chunk_z: i32 chunk_z: i32
} }
} }
def_struct! { def_struct! {
GameEvent 0x1b { GameStateChange 0x1b {
reason: GameEventReason, reason: GameStateChangeReason,
value: f32, value: f32,
} }
} }
def_enum! { def_enum! {
GameEventReason: u8 { GameStateChangeReason: u8 {
NoRespawnBlockAvailable = 0, NoRespawnBlockAvailable = 0,
EndRaining = 1, EndRaining = 1,
BeginRaining = 2, BeginRaining = 2,
@ -774,7 +774,7 @@ pub mod play {
} }
def_struct! { def_struct! {
InitializeWorldBorder 0x1d { WorldBorderInitialize 0x1d {
x: f64, x: f64,
z: f64, z: f64,
old_diameter: f64, old_diameter: f64,
@ -793,12 +793,12 @@ pub mod play {
} }
def_struct! { def_struct! {
LevelChunkWithLight 0x1f { ChunkData 0x1f {
chunk_x: i32, chunk_x: i32,
chunk_z: i32, chunk_z: i32,
heightmaps: Nbt<LevelChunkHeightmaps>, heightmaps: Nbt<ChunkDataHeightmaps>,
blocks_and_biomes: Vec<u8>, blocks_and_biomes: Vec<u8>,
block_entities: Vec<LevelChunkBlockEntity>, block_entities: Vec<ChunkDataBlockEntity>,
trust_edges: bool, trust_edges: bool,
sky_light_mask: BitVec<u64>, sky_light_mask: BitVec<u64>,
block_light_mask: BitVec<u64>, block_light_mask: BitVec<u64>,
@ -810,13 +810,13 @@ pub mod play {
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct LevelChunkHeightmaps { pub struct ChunkDataHeightmaps {
#[serde(rename = "MOTION_BLOCKING", serialize_with = "nbt::i64_array")] #[serde(rename = "MOTION_BLOCKING", serialize_with = "nbt::i64_array")]
pub motion_blocking: Vec<i64>, pub motion_blocking: Vec<i64>,
} }
def_struct! { def_struct! {
LevelChunkBlockEntity { ChunkDataBlockEntity {
packed_xz: i8, packed_xz: i8,
y: i16, y: i16,
kind: VarInt, kind: VarInt,
@ -825,7 +825,7 @@ pub mod play {
} }
def_struct! { def_struct! {
Login 0x23 { GameJoin 0x23 {
/// Entity ID of the joining player /// Entity ID of the joining player
entity_id: i32, entity_id: i32,
is_hardcore: bool, is_hardcore: bool,
@ -1017,7 +1017,7 @@ pub mod play {
} }
def_struct! { def_struct! {
MoveEntityPosition 0x26 { MoveRelative 0x26 {
entity_id: VarInt, entity_id: VarInt,
delta: Vec3<i16>, delta: Vec3<i16>,
on_ground: bool, on_ground: bool,
@ -1025,7 +1025,7 @@ pub mod play {
} }
def_struct! { def_struct! {
MoveEntityPositionAndRotation 0x27 { RotateAndMoveRelative 0x27 {
entity_id: VarInt, entity_id: VarInt,
delta: Vec3<i16>, delta: Vec3<i16>,
yaw: ByteAngle, yaw: ByteAngle,
@ -1035,7 +1035,7 @@ pub mod play {
} }
def_struct! { def_struct! {
MoveEntityRotation 0x28 { Rotate 0x28 {
entity_id: VarInt, entity_id: VarInt,
yaw: ByteAngle, yaw: ByteAngle,
pitch: ByteAngle, pitch: ByteAngle,
@ -1044,7 +1044,7 @@ pub mod play {
} }
def_struct! { def_struct! {
PlayerChat 0x30 { ChatMessage 0x30 {
message: Text, message: Text,
/// Index into the chat type registry /// Index into the chat type registry
kind: VarInt, kind: VarInt,
@ -1054,8 +1054,8 @@ pub mod play {
} }
def_enum! { def_enum! {
PlayerInfo 0x34: VarInt { UpdatePlayerList 0x34: VarInt {
AddPlayer: Vec<PlayerInfoAddPlayer> = 0, AddPlayer: Vec<PlayerListAddPlayer> = 0,
UpdateGameMode: Vec<(Uuid, GameMode)> = 1, UpdateGameMode: Vec<(Uuid, GameMode)> = 1,
UpdateLatency: Vec<(Uuid, VarInt)> = 2, UpdateLatency: Vec<(Uuid, VarInt)> = 2,
UpdateDisplayName: Vec<(Uuid, Option<Text>)> = 3, UpdateDisplayName: Vec<(Uuid, Option<Text>)> = 3,
@ -1064,7 +1064,7 @@ pub mod play {
} }
def_struct! { def_struct! {
PlayerInfoAddPlayer { PlayerListAddPlayer {
uuid: Uuid, uuid: Uuid,
username: BoundedString<3, 16>, username: BoundedString<3, 16>,
properties: Vec<Property>, properties: Vec<Property>,
@ -1076,18 +1076,18 @@ pub mod play {
} }
def_struct! { def_struct! {
PlayerPosition 0x36 { PlayerPositionLook 0x36 {
position: Vec3<f64>, position: Vec3<f64>,
yaw: f32, yaw: f32,
pitch: f32, pitch: f32,
flags: PlayerPositionFlags, flags: PlayerPositionLookFlags,
teleport_id: VarInt, teleport_id: VarInt,
dismount_vehicle: bool, dismount_vehicle: bool,
} }
} }
def_bitfield! { def_bitfield! {
PlayerPositionFlags: u8 { PlayerPositionLookFlags: u8 {
x = 0, x = 0,
y = 1, y = 1,
z = 2, z = 2,
@ -1097,13 +1097,13 @@ pub mod play {
} }
def_struct! { def_struct! {
RemoveEntities 0x38 { EntitiesDestroy 0x38 {
entities: Vec<VarInt>, entities: Vec<VarInt>,
} }
} }
def_struct! { def_struct! {
Respawn 0x3b { PlayerRespawn 0x3b {
dimension_type_name: Ident, dimension_type_name: Ident,
dimension_name: Ident, dimension_name: Ident,
hashed_seed: u64, hashed_seed: u64,
@ -1117,14 +1117,14 @@ pub mod play {
} }
def_struct! { def_struct! {
RotateHead 0x3c { EntitySetHeadYaw 0x3c {
entity_id: VarInt, entity_id: VarInt,
head_yaw: ByteAngle, head_yaw: ByteAngle,
} }
} }
def_struct! { def_struct! {
SectionBlocksUpdate 0x3d { ChunkSectionUpdate 0x3d {
chunk_section_position: i64, chunk_section_position: i64,
invert_trust_edges: bool, invert_trust_edges: bool,
blocks: Vec<VarLong>, blocks: Vec<VarLong>,
@ -1132,53 +1132,53 @@ pub mod play {
} }
def_struct! { def_struct! {
SetCarriedItem 0x47 { UpdateSelectedSlot 0x47 {
slot: BoundedInt<u8, 0, 9>, slot: BoundedInt<u8, 0, 9>,
} }
} }
def_struct! { def_struct! {
SetChunkCacheCenter 0x48 { ChunkRenderDistanceCenter 0x48 {
chunk_x: VarInt, chunk_x: VarInt,
chunk_z: VarInt, chunk_z: VarInt,
} }
} }
def_struct! { def_struct! {
SetChunkCacheRadius 0x49 { ChunkLoadDistance 0x49 {
view_distance: BoundedInt<VarInt, 2, 32>, view_distance: BoundedInt<VarInt, 2, 32>,
} }
} }
def_struct! { def_struct! {
SpawnPosition 0x4a { PlayerSpawnPosition 0x4a {
location: BlockPos, location: BlockPos,
angle: f32, angle: f32,
} }
} }
def_struct! { def_struct! {
SetEntityMetadata 0x4d { EntityTrackerUpdate 0x4d {
entity_id: VarInt, entity_id: VarInt,
metadata: RawBytes, metadata: RawBytes,
} }
} }
def_struct! { def_struct! {
SetEntityMotion 0x4f { EntityVelocityUpdate 0x4f {
entity_id: VarInt, entity_id: VarInt,
velocity: Vec3<i16>, velocity: Vec3<i16>,
} }
} }
def_struct! { def_struct! {
SetSubtitleText 0x58 { UpdateSubtitle 0x58 {
subtitle_text: Text, subtitle_text: Text,
} }
} }
def_struct! { def_struct! {
SetTime 0x59 { WorldTimeUpdate 0x59 {
/// The age of the world in 1/20ths of a second. /// The age of the world in 1/20ths of a second.
world_age: i64, world_age: i64,
/// The current time of day in 1/20ths of a second. /// The current time of day in 1/20ths of a second.
@ -1189,14 +1189,14 @@ pub mod play {
} }
def_struct! { def_struct! {
SetTitleText 0x5a { UpdateTitle 0x5a {
text: Text, text: Text,
} }
} }
def_struct! { def_struct! {
#[derive(Copy, PartialEq, Eq)] #[derive(Copy, PartialEq, Eq)]
SetTitleAnimationTimes 0x5b { TitleAnimationTimes 0x5b {
/// Ticks to spend fading in. /// Ticks to spend fading in.
fade_in: u32, fade_in: u32,
/// Ticks to keep the title displayed. /// Ticks to keep the title displayed.
@ -1207,7 +1207,7 @@ pub mod play {
} }
def_struct! { def_struct! {
SystemChat 0x5f { GameMessage 0x5f {
chat: Text, chat: Text,
/// Index into the chat type registry. /// Index into the chat type registry.
kind: VarInt, kind: VarInt,
@ -1215,14 +1215,14 @@ pub mod play {
} }
def_struct! { def_struct! {
TabList 0x60 { PlayerListHeaderFooter 0x60 {
header: Text, header: Text,
footer: Text, footer: Text,
} }
} }
def_struct! { def_struct! {
TeleportEntity 0x63 { EntityPosition 0x63 {
entity_id: VarInt, entity_id: VarInt,
position: Vec3<f64>, position: Vec3<f64>,
yaw: ByteAngle, yaw: ByteAngle,
@ -1232,22 +1232,22 @@ pub mod play {
} }
def_struct! { def_struct! {
UpdateAttributes 0x65 { EntityAttributes 0x65 {
entity_id: VarInt, entity_id: VarInt,
properties: Vec<UpdateAttributesProperty>, properties: Vec<EntityAttributesProperty>,
} }
} }
def_struct! { def_struct! {
UpdateAttributesProperty { EntityAttributesProperty {
key: Ident, key: Ident,
value: f64, value: f64,
modifiers: Vec<UpdateAttributesModifiers> modifiers: Vec<EntityAttributesModifiers>
} }
} }
def_struct! { def_struct! {
UpdateAttributesModifiers { EntityAttributesModifiers {
uuid: Uuid, uuid: Uuid,
amount: f64, amount: f64,
operation: u8, operation: u8,
@ -1256,48 +1256,48 @@ pub mod play {
def_packet_group! { def_packet_group! {
S2cPlayPacket { S2cPlayPacket {
AddEntity, EntitySpawn,
AddExperienceOrb, ExperienceOrbSpawn,
AddPlayer, PlayerSpawn,
Animate, EntityAnimation,
BlockChangeAck, PlayerActionResponse,
BlockDestruction, BlockBreakingProgress,
BlockEntityData, BlockEntityUpdate,
BlockEvent, BlockEvent,
BlockUpdate, BlockUpdate,
BossEvent, BossBar,
ClearTitles, ClearTitles,
Disconnect, Disconnect,
EntityStatus, EntityStatus,
ForgetLevelChunk, UnloadChunk,
GameEvent, GameStateChange,
KeepAlive, KeepAlive,
LevelChunkWithLight, ChunkData,
Login, GameJoin,
MoveEntityPosition, MoveRelative,
MoveEntityPositionAndRotation, RotateAndMoveRelative,
MoveEntityRotation, Rotate,
PlayerChat, ChatMessage,
PlayerInfo, UpdatePlayerList,
PlayerPosition, PlayerPositionLook,
RemoveEntities, EntitiesDestroy,
Respawn, PlayerRespawn,
RotateHead, EntitySetHeadYaw,
SectionBlocksUpdate, ChunkSectionUpdate,
SetCarriedItem, UpdateSelectedSlot,
SetChunkCacheCenter, ChunkRenderDistanceCenter,
SetChunkCacheRadius, ChunkLoadDistance,
SpawnPosition, PlayerSpawnPosition,
SetEntityMetadata, EntityTrackerUpdate,
SetEntityMotion, EntityVelocityUpdate,
SetSubtitleText, UpdateSubtitle,
SetTime, WorldTimeUpdate,
SetTitleText, UpdateTitle,
SetTitleAnimationTimes, TitleAnimationTimes,
SystemChat, GameMessage,
TabList, PlayerListHeaderFooter,
TeleportEntity, EntityPosition,
UpdateAttributes, EntityAttributes,
} }
} }
} }
@ -1306,20 +1306,20 @@ pub mod play {
use super::super::*; use super::super::*;
def_struct! { def_struct! {
AcceptTeleportation 0x00 { TeleportConfirm 0x00 {
teleport_id: VarInt teleport_id: VarInt
} }
} }
def_struct! { def_struct! {
BlockEntityTagQuery 0x01 { QueryBlockNbt 0x01 {
transaction_id: VarInt, transaction_id: VarInt,
location: BlockPos, location: BlockPos,
} }
} }
def_enum! { def_enum! {
ChangeDifficulty 0x02: i8 { UpdateDifficulty 0x02: i8 {
Peaceful = 0, Peaceful = 0,
Easy = 1, Easy = 1,
Normal = 2, Normal = 2,
@ -1328,7 +1328,7 @@ pub mod play {
} }
def_struct! { def_struct! {
ChatCommand 0x03 { CommandExecution 0x03 {
command: String, // TODO: bounded? command: String, // TODO: bounded?
// TODO: timestamp, arg signatures // TODO: timestamp, arg signatures
signed_preview: bool, signed_preview: bool,
@ -1336,7 +1336,7 @@ pub mod play {
} }
def_struct! { def_struct! {
Chat 0x04 { ChatMessage 0x04 {
message: BoundedString<0, 256>, message: BoundedString<0, 256>,
timestamp: u64, timestamp: u64,
salt: u64, salt: u64,
@ -1346,14 +1346,14 @@ pub mod play {
} }
def_struct! { def_struct! {
ChatPreview 0x05 { RequestChatPreview 0x05 {
query: i32, // TODO: is this an i32 or a varint? query: i32, // TODO: is this an i32 or a varint?
message: BoundedString<0, 256>, message: BoundedString<0, 256>,
} }
} }
def_enum! { def_enum! {
ClientCommand 0x06: VarInt { ClientStatus 0x06: VarInt {
/// Sent when ready to complete login and ready to respawn after death. /// Sent when ready to complete login and ready to respawn after death.
PerformRespawn = 0, PerformRespawn = 0,
/// Sent when the statistics menu is opened. /// Sent when the statistics menu is opened.
@ -1362,7 +1362,7 @@ pub mod play {
} }
def_struct! { def_struct! {
ClientInformation 0x07 { ClientSettings 0x07 {
/// e.g. en_US /// e.g. en_US
locale: BoundedString<0, 16>, locale: BoundedString<0, 16>,
/// Client-side render distance in chunks. /// Client-side render distance in chunks.
@ -1408,7 +1408,7 @@ pub mod play {
} }
def_struct! { def_struct! {
CommandSuggestion 0x08 { RequestCommandCompletion 0x08 {
transaction_id: VarInt, transaction_id: VarInt,
/// Text behind the cursor without the '/'. /// Text behind the cursor without the '/'.
text: BoundedString<0, 32500> text: BoundedString<0, 32500>
@ -1416,14 +1416,20 @@ pub mod play {
} }
def_struct! { def_struct! {
ContainerButtonClick 0x09 { ButtonClick 0x09 {
window_id: i8, window_id: i8,
button_id: i8, button_id: i8,
} }
} }
def_struct! { def_struct! {
ContainerClose 0x0b { ClickSlot 0x0a {
// TODO
}
}
def_struct! {
CloseHandledScreen 0x0b {
window_id: u8, window_id: u8,
} }
} }
@ -1436,7 +1442,7 @@ pub mod play {
} }
def_struct! { def_struct! {
EditBook 0x0d { BookUpdate 0x0d {
slot: VarInt, slot: VarInt,
entries: Vec<String>, entries: Vec<String>,
title: Option<String>, title: Option<String>,
@ -1444,14 +1450,14 @@ pub mod play {
} }
def_struct! { def_struct! {
EntityTagQuery 0x0e { QueryEntityNbt 0x0e {
transaction_id: VarInt, transaction_id: VarInt,
entity_id: VarInt, entity_id: VarInt,
} }
} }
def_struct! { def_struct! {
Interact 0x0f { PlayerInteractEntity 0x0f {
entity_id: VarInt, entity_id: VarInt,
kind: InteractKind, kind: InteractKind,
sneaking: bool, sneaking: bool,
@ -1489,7 +1495,7 @@ pub mod play {
} }
def_struct! { def_struct! {
LockDifficulty 0x12 { UpdateDifficultyLock 0x12 {
locked: bool locked: bool
} }
} }
@ -1524,7 +1530,7 @@ pub mod play {
} }
def_struct! { def_struct! {
MovePlayerStatusOnly 0x16 { MovePlayerOnGround 0x16 {
on_ground: bool on_ground: bool
} }
} }
@ -1541,20 +1547,20 @@ pub mod play {
} }
def_struct! { def_struct! {
PaddleBoat 0x18 { BoatPaddleState 0x18 {
left_paddle_turning: bool, left_paddle_turning: bool,
right_paddle_turning: bool, right_paddle_turning: bool,
} }
} }
def_struct! { def_struct! {
PickItem 0x19 { PickFromInventory 0x19 {
slot_to_use: VarInt, slot_to_use: VarInt,
} }
} }
def_struct! { def_struct! {
PlaceRecipe 0x1a { CraftRequest 0x1a {
window_id: i8, window_id: i8,
recipe: Ident, recipe: Ident,
make_all: bool, make_all: bool,
@ -1562,7 +1568,7 @@ pub mod play {
} }
def_enum! { def_enum! {
PlayerAbilities 0x1b: i8 { UpdatePlayerAbilities 0x1b: i8 {
NotFlying = 0, NotFlying = 0,
Flying = 0b10, Flying = 0b10,
} }
@ -1645,7 +1651,7 @@ pub mod play {
} }
def_struct! { def_struct! {
Pong 0x1f { PlayPong 0x1f {
id: i32, id: i32,
} }
} }
@ -1680,7 +1686,7 @@ pub mod play {
} }
def_enum! { def_enum! {
ResourcePack 0x23: VarInt { ResourcePackStatus 0x23: VarInt {
SuccessfullyLoaded = 0, SuccessfullyLoaded = 0,
Declined = 1, Declined = 1,
FailedDownload = 2, FailedDownload = 2,
@ -1689,20 +1695,20 @@ pub mod play {
} }
def_enum! { def_enum! {
SeenAdvancements 0x24: VarInt { AdvancementTab 0x24: VarInt {
OpenedTab: Ident = 0, OpenedTab: Ident = 0,
ClosedScreen = 1, ClosedScreen = 1,
} }
} }
def_struct! { def_struct! {
SelectTrade 0x25 { SelectMerchantTrade 0x25 {
selected_slot: VarInt, selected_slot: VarInt,
} }
} }
def_struct! { def_struct! {
SetBeacon 0x26 { UpdateBeacon 0x26 {
// TODO: potion ids // TODO: potion ids
primary_effect: Option<VarInt>, primary_effect: Option<VarInt>,
secondary_effect: Option<VarInt>, secondary_effect: Option<VarInt>,
@ -1710,13 +1716,13 @@ pub mod play {
} }
def_struct! { def_struct! {
SetCarriedItem 0x27 { UpdateSelectedSlot 0x27 {
slot: BoundedInt<i16, 0, 8>, slot: BoundedInt<i16, 0, 8>,
} }
} }
def_struct! { def_struct! {
SetCommandBlock 0x28 { UpdateCommandBlock 0x28 {
location: BlockPos, location: BlockPos,
command: String, command: String,
mode: CommandBlockMode, mode: CommandBlockMode,
@ -1741,7 +1747,7 @@ pub mod play {
} }
def_struct! { def_struct! {
SetCommandBlockMinecart 0x29 { UpdateCommandBlockMinecart 0x29 {
entity_id: VarInt, entity_id: VarInt,
command: String, command: String,
track_output: bool, track_output: bool,
@ -1749,14 +1755,14 @@ pub mod play {
} }
def_struct! { def_struct! {
SetCreativeModeSlot 0x2a { UpdateCreativeModeSlot 0x2a {
slot: i16, slot: i16,
// TODO: clicked_item: Slot, // TODO: clicked_item: Slot,
} }
} }
def_struct! { def_struct! {
SetJigsawBlock 0x2b { UpdateJigsaw 0x2b {
location: BlockPos, location: BlockPos,
name: Ident, name: Ident,
target: Ident, target: Ident,
@ -1767,7 +1773,7 @@ pub mod play {
} }
def_struct! { def_struct! {
SetStructureBlock 0x2c { UpdateStructureBlock 0x2c {
location: BlockPos, location: BlockPos,
action: StructureBlockAction, action: StructureBlockAction,
mode: StructureBlockMode, mode: StructureBlockMode,
@ -1827,26 +1833,26 @@ pub mod play {
} }
def_struct! { def_struct! {
SignUpdate 0x2d { UpdateSign 0x2d {
location: BlockPos, location: BlockPos,
lines: [BoundedString<0, 384>; 4], lines: [BoundedString<0, 384>; 4],
} }
} }
def_struct! { def_struct! {
Swing 0x2e { HandSwing 0x2e {
hand: Hand, hand: Hand,
} }
} }
def_struct! { def_struct! {
TeleportToEntity 0x2f { SpectatorTeleport 0x2f {
target: Uuid, target: Uuid,
} }
} }
def_struct! { def_struct! {
UseItemOn 0x30 { PlayerInteractBlock 0x30 {
hand: Hand, hand: Hand,
location: BlockPos, location: BlockPos,
face: BlockFace, face: BlockFace,
@ -1857,7 +1863,7 @@ pub mod play {
} }
def_struct! { def_struct! {
UseItem 0x31 { PlayerInteractItem 0x31 {
hand: Hand, hand: Hand,
sequence: VarInt, sequence: VarInt,
} }
@ -1865,55 +1871,56 @@ pub mod play {
def_packet_group! { def_packet_group! {
C2sPlayPacket { C2sPlayPacket {
AcceptTeleportation, TeleportConfirm,
BlockEntityTagQuery, QueryBlockNbt,
ChangeDifficulty, UpdateDifficulty,
ChatCommand, CommandExecution,
Chat, ChatMessage,
ChatPreview, RequestChatPreview,
ClientCommand, ClientStatus,
ClientInformation, ClientSettings,
CommandSuggestion, RequestCommandCompletion,
ContainerButtonClick, ButtonClick,
ContainerClose, ClickSlot,
CloseHandledScreen,
CustomPayload, CustomPayload,
EditBook, BookUpdate,
EntityTagQuery, QueryEntityNbt,
Interact, PlayerInteractEntity,
JigsawGenerate, JigsawGenerate,
KeepAlive, KeepAlive,
LockDifficulty, UpdateDifficultyLock,
MovePlayerPosition, MovePlayerPosition,
MovePlayerPositionAndRotation, MovePlayerPositionAndRotation,
MovePlayerRotation, MovePlayerRotation,
MovePlayerStatusOnly, MovePlayerOnGround,
MoveVehicle, MoveVehicle,
PaddleBoat, BoatPaddleState,
PickItem, PickFromInventory,
PlaceRecipe, CraftRequest,
PlayerAbilities, UpdatePlayerAbilities,
PlayerAction, PlayerAction,
PlayerCommand, PlayerCommand,
PlayerInput, PlayerInput,
Pong, PlayPong,
RecipeBookChangeSettings, RecipeBookChangeSettings,
RecipeBookSeenRecipe, RecipeBookSeenRecipe,
RenameItem, RenameItem,
ResourcePack, ResourcePackStatus,
SeenAdvancements, AdvancementTab,
SelectTrade, SelectMerchantTrade,
SetBeacon, UpdateBeacon,
SetCarriedItem, UpdateSelectedSlot,
SetCommandBlock, UpdateCommandBlock,
SetCommandBlockMinecart, UpdateCommandBlockMinecart,
SetCreativeModeSlot, UpdateCreativeModeSlot,
SetJigsawBlock, UpdateJigsaw,
SetStructureBlock, UpdateStructureBlock,
SignUpdate, UpdateSign,
Swing, HandSwing,
TeleportToEntity, SpectatorTeleport,
UseItemOn, PlayerInteractBlock,
UseItem, PlayerInteractItem,
} }
} }
} }

View file

@ -38,11 +38,11 @@ use crate::protocol_inner::packets::handshake::{Handshake, HandshakeNextState};
use crate::protocol_inner::packets::login::c2s::{ use crate::protocol_inner::packets::login::c2s::{
EncryptionResponse, LoginStart, VerifyTokenOrMsgSig, EncryptionResponse, LoginStart, VerifyTokenOrMsgSig,
}; };
use crate::protocol_inner::packets::login::s2c::{EncryptionRequest, LoginSuccess, SetCompression}; use crate::protocol_inner::packets::login::s2c::{EncryptionRequest, LoginSuccess, LoginCompression};
use crate::protocol_inner::packets::play::c2s::C2sPlayPacket; use crate::protocol_inner::packets::play::c2s::C2sPlayPacket;
use crate::protocol_inner::packets::play::s2c::S2cPlayPacket; use crate::protocol_inner::packets::play::s2c::S2cPlayPacket;
use crate::protocol_inner::packets::status::c2s::{PingRequest, StatusRequest}; use crate::protocol_inner::packets::status::c2s::{QueryPing, QueryRequest};
use crate::protocol_inner::packets::status::s2c::{PongResponse, StatusResponse}; use crate::protocol_inner::packets::status::s2c::{QueryPong, QueryResponse};
use crate::protocol_inner::packets::{login, Property}; use crate::protocol_inner::packets::{login, Property};
use crate::protocol_inner::{BoundedArray, BoundedString, VarInt}; use crate::protocol_inner::{BoundedArray, BoundedString, VarInt};
use crate::util::valid_username; use crate::util::valid_username;
@ -552,7 +552,7 @@ async fn handle_status<C: Config>(
c: &mut Codec, c: &mut Codec,
remote_addr: SocketAddr, remote_addr: SocketAddr,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
c.dec.read_packet::<StatusRequest>().await?; c.dec.read_packet::<QueryRequest>().await?;
match server.0.cfg.server_list_ping(&server, remote_addr).await { match server.0.cfg.server_list_ping(&server, remote_addr).await {
ServerListPing::Respond { ServerListPing::Respond {
@ -583,7 +583,7 @@ async fn handle_status<C: Config>(
} }
c.enc c.enc
.write_packet(&StatusResponse { .write_packet(&QueryResponse {
json_response: json.to_string(), json_response: json.to_string(),
}) })
.await?; .await?;
@ -591,9 +591,9 @@ async fn handle_status<C: Config>(
ServerListPing::Ignore => return Ok(()), ServerListPing::Ignore => return Ok(()),
} }
let PingRequest { payload } = c.dec.read_packet().await?; let QueryPing { payload } = c.dec.read_packet().await?;
c.enc.write_packet(&PongResponse { payload }).await?; c.enc.write_packet(&QueryPong { payload }).await?;
Ok(()) Ok(())
} }
@ -705,7 +705,7 @@ async fn handle_login<C: Config>(
let compression_threshold = 256; let compression_threshold = 256;
c.enc c.enc
.write_packet(&SetCompression { .write_packet(&LoginCompression {
threshold: VarInt(compression_threshold as i32), threshold: VarInt(compression_threshold as i32),
}) })
.await?; .await?;
@ -723,7 +723,7 @@ async fn handle_login<C: Config>(
if let Err(reason) = server.0.cfg.login(server, &npd).await { if let Err(reason) = server.0.cfg.login(server, &npd).await {
log::info!("Disconnect at login: \"{reason}\""); log::info!("Disconnect at login: \"{reason}\"");
c.enc c.enc
.write_packet(&login::s2c::Disconnect { reason }) .write_packet(&login::s2c::LoginDisconnect { reason })
.await?; .await?;
return Ok(None); return Ok(None);
} }