Migrating the packets to wiki.vg (#62)

Addresses #56. Migrating all the packet names to wiki.vg's instead of fabric's.
This commit is contained in:
EmperialDev 2022-09-17 06:29:48 +02:00 committed by GitHub
parent 0a75f103aa
commit 419d317736
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 319 additions and 322 deletions

View file

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

View file

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

View file

@ -19,22 +19,23 @@ use crate::config::Config;
use crate::dimension::DimensionId;
use crate::entity::data::Player;
use crate::entity::{
velocity_to_packet_units, Entities, EntityEvent, EntityId, EntityKind, StatusOrAnimation,
self, velocity_to_packet_units, Entities, EntityId, EntityKind, StatusOrAnimation,
};
use crate::ident::Ident;
use crate::player_list::{PlayerListId, PlayerLists};
use crate::player_textures::SignedPlayerTextures;
use crate::protocol::packets::c2s::play::{self, C2sPlayPacket, InteractKind, PlayerCommandId};
pub use crate::protocol::packets::s2c::play::TitleFade;
pub use crate::protocol::packets::s2c::play::SetTitleAnimationTimes;
use crate::protocol::packets::s2c::play::{
BiomeRegistry, ChatTypeRegistry, ChunkLoadDistance, ChunkRenderDistanceCenter, ClearTitles,
DimensionTypeRegistry, DimensionTypeRegistryEntry, Disconnect, EntitiesDestroy,
EntityAnimation, EntityAttributes, EntityAttributesProperty, EntityPosition, EntitySetHeadYaw,
EntityStatus, EntityTrackerUpdate, EntityVelocityUpdate, ExperienceBarUpdate, GameJoin,
GameMessage, GameStateChange, GameStateChangeReason, HealthUpdate, KeepAlive, MoveRelative,
OverlayMessage, PlaySoundId, PlayerActionResponse, PlayerPositionLook, PlayerPositionLookFlags,
PlayerRespawn, PlayerSpawnPosition, RegistryCodec, Rotate, RotateAndMoveRelative,
S2cPlayPacket, SoundCategory, UnloadChunk, UpdateSubtitle, UpdateTitle,
AcknowledgeBlockChange, BiomeRegistry, ChatTypeRegistry, ClearTitles, CustomSoundEffect,
DimensionTypeRegistry, DimensionTypeRegistryEntry, DisconnectPlay, EntityAnimationS2c,
EntityAttributesProperty, EntityEvent, GameEvent, GameStateChangeReason, KeepAliveS2c,
LoginPlay, PlayerPositionLookFlags, RegistryCodec, RemoveEntities, Respawn, S2cPlayPacket,
SetActionBarText, SetCenterChunk, SetDefaultSpawnPosition, SetEntityMetadata,
SetEntityVelocity, SetExperience, SetHeadRotation, SetHealth, SetRenderDistance,
SetSubtitleText, SetTitleText, SoundCategory, SynchronizePlayerPosition, SystemChatMessage,
TeleportEntity, UnloadChunk, UpdateAttributes, UpdateEntityPosition,
UpdateEntityPositionAndRotation, UpdateEntityRotation,
};
use crate::protocol::{BoundedInt, ByteAngle, NbtBridge, RawBytes, VarInt};
use crate::server::{C2sPacketChannels, NewClientData, S2cPlayMessage, SharedServer};
@ -229,7 +230,7 @@ pub struct Client<C: Config> {
bits: ClientBits,
/// The data for the client's own player entity.
player_data: Player,
entity_events: Vec<EntityEvent>,
entity_events: Vec<entity::EntityEvent>,
}
#[bitfield(u16)]
@ -468,7 +469,7 @@ impl<C: Config> Client<C> {
volume: f32,
pitch: f32,
) {
self.send_packet(PlaySoundId {
self.send_packet(CustomSoundEffect {
name,
category,
position: pos.iter().map(|x| *x as i32 * 8).collect(),
@ -488,15 +489,15 @@ impl<C: Config> Client<C> {
&mut self,
title: impl Into<Text>,
subtitle: impl Into<Text>,
animation: impl Into<Option<TitleFade>>,
animation: impl Into<Option<SetTitleAnimationTimes>>,
) {
let title = title.into();
let subtitle = subtitle.into();
self.send_packet(UpdateTitle { text: title });
self.send_packet(SetTitleText { text: title });
if !subtitle.is_empty() {
self.send_packet(UpdateSubtitle {
self.send_packet(SetSubtitleText {
subtitle_text: subtitle,
});
}
@ -550,7 +551,7 @@ impl<C: Config> Client<C> {
/// * `level` - Number above the XP bar.
/// * `total_xp` - TODO.
pub fn set_level(&mut self, bar: f32, level: i32, total_xp: i32) {
self.send_packet(ExperienceBarUpdate {
self.send_packet(SetExperience {
bar,
level: level.into(),
total_xp: total_xp.into(),
@ -566,7 +567,7 @@ impl<C: Config> Client<C> {
/// * `food` - Integer in range `0..=20`.
/// * `food_saturation` - Float in range `0.0..=5.0`.
pub fn set_health_and_food(&mut self, health: f32, food: i32, food_saturation: f32) {
self.send_packet(HealthUpdate {
self.send_packet(SetHealth {
health,
food: food.into(),
food_saturation,
@ -602,7 +603,7 @@ impl<C: Config> Client<C> {
}
/// Pushes an entity event to the queue.
pub fn push_entity_event(&mut self, event: EntityEvent) {
pub fn push_entity_event(&mut self, event: entity::EntityEvent) {
self.entity_events.push(event);
}
@ -654,7 +655,7 @@ impl<C: Config> Client<C> {
let txt = reason.into();
log::info!("disconnecting client '{}': \"{txt}\"", self.username);
self.send_packet(Disconnect { reason: txt });
self.send_packet(DisconnectPlay { reason: txt });
self.send = None;
}
@ -696,7 +697,7 @@ impl<C: Config> Client<C> {
fn handle_serverbound_packet(&mut self, entities: &Entities<C>, pkt: C2sPlayPacket) {
match pkt {
C2sPlayPacket::TeleportConfirm(p) => {
C2sPlayPacket::ConfirmTeleport(p) => {
if self.pending_teleports == 0 {
log::warn!("unexpected teleport confirmation from {}", self.username());
self.disconnect_no_reason();
@ -718,17 +719,17 @@ impl<C: Config> Client<C> {
self.disconnect_no_reason();
}
}
C2sPlayPacket::QueryBlockNbt(_) => {}
C2sPlayPacket::UpdateDifficulty(_) => {}
C2sPlayPacket::QueryBlockEntityTag(_) => {}
C2sPlayPacket::ChangeDifficulty(_) => {}
C2sPlayPacket::MessageAcknowledgment(_) => {}
C2sPlayPacket::CommandExecution(_) => {}
C2sPlayPacket::ChatCommand(_) => {}
C2sPlayPacket::ChatMessage(p) => self.events.push_back(ClientEvent::ChatMessage {
message: p.message.0,
timestamp: Duration::from_millis(p.timestamp),
}),
C2sPlayPacket::RequestChatPreview(_) => {}
C2sPlayPacket::ClientStatus(_) => {}
C2sPlayPacket::ClientSettings(p) => {
C2sPlayPacket::ChatPreviewC2s(_) => {}
C2sPlayPacket::ClientCommand(_) => {}
C2sPlayPacket::ClientInformation(p) => {
self.events.push_back(ClientEvent::SettingsChanged {
locale: p.locale.0,
view_distance: p.view_distance.0,
@ -739,14 +740,14 @@ impl<C: Config> Client<C> {
allow_server_listings: p.allow_server_listings,
})
}
C2sPlayPacket::RequestCommandCompletion(_) => {}
C2sPlayPacket::CommandSuggestionsRequest(_) => {}
C2sPlayPacket::ClickContainerButton(_) => {}
C2sPlayPacket::ClickContainer(_) => {}
C2sPlayPacket::CloseHandledScreen(_) => {}
C2sPlayPacket::CustomPayload(_) => {}
C2sPlayPacket::BookUpdate(_) => {}
C2sPlayPacket::QueryEntityNbt(_) => {}
C2sPlayPacket::PlayerInteractEntity(p) => {
C2sPlayPacket::CloseContainerC2s(_) => {}
C2sPlayPacket::PluginMessageC2s(_) => {}
C2sPlayPacket::EditBook(_) => {}
C2sPlayPacket::QueryEntityTag(_) => {}
C2sPlayPacket::Interact(p) => {
if let Some(id) = entities.get_with_network_id(p.entity_id.0) {
self.events.push_back(ClientEvent::InteractWithEntity {
id,
@ -762,7 +763,7 @@ impl<C: Config> Client<C> {
}
}
C2sPlayPacket::JigsawGenerate(_) => {}
C2sPlayPacket::KeepAlive(p) => {
C2sPlayPacket::KeepAliveC2s(p) => {
let last_keepalive_id = self.last_keepalive_id;
if self.bits.got_keepalive() {
log::warn!("unexpected keepalive from player {}", self.username());
@ -779,8 +780,8 @@ impl<C: Config> Client<C> {
self.bits.set_got_keepalive(true);
}
}
C2sPlayPacket::UpdateDifficultyLock(_) => {}
C2sPlayPacket::MovePlayerPosition(p) => {
C2sPlayPacket::LockDifficulty(_) => {}
C2sPlayPacket::SetPlayerPosition(p) => {
if self.pending_teleports == 0 {
self.position = p.position;
@ -790,7 +791,7 @@ impl<C: Config> Client<C> {
});
}
}
C2sPlayPacket::MovePlayerPositionAndRotation(p) => {
C2sPlayPacket::SetPlayerPositionAndRotation(p) => {
if self.pending_teleports == 0 {
self.position = p.position;
self.yaw = p.yaw;
@ -804,7 +805,7 @@ impl<C: Config> Client<C> {
});
}
}
C2sPlayPacket::MovePlayerRotation(p) => {
C2sPlayPacket::SetPlayerRotation(p) => {
if self.pending_teleports == 0 {
self.yaw = p.yaw;
self.pitch = p.pitch;
@ -816,14 +817,14 @@ impl<C: Config> Client<C> {
});
}
}
C2sPlayPacket::MovePlayerOnGround(p) => {
C2sPlayPacket::SetPlayerOnGround(p) => {
if self.pending_teleports == 0 {
self.events.push_back(ClientEvent::MoveOnGround {
on_ground: p.on_ground,
});
}
}
C2sPlayPacket::MoveVehicle(p) => {
C2sPlayPacket::MoveVehicleC2s(p) => {
if self.pending_teleports == 0 {
self.position = p.position;
self.yaw = p.yaw;
@ -836,15 +837,15 @@ impl<C: Config> Client<C> {
});
}
}
C2sPlayPacket::BoatPaddleState(p) => {
C2sPlayPacket::PaddleBoat(p) => {
self.events.push_back(ClientEvent::SteerBoat {
left_paddle_turning: p.left_paddle_turning,
right_paddle_turning: p.right_paddle_turning,
});
}
C2sPlayPacket::PickFromInventory(_) => {}
C2sPlayPacket::CraftRequest(_) => {}
C2sPlayPacket::UpdatePlayerAbilities(_) => {}
C2sPlayPacket::PickItem(_) => {}
C2sPlayPacket::PlaceRecipe(_) => {}
C2sPlayPacket::PlayerAbilitiesC2s(_) => {}
C2sPlayPacket::PlayerAction(p) => {
if p.sequence.0 != 0 {
self.dug_blocks.push(p.sequence.0);
@ -888,34 +889,32 @@ impl<C: Config> Client<C> {
});
}
C2sPlayPacket::PlayerInput(_) => {}
C2sPlayPacket::PlayPong(_) => {}
C2sPlayPacket::RecipeBookChangeSettings(_) => {}
C2sPlayPacket::RecipeBookSeenRecipe(_) => {}
C2sPlayPacket::PongPlay(_) => {}
C2sPlayPacket::ChangeRecipeBookSettings(_) => {}
C2sPlayPacket::SetSeenRecipe(_) => {}
C2sPlayPacket::RenameItem(_) => {}
C2sPlayPacket::ResourcePackStatus(_) => {}
C2sPlayPacket::AdvancementTab(_) => {}
C2sPlayPacket::SelectMerchantTrade(_) => {}
C2sPlayPacket::UpdateBeacon(_) => {}
C2sPlayPacket::UpdateSelectedSlot(_) => {}
C2sPlayPacket::UpdateCommandBlock(_) => {}
C2sPlayPacket::UpdateCommandBlockMinecart(_) => {}
C2sPlayPacket::UpdateCreativeModeSlot(_) => {}
C2sPlayPacket::UpdateJigsaw(_) => {}
C2sPlayPacket::UpdateStructureBlock(_) => {}
C2sPlayPacket::ResourcePackC2s(_) => {}
C2sPlayPacket::SeenAdvancements(_) => {}
C2sPlayPacket::SelectTrade(_) => {}
C2sPlayPacket::SetBeaconEffect(_) => {}
C2sPlayPacket::SetHeldItemS2c(_) => {}
C2sPlayPacket::ProgramCommandBlock(_) => {}
C2sPlayPacket::ProgramCommandBlockMinecart(_) => {}
C2sPlayPacket::SetCreativeModeSlot(_) => {}
C2sPlayPacket::ProgramJigsawBlock(_) => {}
C2sPlayPacket::ProgramStructureBlock(_) => {}
C2sPlayPacket::UpdateSign(_) => {}
C2sPlayPacket::HandSwing(p) => self.events.push_back(ClientEvent::ArmSwing(p.hand)),
C2sPlayPacket::SpectatorTeleport(_) => {}
C2sPlayPacket::PlayerInteractBlock(p) => {
self.events.push_back(ClientEvent::InteractWithBlock {
hand: p.hand,
location: p.location,
face: p.face,
cursor_pos: p.cursor_pos,
head_inside_block: p.head_inside_block,
sequence: p.sequence,
})
}
C2sPlayPacket::PlayerInteractItem(_) => {}
C2sPlayPacket::SwingArm(p) => self.events.push_back(ClientEvent::ArmSwing(p.hand)),
C2sPlayPacket::TeleportToEntity(_) => {}
C2sPlayPacket::UseItemOn(p) => self.events.push_back(ClientEvent::InteractWithBlock {
hand: p.hand,
location: p.location,
face: p.face,
cursor_pos: p.cursor_pos,
head_inside_block: p.head_inside_block,
sequence: p.sequence,
}),
C2sPlayPacket::UseItem(_) => {}
}
}
@ -965,7 +964,7 @@ impl<C: Config> Client<C> {
dimension_names.push(ident!("{LIBRARY_NAMESPACE}:dummy_dimension"));
self.send_packet(GameJoin {
self.send_packet(LoginPlay {
entity_id: 0, // EntityId 0 is reserved for clients.
is_hardcore: self.bits.hardcore(),
gamemode: self.new_game_mode,
@ -1002,7 +1001,7 @@ impl<C: Config> Client<C> {
// Client bug workaround: send the client to a dummy dimension first.
// TODO: is there actually a bug?
self.send_packet(PlayerRespawn {
self.send_packet(Respawn {
dimension_type_name: ident!("{LIBRARY_NAMESPACE}:dimension_type_0"),
dimension_name: ident!("{LIBRARY_NAMESPACE}:dummy_dimension"),
hashed_seed: 0,
@ -1014,7 +1013,7 @@ impl<C: Config> Client<C> {
last_death_location: None,
});
self.send_packet(PlayerRespawn {
self.send_packet(Respawn {
dimension_type_name: ident!(
"{LIBRARY_NAMESPACE}:dimension_type_{}",
world.meta.dimension().0
@ -1040,7 +1039,7 @@ impl<C: Config> Client<C> {
// Update game mode
if self.old_game_mode != self.new_game_mode {
self.old_game_mode = self.new_game_mode;
self.send_packet(GameStateChange {
self.send_packet(GameEvent {
reason: GameStateChangeReason::ChangeGameMode,
value: self.new_game_mode as i32 as f32,
});
@ -1075,7 +1074,7 @@ impl<C: Config> Client<C> {
if self.bits.attack_speed_modified() {
self.bits.set_attack_speed_modified(false);
self.send_packet(EntityAttributes {
self.send_packet(UpdateAttributes {
entity_id: VarInt(0),
properties: vec![EntityAttributesProperty {
key: ident!("generic.attack_speed"),
@ -1088,7 +1087,7 @@ impl<C: Config> Client<C> {
if self.bits.movement_speed_modified() {
self.bits.set_movement_speed_modified(false);
self.send_packet(EntityAttributes {
self.send_packet(UpdateAttributes {
entity_id: VarInt(0),
properties: vec![EntityAttributesProperty {
key: ident!("generic.movement_speed"),
@ -1102,7 +1101,7 @@ impl<C: Config> Client<C> {
if self.bits.modified_spawn_position() {
self.bits.set_modified_spawn_position(false);
self.send_packet(PlayerSpawnPosition {
self.send_packet(SetDefaultSpawnPosition {
location: self.spawn_position,
angle: self.spawn_position_yaw,
})
@ -1113,7 +1112,7 @@ impl<C: Config> Client<C> {
self.bits.set_view_distance_modified(false);
if !self.created_this_tick() {
self.send_packet(ChunkLoadDistance {
self.send_packet(SetRenderDistance {
view_distance: BoundedInt(VarInt(self.view_distance() as i32)),
});
}
@ -1123,7 +1122,7 @@ impl<C: Config> Client<C> {
if current_tick % (shared.tick_rate() * 8) == 0 {
if self.bits.got_keepalive() {
let id = rand::random();
self.send_packet(KeepAlive { id });
self.send_packet(KeepAliveS2c { id });
self.last_keepalive_id = id;
self.bits.set_got_keepalive(false);
} else {
@ -1144,7 +1143,7 @@ impl<C: Config> Client<C> {
let new_section = self.position.map(|n| (n / 16.0).floor() as i32);
if old_section != new_section {
self.send_packet(ChunkRenderDistanceCenter {
self.send_packet(SetCenterChunk {
chunk_x: VarInt(new_section.x),
chunk_z: VarInt(new_section.z),
})
@ -1195,7 +1194,7 @@ impl<C: Config> Client<C> {
for seq in self.dug_blocks.drain(..) {
send_packet(
&mut self.send,
PlayerActionResponse {
AcknowledgeBlockChange {
sequence: VarInt(seq),
},
)
@ -1208,7 +1207,7 @@ impl<C: Config> Client<C> {
if self.bits.teleported_this_tick() {
self.bits.set_teleported_this_tick(false);
self.send_packet(PlayerPositionLook {
self.send_packet(SynchronizePlayerPosition {
position: self.position,
yaw: self.yaw,
pitch: self.pitch,
@ -1233,7 +1232,7 @@ impl<C: Config> Client<C> {
if self.bits.velocity_modified() {
self.bits.set_velocity_modified(false);
self.send_packet(EntityVelocityUpdate {
self.send_packet(SetEntityVelocity {
entity_id: VarInt(0),
velocity: velocity_to_packet_units(self.velocity),
});
@ -1243,7 +1242,7 @@ impl<C: Config> Client<C> {
for msg in self.msgs_to_send.drain(..) {
send_packet(
&mut self.send,
GameMessage {
SystemChatMessage {
chat: msg,
kind: VarInt(0),
},
@ -1251,7 +1250,7 @@ impl<C: Config> Client<C> {
}
if let Some(bar) = self.bar_to_send.take() {
send_packet(&mut self.send, OverlayMessage { text: bar });
send_packet(&mut self.send, SetActionBarText { text: bar });
}
let mut entities_to_unload = Vec::new();
@ -1276,7 +1275,7 @@ impl<C: Config> Client<C> {
{
send_packet(
&mut self.send,
RotateAndMoveRelative {
UpdateEntityPositionAndRotation {
entity_id: VarInt(id.to_network_id()),
delta: (position_delta * 4096.0).as_(),
yaw: ByteAngle::from_degrees(entity.yaw()),
@ -1288,7 +1287,7 @@ impl<C: Config> Client<C> {
if entity.position() != entity.old_position() && !needs_teleport {
send_packet(
&mut self.send,
MoveRelative {
UpdateEntityPosition {
entity_id: VarInt(id.to_network_id()),
delta: (position_delta * 4096.0).as_(),
on_ground: entity.on_ground(),
@ -1299,7 +1298,7 @@ impl<C: Config> Client<C> {
if flags.yaw_or_pitch_modified() {
send_packet(
&mut self.send,
Rotate {
UpdateEntityRotation {
entity_id: VarInt(id.to_network_id()),
yaw: ByteAngle::from_degrees(entity.yaw()),
pitch: ByteAngle::from_degrees(entity.pitch()),
@ -1312,7 +1311,7 @@ impl<C: Config> Client<C> {
if needs_teleport {
send_packet(
&mut self.send,
EntityPosition {
TeleportEntity {
entity_id: VarInt(id.to_network_id()),
position: entity.position(),
yaw: ByteAngle::from_degrees(entity.yaw()),
@ -1325,7 +1324,7 @@ impl<C: Config> Client<C> {
if flags.velocity_modified() {
send_packet(
&mut self.send,
EntityVelocityUpdate {
SetEntityVelocity {
entity_id: VarInt(id.to_network_id()),
velocity: velocity_to_packet_units(entity.velocity()),
},
@ -1335,7 +1334,7 @@ impl<C: Config> Client<C> {
if flags.head_yaw_modified() {
send_packet(
&mut self.send,
EntitySetHeadYaw {
SetHeadRotation {
entity_id: VarInt(id.to_network_id()),
head_yaw: ByteAngle::from_degrees(entity.head_yaw()),
},
@ -1353,7 +1352,7 @@ impl<C: Config> Client<C> {
});
if !entities_to_unload.is_empty() {
self.send_packet(EntitiesDestroy {
self.send_packet(RemoveEntities {
entities: entities_to_unload,
});
}
@ -1365,7 +1364,7 @@ impl<C: Config> Client<C> {
if !data.is_empty() {
data.push(0xff);
self.send_packet(EntityTrackerUpdate {
self.send_packet(SetEntityMetadata {
entity_id: VarInt(0),
metadata: RawBytes(data),
});
@ -1428,19 +1427,19 @@ fn send_packet(send_opt: &mut SendOpt, pkt: impl Into<S2cPlayMessage>) {
}
}
fn send_entity_events(send_opt: &mut SendOpt, entity_id: i32, events: &[EntityEvent]) {
fn send_entity_events(send_opt: &mut SendOpt, entity_id: i32, events: &[entity::EntityEvent]) {
for &event in events {
match event.status_or_animation() {
StatusOrAnimation::Status(code) => send_packet(
send_opt,
EntityStatus {
EntityEvent {
entity_id,
entity_status: code,
},
),
StatusOrAnimation::Animation(code) => send_packet(
send_opt,
EntityAnimation {
EntityAnimationS2c {
entity_id: VarInt(entity_id),
animation: code,
},

View file

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

View file

@ -10,7 +10,7 @@ use crate::client::GameMode;
use crate::config::Config;
use crate::player_textures::SignedPlayerTextures;
use crate::protocol::packets::s2c::play::{
PlayerListAddPlayer, PlayerListHeaderFooter, S2cPlayPacket, UpdatePlayerList,
PlayerInfo, PlayerListAddPlayer, S2cPlayPacket, SetTabListHeaderAndFooter,
};
use crate::protocol::packets::Property;
use crate::protocol::VarInt;
@ -258,12 +258,12 @@ impl<C: Config> PlayerList<C> {
.collect();
if !add_player.is_empty() {
push_packet(UpdatePlayerList::AddPlayer(add_player).into());
push_packet(PlayerInfo::AddPlayer(add_player).into());
}
if self.header != Text::default() || self.footer != Text::default() {
push_packet(
PlayerListHeaderFooter {
SetTabListHeaderAndFooter {
header: self.header.clone(),
footer: self.footer.clone(),
}
@ -274,9 +274,7 @@ impl<C: Config> PlayerList<C> {
pub(crate) fn update_packets(&self, mut push_packet: impl FnMut(S2cPlayPacket)) {
if !self.removed.is_empty() {
push_packet(
UpdatePlayerList::RemovePlayer(self.removed.iter().cloned().collect()).into(),
);
push_packet(PlayerInfo::RemovePlayer(self.removed.iter().cloned().collect()).into());
}
let mut add_player = Vec::new();
@ -322,24 +320,24 @@ impl<C: Config> PlayerList<C> {
}
if !add_player.is_empty() {
push_packet(UpdatePlayerList::AddPlayer(add_player).into());
push_packet(PlayerInfo::AddPlayer(add_player).into());
}
if !game_mode.is_empty() {
push_packet(UpdatePlayerList::UpdateGameMode(game_mode).into());
push_packet(PlayerInfo::UpdateGameMode(game_mode).into());
}
if !ping.is_empty() {
push_packet(UpdatePlayerList::UpdateLatency(ping).into());
push_packet(PlayerInfo::UpdateLatency(ping).into());
}
if !display_name.is_empty() {
push_packet(UpdatePlayerList::UpdateDisplayName(display_name).into());
push_packet(PlayerInfo::UpdateDisplayName(display_name).into());
}
if self.modified_header_or_footer {
push_packet(
PlayerListHeaderFooter {
SetTabListHeaderAndFooter {
header: self.header.clone(),
footer: self.footer.clone(),
}
@ -349,7 +347,7 @@ impl<C: Config> PlayerList<C> {
}
pub(crate) fn clear_packets(&self, mut push_packet: impl FnMut(S2cPlayPacket)) {
push_packet(UpdatePlayerList::RemovePlayer(self.entries.keys().cloned().collect()).into());
push_packet(PlayerInfo::RemovePlayer(self.entries.keys().cloned().collect()).into());
}
}

View file

@ -32,19 +32,19 @@ pub mod status {
use super::*;
def_struct! {
QueryRequest {}
StatusRequest {}
}
def_struct! {
QueryPing {
PingRequest {
payload: u64
}
}
def_packet_group! {
C2sStatusPacket {
QueryRequest = 0,
QueryPing = 1,
StatusRequest = 0,
PingRequest = 1,
}
}
}
@ -101,20 +101,20 @@ pub mod play {
use super::*;
def_struct! {
TeleportConfirm {
ConfirmTeleport {
teleport_id: VarInt
}
}
def_struct! {
QueryBlockNbt {
QueryBlockEntityTag {
transaction_id: VarInt,
location: BlockPos,
}
}
def_enum! {
UpdateDifficulty: i8 {
ChangeDifficulty: i8 {
Peaceful = 0,
Easy = 1,
Normal = 2,
@ -150,7 +150,7 @@ pub mod play {
}
def_struct! {
CommandExecution {
ChatCommand {
command: BoundedString<0, 256>,
timestamp: u64,
salt: u64,
@ -172,14 +172,14 @@ pub mod play {
}
def_struct! {
RequestChatPreview {
ChatPreviewC2s {
query: i32, // TODO: is this an i32 or a varint?
message: BoundedString<0, 256>,
}
}
def_enum! {
ClientStatus: VarInt {
ClientCommand: VarInt {
/// Sent when ready to complete login and ready to respawn after death.
PerformRespawn = 0,
/// Sent when the statistics menu is opened.
@ -188,7 +188,7 @@ pub mod play {
}
def_struct! {
ClientSettings {
ClientInformation {
/// e.g. en_US
locale: BoundedString<0, 16>,
/// Client-side render distance in chunks.
@ -234,7 +234,7 @@ pub mod play {
}
def_struct! {
RequestCommandCompletion {
CommandSuggestionsRequest {
transaction_id: VarInt,
/// Text behind the cursor without the '/'.
text: BoundedString<0, 32500>
@ -271,20 +271,20 @@ pub mod play {
}
def_struct! {
CloseHandledScreen {
CloseContainerC2s {
window_id: u8,
}
}
def_struct! {
CustomPayload {
PluginMessageC2s {
channel: Ident,
data: RawBytes,
}
}
def_struct! {
BookUpdate {
EditBook {
slot: VarInt,
entries: Vec<String>,
title: Option<String>,
@ -292,14 +292,14 @@ pub mod play {
}
def_struct! {
QueryEntityNbt {
QueryEntityTag {
transaction_id: VarInt,
entity_id: VarInt,
}
}
def_struct! {
PlayerInteractEntity {
Interact {
entity_id: VarInt,
kind: InteractKind,
sneaking: bool,
@ -331,26 +331,26 @@ pub mod play {
}
def_struct! {
KeepAlive {
KeepAliveC2s {
id: i64,
}
}
def_struct! {
UpdateDifficultyLock {
LockDifficulty {
locked: bool
}
}
def_struct! {
MovePlayerPosition {
SetPlayerPosition {
position: Vec3<f64>,
on_ground: bool,
}
}
def_struct! {
MovePlayerPositionAndRotation {
SetPlayerPositionAndRotation {
// Absolute position
position: Vec3<f64>,
/// Absolute rotation on X axis in degrees.
@ -362,7 +362,7 @@ pub mod play {
}
def_struct! {
MovePlayerRotation {
SetPlayerRotation {
/// Absolute rotation on X axis in degrees.
yaw: f32,
/// Absolute rotation on Y axis in degrees.
@ -372,13 +372,13 @@ pub mod play {
}
def_struct! {
MovePlayerOnGround {
SetPlayerOnGround {
on_ground: bool
}
}
def_struct! {
MoveVehicle {
MoveVehicleC2s {
/// Absolute position
position: Vec3<f64>,
/// Degrees
@ -389,20 +389,20 @@ pub mod play {
}
def_struct! {
BoatPaddleState {
PaddleBoat {
left_paddle_turning: bool,
right_paddle_turning: bool,
}
}
def_struct! {
PickFromInventory {
PickItem {
slot_to_use: VarInt,
}
}
def_struct! {
CraftRequest {
PlaceRecipe {
window_id: i8,
recipe: Ident,
make_all: bool,
@ -410,7 +410,7 @@ pub mod play {
}
def_enum! {
UpdatePlayerAbilities: i8 {
PlayerAbilitiesC2s: i8 {
NotFlying = 0,
Flying = 0b10,
}
@ -493,13 +493,13 @@ pub mod play {
}
def_struct! {
PlayPong {
PongPlay {
id: i32,
}
}
def_struct! {
RecipeBookChangeSettings {
ChangeRecipeBookSettings {
book_id: RecipeBookId,
book_open: bool,
filter_active: bool,
@ -516,7 +516,7 @@ pub mod play {
}
def_struct! {
RecipeBookSeenRecipe {
SetSeenRecipe {
recipe_id: Ident,
}
}
@ -528,7 +528,7 @@ pub mod play {
}
def_enum! {
ResourcePackStatus: VarInt {
ResourcePackC2s: VarInt {
SuccessfullyLoaded = 0,
Declined = 1,
FailedDownload = 2,
@ -537,20 +537,20 @@ pub mod play {
}
def_enum! {
AdvancementTab: VarInt {
SeenAdvancements: VarInt {
OpenedTab: Ident = 0,
ClosedScreen = 1,
}
}
def_struct! {
SelectMerchantTrade {
SelectTrade {
selected_slot: VarInt,
}
}
def_struct! {
UpdateBeacon {
SetBeaconEffect {
// TODO: potion ids
primary_effect: Option<VarInt>,
secondary_effect: Option<VarInt>,
@ -558,13 +558,13 @@ pub mod play {
}
def_struct! {
UpdateSelectedSlot {
SetHeldItemS2c {
slot: BoundedInt<i16, 0, 8>,
}
}
def_struct! {
UpdateCommandBlock {
ProgramCommandBlock {
location: BlockPos,
command: String,
mode: CommandBlockMode,
@ -589,7 +589,7 @@ pub mod play {
}
def_struct! {
UpdateCommandBlockMinecart {
ProgramCommandBlockMinecart {
entity_id: VarInt,
command: String,
track_output: bool,
@ -597,14 +597,14 @@ pub mod play {
}
def_struct! {
UpdateCreativeModeSlot {
SetCreativeModeSlot {
slot: i16,
clicked_item: Slot,
}
}
def_struct! {
UpdateJigsaw {
ProgramJigsawBlock {
location: BlockPos,
name: Ident,
target: Ident,
@ -615,7 +615,7 @@ pub mod play {
}
def_struct! {
UpdateStructureBlock {
ProgramStructureBlock {
location: BlockPos,
action: StructureBlockAction,
mode: StructureBlockMode,
@ -682,19 +682,19 @@ pub mod play {
}
def_struct! {
HandSwing {
SwingArm {
hand: Hand,
}
}
def_struct! {
SpectatorTeleport {
TeleportToEntity {
target: Uuid,
}
}
def_struct! {
PlayerInteractBlock {
UseItemOn {
hand: Hand,
location: BlockPos,
face: BlockFace,
@ -705,7 +705,7 @@ pub mod play {
}
def_struct! {
PlayerInteractItem {
UseItem {
hand: Hand,
sequence: VarInt,
}
@ -713,57 +713,57 @@ pub mod play {
def_packet_group! {
C2sPlayPacket {
TeleportConfirm = 0,
QueryBlockNbt = 1,
UpdateDifficulty = 2,
ConfirmTeleport = 0,
QueryBlockEntityTag = 1,
ChangeDifficulty = 2,
MessageAcknowledgment = 3,
CommandExecution = 4,
ChatCommand = 4,
ChatMessage = 5,
RequestChatPreview = 6,
ClientStatus = 7,
ClientSettings = 8,
RequestCommandCompletion = 9,
ChatPreviewC2s = 6,
ClientCommand = 7,
ClientInformation = 8,
CommandSuggestionsRequest = 9,
ClickContainerButton = 10,
ClickContainer = 11,
CloseHandledScreen = 12,
CustomPayload = 13,
BookUpdate = 14,
QueryEntityNbt = 15,
PlayerInteractEntity = 16,
CloseContainerC2s = 12,
PluginMessageC2s = 13,
EditBook = 14,
QueryEntityTag = 15,
Interact = 16,
JigsawGenerate = 17,
KeepAlive = 18,
UpdateDifficultyLock = 19,
MovePlayerPosition = 20,
MovePlayerPositionAndRotation = 21,
MovePlayerRotation = 22,
MovePlayerOnGround = 23,
MoveVehicle = 24,
BoatPaddleState = 25,
PickFromInventory = 26,
CraftRequest = 27,
UpdatePlayerAbilities = 28,
KeepAliveC2s = 18,
LockDifficulty = 19,
SetPlayerPosition = 20,
SetPlayerPositionAndRotation = 21,
SetPlayerRotation = 22,
SetPlayerOnGround = 23,
MoveVehicleC2s = 24,
PaddleBoat = 25,
PickItem = 26,
PlaceRecipe = 27,
PlayerAbilitiesC2s = 28,
PlayerAction = 29,
PlayerCommand = 30,
PlayerInput = 31,
PlayPong = 32,
RecipeBookChangeSettings = 33,
RecipeBookSeenRecipe = 34,
PongPlay = 32,
ChangeRecipeBookSettings = 33,
SetSeenRecipe = 34,
RenameItem = 35,
ResourcePackStatus = 36,
AdvancementTab = 37,
SelectMerchantTrade = 38,
UpdateBeacon = 39,
UpdateSelectedSlot = 40,
UpdateCommandBlock = 41,
UpdateCommandBlockMinecart = 42,
UpdateCreativeModeSlot = 43,
UpdateJigsaw = 44,
UpdateStructureBlock = 45,
ResourcePackC2s = 36,
SeenAdvancements = 37,
SelectTrade = 38,
SetBeaconEffect = 39,
SetHeldItemS2c = 40,
ProgramCommandBlock = 41,
ProgramCommandBlockMinecart = 42,
SetCreativeModeSlot = 43,
ProgramJigsawBlock = 44,
ProgramStructureBlock = 45,
UpdateSign = 46,
HandSwing = 47,
SpectatorTeleport = 48,
PlayerInteractBlock = 49,
PlayerInteractItem = 50,
SwingArm = 47,
TeleportToEntity = 48,
UseItemOn = 49,
UseItem = 50,
}
}
}

View file

@ -6,13 +6,13 @@ pub mod status {
use super::*;
def_struct! {
QueryResponse {
StatusResponse {
json_response: String
}
}
def_struct! {
QueryPong {
PingResponse {
/// Should be the same as the payload from ping.
payload: u64
}
@ -20,8 +20,8 @@ pub mod status {
def_packet_group! {
S2cStatusPacket {
QueryResponse = 0,
QueryPong = 1,
StatusResponse = 0,
PingResponse = 1,
}
}
}
@ -30,7 +30,7 @@ pub mod login {
use super::*;
def_struct! {
LoginDisconnect {
DisconnectLogin {
reason: Text,
}
}
@ -54,7 +54,7 @@ pub mod login {
}
def_struct! {
LoginCompression {
SetCompression {
threshold: VarInt
}
}
@ -69,10 +69,10 @@ pub mod login {
def_packet_group! {
S2cLoginPacket {
LoginDisconnect = 0,
DisconnectLogin = 0,
EncryptionRequest = 1,
LoginSuccess = 2,
LoginCompression = 3,
SetCompression = 3,
LoginPluginRequest = 4,
}
}
@ -82,7 +82,7 @@ pub mod play {
use super::*;
def_struct! {
EntitySpawn {
SpawnEntity {
entity_id: VarInt,
object_uuid: Uuid,
kind: VarInt,
@ -96,7 +96,7 @@ pub mod play {
}
def_struct! {
ExperienceOrbSpawn {
SpawnExperienceOrb {
entity_id: VarInt,
position: Vec3<f64>,
count: i16,
@ -104,7 +104,7 @@ pub mod play {
}
def_struct! {
PlayerSpawn {
SpawnPlayer {
entity_id: VarInt,
player_uuid: Uuid,
position: Vec3<f64>,
@ -114,20 +114,20 @@ pub mod play {
}
def_struct! {
EntityAnimation {
EntityAnimationS2c {
entity_id: VarInt,
animation: u8,
}
}
def_struct! {
PlayerActionResponse {
AcknowledgeBlockChange {
sequence: VarInt,
}
}
def_struct! {
BlockBreakingProgress {
SetBlockDestroyStage {
entity_id: VarInt,
location: BlockPos,
destroy_stage: BoundedInt<u8, 0, 10>,
@ -135,7 +135,7 @@ pub mod play {
}
def_struct! {
BlockEntityUpdate {
BlockEntityData {
location: BlockPos,
kind: VarInt, // TODO: use enum here
data: Compound,
@ -143,7 +143,7 @@ pub mod play {
}
def_struct! {
BlockEvent {
BlockAction {
location: BlockPos,
action_id: u8,
action_param: u8,
@ -276,7 +276,7 @@ pub mod play {
}
def_struct! {
PlaySoundId {
CustomSoundEffect {
name: Ident,
category: SoundCategory,
position: Vec3<i32>,
@ -287,13 +287,13 @@ pub mod play {
}
def_struct! {
Disconnect {
DisconnectPlay {
reason: Text,
}
}
def_struct! {
EntityStatus {
EntityEvent {
entity_id: i32,
entity_status: u8,
}
@ -307,7 +307,7 @@ pub mod play {
}
def_struct! {
GameStateChange {
GameEvent {
reason: GameStateChangeReason,
value: f32,
}
@ -344,13 +344,13 @@ pub mod play {
}
def_struct! {
KeepAlive {
KeepAliveS2c {
id: i64,
}
}
def_struct! {
ChunkData {
ChunkDataAndUpdateLight {
chunk_x: i32,
chunk_z: i32,
heightmaps: NbtBridge<ChunkDataHeightmaps>,
@ -382,7 +382,7 @@ pub mod play {
}
def_struct! {
GameJoin {
LoginPlay {
/// Entity ID of the joining player
entity_id: i32,
is_hardcore: bool,
@ -574,7 +574,7 @@ pub mod play {
}
def_struct! {
MoveRelative {
UpdateEntityPosition {
entity_id: VarInt,
delta: Vec3<i16>,
on_ground: bool,
@ -582,7 +582,7 @@ pub mod play {
}
def_struct! {
RotateAndMoveRelative {
UpdateEntityPositionAndRotation {
entity_id: VarInt,
delta: Vec3<i16>,
yaw: ByteAngle,
@ -592,7 +592,7 @@ pub mod play {
}
def_struct! {
Rotate {
UpdateEntityRotation {
entity_id: VarInt,
yaw: ByteAngle,
pitch: ByteAngle,
@ -609,7 +609,7 @@ pub mod play {
}
def_struct! {
ChatMessage {
PlayerChatMessage {
// TODO: more 1.19 stuff.
message: Text,
/// Index into the chat type registry
@ -619,7 +619,7 @@ pub mod play {
}
def_enum! {
UpdatePlayerList: VarInt {
PlayerInfo: VarInt {
AddPlayer: Vec<PlayerListAddPlayer> = 0,
UpdateGameMode: Vec<(Uuid, GameMode)> = 1,
UpdateLatency: Vec<(Uuid, VarInt)> = 2,
@ -641,7 +641,7 @@ pub mod play {
}
def_struct! {
PlayerPositionLook {
SynchronizePlayerPosition {
position: Vec3<f64>,
yaw: f32,
pitch: f32,
@ -662,13 +662,13 @@ pub mod play {
}
def_struct! {
EntitiesDestroy {
RemoveEntities {
entities: Vec<VarInt>,
}
}
def_struct! {
PlayerRespawn {
Respawn {
dimension_type_name: Ident,
dimension_name: Ident,
hashed_seed: u64,
@ -682,14 +682,14 @@ pub mod play {
}
def_struct! {
EntitySetHeadYaw {
SetHeadRotation {
entity_id: VarInt,
head_yaw: ByteAngle,
}
}
def_struct! {
ChunkSectionUpdate {
UpdateSectionBlocks {
chunk_section_position: i64,
invert_trust_edges: bool,
blocks: Vec<VarLong>,
@ -697,53 +697,53 @@ pub mod play {
}
def_struct! {
OverlayMessage {
SetActionBarText {
text: Text
}
}
def_struct! {
UpdateSelectedSlot {
SetHeldItemS2c {
slot: BoundedInt<u8, 0, 9>,
}
}
def_struct! {
ChunkRenderDistanceCenter {
SetCenterChunk {
chunk_x: VarInt,
chunk_z: VarInt,
}
}
def_struct! {
ChunkLoadDistance {
SetRenderDistance {
view_distance: BoundedInt<VarInt, 2, 32>,
}
}
def_struct! {
PlayerSpawnPosition {
SetDefaultSpawnPosition {
location: BlockPos,
angle: f32,
}
}
def_struct! {
EntityTrackerUpdate {
SetEntityMetadata {
entity_id: VarInt,
metadata: RawBytes,
}
}
def_struct! {
EntityVelocityUpdate {
SetEntityVelocity {
entity_id: VarInt,
velocity: Vec3<i16>,
}
}
def_struct! {
ExperienceBarUpdate {
SetExperience {
bar: f32,
level: VarInt,
total_xp: VarInt,
@ -751,7 +751,7 @@ pub mod play {
}
def_struct! {
HealthUpdate {
SetHealth {
health: f32,
food: VarInt,
food_saturation: f32,
@ -759,13 +759,13 @@ pub mod play {
}
def_struct! {
UpdateSubtitle {
SetSubtitleText {
subtitle_text: Text,
}
}
def_struct! {
WorldTimeUpdate {
UpdateTime {
/// The age of the world in 1/20ths of a second.
world_age: i64,
/// The current time of day in 1/20ths of a second.
@ -776,14 +776,14 @@ pub mod play {
}
def_struct! {
UpdateTitle {
SetTitleText {
text: Text,
}
}
def_struct! {
#[derive(Copy, PartialEq, Eq)]
TitleFade {
SetTitleAnimationTimes {
/// Ticks to spend fading in.
fade_in: u32,
/// Ticks to keep the title displayed.
@ -794,7 +794,7 @@ pub mod play {
}
def_struct! {
PlaySoundFromEntity {
EntitySoundEffect {
id: VarInt,
category: SoundCategory,
entity_id: VarInt,
@ -804,7 +804,7 @@ pub mod play {
}
def_struct! {
PlaySound {
SoundEffect {
id: VarInt,
category: SoundCategory,
position: Vec3<i32>,
@ -815,7 +815,7 @@ pub mod play {
}
def_struct! {
GameMessage {
SystemChatMessage {
chat: Text,
/// Index into the chat type registry.
kind: VarInt,
@ -823,14 +823,14 @@ pub mod play {
}
def_struct! {
PlayerListHeaderFooter {
SetTabListHeaderAndFooter {
header: Text,
footer: Text,
}
}
def_struct! {
EntityPosition {
TeleportEntity {
entity_id: VarInt,
position: Vec3<f64>,
yaw: ByteAngle,
@ -840,7 +840,7 @@ pub mod play {
}
def_struct! {
EntityAttributes {
UpdateAttributes {
entity_id: VarInt,
properties: Vec<EntityAttributesProperty>,
}
@ -864,14 +864,14 @@ pub mod play {
def_packet_group! {
S2cPlayPacket {
EntitySpawn = 0,
ExperienceOrbSpawn = 1,
PlayerSpawn = 2,
EntityAnimation = 3,
PlayerActionResponse = 5,
BlockBreakingProgress = 6,
BlockEntityUpdate = 7,
BlockEvent = 8,
SpawnEntity = 0,
SpawnExperienceOrb = 1,
SpawnPlayer = 2,
EntityAnimationS2c = 3,
AcknowledgeBlockChange = 5,
SetBlockDestroyStage = 6,
BlockEntityData = 7,
BlockAction = 8,
BlockUpdate = 9,
BossBar = 10,
ClearTitles = 13,
@ -879,44 +879,44 @@ pub mod play {
SetContainerProperty = 18,
SetContainerSlot = 19,
SetCooldown = 20,
PlaySoundId = 23,
Disconnect = 25,
EntityStatus = 26,
CustomSoundEffect = 23,
DisconnectPlay = 25,
EntityEvent = 26,
UnloadChunk = 28,
GameStateChange = 29,
KeepAlive = 32,
ChunkData = 33,
GameJoin = 37,
MoveRelative = 40,
RotateAndMoveRelative = 41,
Rotate = 42,
GameEvent = 29,
KeepAliveS2c = 32,
ChunkDataAndUpdateLight = 33,
LoginPlay = 37,
UpdateEntityPosition = 40,
UpdateEntityPositionAndRotation = 41,
UpdateEntityRotation = 42,
OpenScreen = 45,
ChatMessage = 51,
UpdatePlayerList = 55,
PlayerPositionLook = 57,
EntitiesDestroy = 59,
PlayerRespawn = 62,
EntitySetHeadYaw = 63,
ChunkSectionUpdate = 64,
OverlayMessage = 67,
UpdateSelectedSlot = 74,
ChunkRenderDistanceCenter = 75,
ChunkLoadDistance = 76,
PlayerSpawnPosition = 77,
EntityTrackerUpdate = 80,
EntityVelocityUpdate = 82,
ExperienceBarUpdate = 84,
HealthUpdate = 85,
UpdateSubtitle = 91,
WorldTimeUpdate = 92,
UpdateTitle = 93,
TitleFade = 94,
PlaySoundFromEntity = 95,
PlaySound = 96,
GameMessage = 98,
PlayerListHeaderFooter = 99,
EntityPosition = 102,
EntityAttributes = 104,
PlayerChatMessage = 51,
PlayerInfo = 55,
SynchronizePlayerPosition = 57,
RemoveEntities = 59,
Respawn = 62,
SetHeadRotation = 63,
UpdateSectionBlocks = 64,
SetActionBarText = 67,
SetHeldItemS2c = 74,
SetCenterChunk = 75,
SetRenderDistance = 76,
SetDefaultSpawnPosition = 77,
SetEntityMetadata = 80,
SetEntityVelocity = 82,
SetExperience = 84,
SetHealth = 85,
SetSubtitleText = 91,
UpdateTime = 92,
SetTitleText = 93,
SetTitleAnimationTimes = 94,
EntitySoundEffect = 95,
SoundEffect = 96,
SystemChatMessage = 98,
SetTabListHeaderAndFooter = 99,
TeleportEntity = 102,
UpdateAttributes = 104,
}
}
}

View file

@ -38,12 +38,12 @@ use crate::protocol::codec::{Decoder, Encoder};
use crate::protocol::packets::c2s::handshake::{Handshake, HandshakeNextState};
use crate::protocol::packets::c2s::login::{EncryptionResponse, LoginStart, VerifyTokenOrMsgSig};
use crate::protocol::packets::c2s::play::C2sPlayPacket;
use crate::protocol::packets::c2s::status::{QueryPing, QueryRequest};
use crate::protocol::packets::c2s::status::{PingRequest, StatusRequest};
use crate::protocol::packets::s2c::login::{
EncryptionRequest, LoginCompression, LoginDisconnect, LoginSuccess,
DisconnectLogin, EncryptionRequest, LoginSuccess, SetCompression,
};
use crate::protocol::packets::s2c::play::S2cPlayPacket;
use crate::protocol::packets::s2c::status::{QueryPong, QueryResponse};
use crate::protocol::packets::s2c::status::{PingResponse, StatusResponse};
use crate::protocol::packets::Property;
use crate::protocol::{BoundedArray, BoundedString, VarInt};
use crate::util::valid_username;
@ -573,7 +573,7 @@ async fn handle_status<C: Config>(
remote_addr: SocketAddr,
handshake: Handshake,
) -> anyhow::Result<()> {
c.dec.read_packet::<QueryRequest>().await?;
c.dec.read_packet::<StatusRequest>().await?;
match server
.0
@ -610,7 +610,7 @@ async fn handle_status<C: Config>(
}
c.enc
.write_packet(&QueryResponse {
.write_packet(&StatusResponse {
json_response: json.to_string(),
})
.await?;
@ -618,9 +618,9 @@ async fn handle_status<C: Config>(
ServerListPing::Ignore => return Ok(()),
}
let QueryPing { payload } = c.dec.read_packet().await?;
let PingRequest { payload } = c.dec.read_packet().await?;
c.enc.write_packet(&QueryPong { payload }).await?;
c.enc.write_packet(&PingResponse { payload }).await?;
Ok(())
}
@ -739,7 +739,7 @@ async fn handle_login<C: Config>(
let compression_threshold = 256;
c.enc
.write_packet(&LoginCompression {
.write_packet(&SetCompression {
threshold: VarInt(compression_threshold as i32),
})
.await?;
@ -756,7 +756,7 @@ async fn handle_login<C: Config>(
if let Err(reason) = server.0.cfg.login(server, &ncd).await {
log::info!("Disconnect at login: \"{reason}\"");
c.enc.write_packet(&LoginDisconnect { reason }).await?;
c.enc.write_packet(&DisconnectLogin { reason }).await?;
return Ok(None);
}