Rename packets

This commit is contained in:
Ryan 2022-06-30 14:18:29 -07:00
parent 6ef634ca2c
commit 9a87fda211
7 changed files with 265 additions and 328 deletions

View file

@ -6,7 +6,7 @@ use log::LevelFilter;
use noise::{NoiseFn, Seedable, SuperSimplex};
use rayon::iter::ParallelIterator;
use valence::block::{BlockState, PropName, PropValue};
use valence::client::{ChatMessageType, GameMode};
use valence::client::{GameMode, PlayerChatType};
use valence::config::{Config, ServerListPing};
use valence::text::Color;
use valence::util::chunks_in_view_distance;
@ -114,7 +114,7 @@ impl Config for Game {
None,
);
client.send_message("welcome!", ChatMessageType::Chat);
client.send_message("welcome!", PlayerChatType::Chat);
}
let dist = client.view_distance();

View file

@ -10,7 +10,7 @@ use rayon::iter::{IntoParallelRefIterator, IntoParallelRefMutIterator, ParallelI
use crate::block::BlockState;
use crate::protocol::packets::play::s2c::{
BlockChange, ChunkDataAndUpdateLight, ChunkDataHeightmaps, MultiBlockChange, S2cPlayPacket,
BlockUpdate, LevelChunkHeightmaps, LevelChunkWithLight, S2cPlayPacket, SectionBlocksUpdate,
};
use crate::protocol::{Encode, Nbt, VarInt, VarLong};
use crate::{BiomeId, BlockPos, ChunkPos, DimensionId, Server, Ticks};
@ -202,17 +202,17 @@ impl Chunk {
/// 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) -> ChunkDataAndUpdateLight {
pub(crate) fn chunk_data_packet(&self, pos: ChunkPos) -> LevelChunkWithLight {
let mut blocks_and_biomes = Vec::new();
for sect in self.sections.iter() {
blocks_and_biomes.extend_from_slice(&sect.compact_data);
}
ChunkDataAndUpdateLight {
LevelChunkWithLight {
chunk_x: pos.x,
chunk_z: pos.z,
heightmaps: Nbt(ChunkDataHeightmaps {
heightmaps: Nbt(LevelChunkHeightmaps {
motion_blocking: self.heightmap.clone(),
}),
blocks_and_biomes,
@ -250,7 +250,7 @@ impl Chunk {
let global_y = sect_y as i32 * 16 + (idx / (16 * 16)) as i32 + min_y;
let global_z = pos.z * 16 + (idx / 16 % 16) as i32;
packet(BlockChangePacket::Single(BlockChange {
packet(BlockChangePacket::Single(BlockUpdate {
location: BlockPos::new(global_x, global_y, global_z),
block_id: VarInt((block & BLOCK_STATE_MASK).into()),
}));
@ -276,7 +276,7 @@ impl Chunk {
| (pos.z as i64 & 0x3fffff) << 20
| (sect_y as i64 + min_y.div_euclid(16) as i64) & 0xfffff;
packet(BlockChangePacket::Multi(MultiBlockChange {
packet(BlockChangePacket::Multi(SectionBlocksUpdate {
chunk_section_position,
invert_trust_edges: false,
blocks,
@ -336,8 +336,8 @@ impl Chunk {
#[derive(Clone, Debug)]
pub(crate) enum BlockChangePacket {
Single(BlockChange),
Multi(MultiBlockChange),
Single(BlockUpdate),
Multi(SectionBlocksUpdate),
}
impl From<BlockChangePacket> for S2cPlayPacket {

View file

@ -16,16 +16,16 @@ use crate::entity::types::Player;
use crate::entity::{velocity_to_packet_units, EntityType};
use crate::player_textures::SignedPlayerTextures;
use crate::protocol::packets::play::c2s::{C2sPlayPacket, DiggingStatus, InteractType};
pub use crate::protocol::packets::play::s2c::ChatMessageType;
pub use crate::protocol::packets::play::s2c::PlayerChatType;
use crate::protocol::packets::play::s2c::{
AcknowledgeBlockChanges, Biome as BiomeRegistryBiome, BiomeAdditionsSound, BiomeEffects,
BiomeMoodSound, BiomeMusic, BiomeParticle, BiomeParticleOptions, BiomeProperty, BiomeRegistry,
ChangeGameState, ChangeGameStateReason, ChatTypeRegistry, DestroyEntities, DimensionType,
DimensionTypeRegistry, DimensionTypeRegistryEntry, Disconnect, EntityHeadLook, EntityMetadata,
EntityPosition, EntityPositionAndRotation, EntityRotation, EntityTeleport, EntityVelocity,
JoinGame, KeepAlive, PlayerPositionAndLook, PlayerPositionAndLookFlags, RegistryCodec,
S2cPlayPacket, SpawnPosition, SystemChatMessage, UnloadChunk, UpdateViewDistance,
UpdateViewPosition,
Biome as BiomeRegistryBiome, BiomeAdditionsSound, BiomeEffects, BiomeMoodSound, BiomeMusic,
BiomeParticle, BiomeParticleOptions, BiomeProperty, BiomeRegistry, BlockChangeAck,
ChatTypeRegistry, DimensionType, DimensionTypeRegistry, DimensionTypeRegistryEntry, Disconnect,
ForgetLevelChunk, GameEvent, GameEventReason, KeepAlive, Login, MoveEntityPosition,
MoveEntityPositionAndRotation, MoveEntityRotation, PlayerPosition, PlayerPositionFlags,
RegistryCodec, RemoveEntities, RotateHead, S2cPlayPacket, SetChunkCacheCenter,
SetChunkCacheRadius, SetEntityMetadata, SetEntityMotion, SpawnPosition, SystemChat,
TeleportEntity,
};
use crate::protocol::{BoundedInt, ByteAngle, Nbt, RawBytes, VarInt};
use crate::server::C2sPacketChannels;
@ -136,7 +136,7 @@ pub struct Client {
old_game_mode: GameMode,
settings: Option<Settings>,
dug_blocks: Vec<i32>,
msgs_to_send: Vec<(Text, ChatMessageType)>,
msgs_to_send: Vec<(Text, PlayerChatType)>,
/// The metadata for the client's own player entity.
player_meta: Player,
}
@ -200,7 +200,7 @@ impl Client {
self.textures.as_ref()
}
pub fn send_message(&mut self, msg: impl Into<Text>, typ: ChatMessageType) {
pub fn send_message(&mut self, msg: impl Into<Text>, typ: PlayerChatType) {
self.msgs_to_send.push((msg.into(), typ));
}
@ -386,7 +386,7 @@ impl Client {
}
match pkt {
C2sPlayPacket::TeleportConfirm(p) => {
C2sPlayPacket::AcceptTeleportation(p) => {
if self.pending_teleports == 0 {
self.disconnect("Unexpected teleport confirmation");
return;
@ -405,16 +405,16 @@ impl Client {
));
}
}
C2sPlayPacket::QueryBlockNbt(_) => {}
C2sPlayPacket::SetDifficulty(_) => {}
C2sPlayPacket::BlockEntityTagQuery(_) => {}
C2sPlayPacket::ChangeDifficulty(_) => {}
C2sPlayPacket::ChatCommand(_) => {}
C2sPlayPacket::ChatMessage(p) => self.events.push(Event::ChatMessage {
C2sPlayPacket::Chat(p) => self.events.push(Event::ChatMessage {
message: p.message.0,
timestamp: Duration::from_millis(p.timestamp),
}),
C2sPlayPacket::ChatPreview(_) => {}
C2sPlayPacket::ClientStatus(_) => {}
C2sPlayPacket::ClientSettings(p) => {
C2sPlayPacket::ClientCommand(_) => {}
C2sPlayPacket::ClientInformation(p) => {
let old = self.settings.replace(Settings {
locale: p.locale.0,
view_distance: p.view_distance.0,
@ -427,13 +427,13 @@ impl Client {
self.events.push(Event::SettingsChanged(old));
}
C2sPlayPacket::TabComplete(_) => {}
C2sPlayPacket::ClickWindowButton(_) => {}
C2sPlayPacket::CloseWindow(_) => {}
C2sPlayPacket::PluginMessage(_) => {}
C2sPlayPacket::CommandSuggestion(_) => {}
C2sPlayPacket::ContainerButtonClick(_) => {}
C2sPlayPacket::ContainerClose(_) => {}
C2sPlayPacket::CustomPayload(_) => {}
C2sPlayPacket::EditBook(_) => {}
C2sPlayPacket::QueryEntityNbt(_) => {}
C2sPlayPacket::InteractEntity(p) => {
C2sPlayPacket::EntityTagQuery(_) => {}
C2sPlayPacket::Interact(p) => {
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
// that the distance is <=4 blocks.
@ -451,7 +451,7 @@ impl Client {
});
}
}
C2sPlayPacket::GenerateStructure(_) => {}
C2sPlayPacket::JigsawGenerate(_) => {}
C2sPlayPacket::KeepAlive(p) => {
let last_keepalive_id = self.last_keepalive_id;
if self.got_keepalive {
@ -466,16 +466,16 @@ impl Client {
}
}
C2sPlayPacket::LockDifficulty(_) => {}
C2sPlayPacket::PlayerPosition(p) => {
C2sPlayPacket::MovePlayerPosition(p) => {
handle_movement_packet(self, false, p.position, self.yaw, self.pitch, p.on_ground)
}
C2sPlayPacket::PlayerPositionAndRotation(p) => {
C2sPlayPacket::MovePlayerPositionAndRotation(p) => {
handle_movement_packet(self, false, p.position, p.yaw, p.pitch, p.on_ground)
}
C2sPlayPacket::PlayerRotation(p) => {
C2sPlayPacket::MovePlayerRotation(p) => {
handle_movement_packet(self, false, self.new_position, p.yaw, p.pitch, p.on_ground)
}
C2sPlayPacket::PlayerMovement(p) => handle_movement_packet(
C2sPlayPacket::MovePlayerStatusOnly(p) => handle_movement_packet(
self,
false,
self.new_position,
@ -483,19 +483,19 @@ impl Client {
self.pitch,
p.on_ground,
),
C2sPlayPacket::VehicleMove(p) => {
C2sPlayPacket::MoveVehicle(p) => {
handle_movement_packet(self, true, p.position, p.yaw, p.pitch, self.on_ground);
}
C2sPlayPacket::SteerBoat(p) => {
C2sPlayPacket::PaddleBoat(p) => {
self.events.push(Event::SteerBoat {
left_paddle_turning: p.left_paddle_turning,
right_paddle_turning: p.right_paddle_turning,
});
}
C2sPlayPacket::PickItem(_) => {}
C2sPlayPacket::CraftRecipeRequest(_) => {}
C2sPlayPacket::PlaceRecipe(_) => {}
C2sPlayPacket::PlayerAbilities(_) => {}
C2sPlayPacket::PlayerDigging(p) => {
C2sPlayPacket::PlayerAction(p) => {
// TODO: verify dug block is within the correct distance from the client.
// TODO: verify that the broken block is allowed to be broken?
@ -525,26 +525,26 @@ impl Client {
DiggingStatus::SwapItemInHand => return,
});
}
C2sPlayPacket::EntityAction(_) => {}
C2sPlayPacket::SteerVehicle(_) => {}
C2sPlayPacket::PlayerCommand(_) => {}
C2sPlayPacket::PlayerInput(_) => {}
C2sPlayPacket::Pong(_) => {}
C2sPlayPacket::SetRecipeBookState(_) => {}
C2sPlayPacket::SetDisplayedRecipe(_) => {}
C2sPlayPacket::NameItem(_) => {}
C2sPlayPacket::ResourcePackStatus(_) => {}
C2sPlayPacket::AdvancementTab(_) => {}
C2sPlayPacket::RecipeBookChangeSettings(_) => {}
C2sPlayPacket::RecipeBookSeenRecipe(_) => {}
C2sPlayPacket::RenameItem(_) => {}
C2sPlayPacket::ResourcePack(_) => {}
C2sPlayPacket::SeenAdvancements(_) => {}
C2sPlayPacket::SelectTrade(_) => {}
C2sPlayPacket::SetBeaconEffect(_) => {}
C2sPlayPacket::HeldItemChange(_) => {}
C2sPlayPacket::UpdateCommandBlock(_) => {}
C2sPlayPacket::UpdateCommandBlockMinecart(_) => {}
C2sPlayPacket::CreativeInventoryAction(_) => {}
C2sPlayPacket::UpdateJigsawBlock(_) => {}
C2sPlayPacket::UpdateStructureBlock(_) => {}
C2sPlayPacket::UpdateSign(_) => {}
C2sPlayPacket::PlayerArmSwing(_) => {}
C2sPlayPacket::Spectate(_) => {}
C2sPlayPacket::PlayerBlockPlacement(_) => {}
C2sPlayPacket::SetBeacon(_) => {}
C2sPlayPacket::SetCarriedItem(_) => {}
C2sPlayPacket::SetCommandBlock(_) => {}
C2sPlayPacket::SetCommandBlockMinecart(_) => {}
C2sPlayPacket::SetCreativeModeSlot(_) => {}
C2sPlayPacket::SetJigsawBlock(_) => {}
C2sPlayPacket::SetStructureBlock(_) => {}
C2sPlayPacket::SignUpdate(_) => {}
C2sPlayPacket::Swing(_) => {}
C2sPlayPacket::TeleportToEntity(_) => {}
C2sPlayPacket::UseItemOn(_) => {}
C2sPlayPacket::UseItem(_) => {}
}
}
@ -571,7 +571,7 @@ impl Client {
meta.player_list()
.initial_packets(|pkt| self.send_packet(pkt));
self.send_packet(JoinGame {
self.send_packet(Login {
entity_id: 0, // EntityId 0 is reserved for clients.
is_hardcore: false, // TODO
gamemode: self.new_game_mode,
@ -603,8 +603,8 @@ impl Client {
} else {
if self.old_game_mode != self.new_game_mode {
self.old_game_mode = self.new_game_mode;
self.send_packet(ChangeGameState {
reason: ChangeGameStateReason::ChangeGameMode,
self.send_packet(GameEvent {
reason: GameEventReason::ChangeGameMode,
value: self.new_game_mode as i32 as f32,
});
}
@ -626,7 +626,7 @@ impl Client {
if 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 {
self.send_packet(UpdateViewDistance {
self.send_packet(SetChunkCacheRadius {
view_distance: BoundedInt(VarInt(self.new_max_view_distance as i32)),
})
}
@ -655,7 +655,7 @@ impl Client {
let new_section = self.new_position.map(|n| (n / 16.0).floor() as i32);
if old_section != new_section {
self.send_packet(UpdateViewPosition {
self.send_packet(SetChunkCacheCenter {
chunk_x: VarInt(new_section.x),
chunk_z: VarInt(new_section.z),
})
@ -684,7 +684,7 @@ impl Client {
send_packet(
&mut self.send,
UnloadChunk {
ForgetLevelChunk {
chunk_x: pos.x,
chunk_z: pos.z,
},
@ -706,7 +706,7 @@ impl Client {
for seq in self.dug_blocks.drain(..) {
send_packet(
&mut self.send,
AcknowledgeBlockChanges {
BlockChangeAck {
sequence: VarInt(seq),
},
)
@ -717,11 +717,11 @@ impl Client {
if self.teleported_this_tick {
self.teleported_this_tick = false;
self.send_packet(PlayerPositionAndLook {
self.send_packet(PlayerPosition {
position: self.new_position,
yaw: self.yaw,
pitch: self.pitch,
flags: PlayerPositionAndLookFlags::new(false, false, false, false, false),
flags: PlayerPositionFlags::new(false, false, false, false, false),
teleport_id: VarInt((self.teleport_id_counter - 1) as i32),
dismount_vehicle: false,
});
@ -729,7 +729,7 @@ impl Client {
for (msg, typ) in self.msgs_to_send.drain(..) {
// TODO: wont work without proper chat registry.
send_packet(&mut self.send, SystemChatMessage { chat: msg, typ });
send_packet(&mut self.send, SystemChat { chat: msg, typ });
}
let mut entities_to_unload = Vec::new();
@ -756,7 +756,7 @@ impl Client {
{
send_packet(
&mut self.send,
EntityPositionAndRotation {
MoveEntityPositionAndRotation {
entity_id: VarInt(id.to_network_id()),
delta: (position_delta * 4096.0).as_(),
yaw: ByteAngle::from_degrees(entity.yaw()),
@ -768,7 +768,7 @@ impl Client {
if entity.position() != entity.old_position() && !needs_teleport {
send_packet(
&mut self.send,
EntityPosition {
MoveEntityPosition {
entity_id: VarInt(id.to_network_id()),
delta: (position_delta * 4096.0).as_(),
on_ground: entity.on_ground(),
@ -779,7 +779,7 @@ impl Client {
if flags.yaw_or_pitch_modified() {
send_packet(
&mut self.send,
EntityRotation {
MoveEntityRotation {
entity_id: VarInt(id.to_network_id()),
yaw: ByteAngle::from_degrees(entity.yaw()),
pitch: ByteAngle::from_degrees(entity.pitch()),
@ -792,7 +792,7 @@ impl Client {
if needs_teleport {
send_packet(
&mut self.send,
EntityTeleport {
TeleportEntity {
entity_id: VarInt(id.to_network_id()),
position: entity.position(),
yaw: ByteAngle::from_degrees(entity.yaw()),
@ -805,7 +805,7 @@ impl Client {
if flags.velocity_modified() {
send_packet(
&mut self.send,
EntityVelocity {
SetEntityMotion {
entity_id: VarInt(id.to_network_id()),
velocity: velocity_to_packet_units(entity.velocity()),
},
@ -815,7 +815,7 @@ impl Client {
if flags.head_yaw_modified() {
send_packet(
&mut self.send,
EntityHeadLook {
RotateHead {
entity_id: VarInt(id.to_network_id()),
head_yaw: ByteAngle::from_degrees(entity.head_yaw()),
},
@ -831,7 +831,7 @@ impl Client {
});
if !entities_to_unload.is_empty() {
self.send_packet(DestroyEntities {
self.send_packet(RemoveEntities {
entities: entities_to_unload,
});
}
@ -843,7 +843,7 @@ impl Client {
if !data.is_empty() {
data.push(0xff);
self.send_packet(EntityMetadata {
self.send_packet(SetEntityMetadata {
entity_id: VarInt(0),
metadata: RawBytes(data),
});

View file

@ -13,7 +13,7 @@ use uuid::Uuid;
use vek::{Aabb, Vec3};
use crate::protocol::packets::play::s2c::{
EntityMetadata, S2cPlayPacket, SpawnEntity, SpawnExperienceOrb, SpawnPlayer,
AddEntity, AddExperienceOrb, AddPlayer, S2cPlayPacket, SetEntityMetadata,
};
use crate::protocol::{ByteAngle, RawBytes, VarInt};
use crate::slotmap::{Key, SlotMap};
@ -307,8 +307,8 @@ impl Entity {
/// spawned.
///
/// Is `None` if there is no initial metadata.
pub(crate) fn initial_metadata_packet(&self, this_id: EntityId) -> Option<EntityMetadata> {
self.meta.initial_metadata().map(|meta| EntityMetadata {
pub(crate) fn initial_metadata_packet(&self, this_id: EntityId) -> Option<SetEntityMetadata> {
self.meta.initial_metadata().map(|meta| SetEntityMetadata {
entity_id: VarInt(this_id.to_network_id()),
metadata: RawBytes(meta),
})
@ -317,8 +317,8 @@ impl Entity {
/// Gets the metadata packet to send to clients when the entity is modified.
///
/// Is `None` if this entity's metadata has not been modified.
pub(crate) fn updated_metadata_packet(&self, this_id: EntityId) -> Option<EntityMetadata> {
self.meta.updated_metadata().map(|meta| EntityMetadata {
pub(crate) fn updated_metadata_packet(&self, this_id: EntityId) -> Option<SetEntityMetadata> {
self.meta.updated_metadata().map(|meta| SetEntityMetadata {
entity_id: VarInt(this_id.to_network_id()),
metadata: RawBytes(meta),
})
@ -328,20 +328,20 @@ impl Entity {
match &self.meta {
EntityMeta::Marker(_) => None,
EntityMeta::ExperienceOrb(_) => {
Some(EntitySpawnPacket::SpawnExperienceOrb(SpawnExperienceOrb {
Some(EntitySpawnPacket::SpawnExperienceOrb(AddExperienceOrb {
entity_id: VarInt(this_id.to_network_id()),
position: self.new_position,
count: 0, // TODO
}))
}
EntityMeta::Player(_) => Some(EntitySpawnPacket::SpawnPlayer(SpawnPlayer {
EntityMeta::Player(_) => Some(EntitySpawnPacket::SpawnPlayer(AddPlayer {
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::SpawnEntity(SpawnEntity {
_ => Some(EntitySpawnPacket::SpawnEntity(AddEntity {
entity_id: VarInt(this_id.to_network_id()),
object_uuid: self.uuid,
typ: VarInt(self.typ() as i32),
@ -505,9 +505,9 @@ pub(crate) fn velocity_to_packet_units(vel: Vec3<f32>) -> Vec3<i16> {
}
pub(crate) enum EntitySpawnPacket {
SpawnEntity(SpawnEntity),
SpawnExperienceOrb(SpawnExperienceOrb),
SpawnPlayer(SpawnPlayer),
SpawnEntity(AddEntity),
SpawnExperienceOrb(AddExperienceOrb),
SpawnPlayer(AddPlayer),
}
impl From<EntitySpawnPacket> for S2cPlayPacket {

View file

@ -7,7 +7,7 @@ use uuid::Uuid;
use crate::client::GameMode;
use crate::player_textures::SignedPlayerTextures;
use crate::protocol::packets::play::s2c::{
PlayerInfo, PlayerInfoAddPlayer, PlayerListHeaderFooter, S2cPlayPacket,
PlayerInfo, PlayerInfoAddPlayer, S2cPlayPacket, TabList,
};
use crate::protocol::packets::Property;
use crate::protocol::VarInt;
@ -148,7 +148,7 @@ impl PlayerList {
if self.header != Text::default() || self.footer != Text::default() {
packet(
PlayerListHeaderFooter {
TabList {
header: self.header.clone(),
footer: self.footer.clone(),
}
@ -222,7 +222,7 @@ impl PlayerList {
if self.modified_header_or_footer {
packet(
PlayerListHeaderFooter {
TabList {
header: self.header.clone(),
footer: self.footer.clone(),
}

View file

@ -372,7 +372,7 @@ pub mod status {
}
def_struct! {
Pong 0x01 {
PongResponse 0x01 {
/// Should be the same as the payload from [`Ping`].
payload: u64
}
@ -383,11 +383,11 @@ pub mod status {
use super::super::*;
def_struct! {
Request 0x00 {}
StatusRequest 0x00 {}
}
def_struct! {
Ping 0x01 {
PingRequest 0x01 {
payload: u64
}
}
@ -469,7 +469,7 @@ pub mod play {
use super::super::*;
def_struct! {
SpawnEntity 0x00 {
AddEntity 0x00 {
entity_id: VarInt,
object_uuid: Uuid,
typ: VarInt,
@ -483,24 +483,15 @@ pub mod play {
}
def_struct! {
SpawnExperienceOrb 0x01 {
AddExperienceOrb 0x01 {
entity_id: VarInt,
position: Vec3<f64>,
count: i16,
}
}
def_enum! {
PaintingDirection: u8 {
South = 0,
West = 1,
North = 2,
East = 3,
}
}
def_struct! {
SpawnPlayer 0x02 {
AddPlayer 0x02 {
entity_id: VarInt,
player_uuid: Uuid,
position: Vec3<f64>,
@ -510,7 +501,7 @@ pub mod play {
}
def_struct! {
EntityAnimation 0x03 {
Animate 0x03 {
entity_id: VarInt,
animation: Animation,
}
@ -528,13 +519,13 @@ pub mod play {
}
def_struct! {
AcknowledgeBlockChanges 0x05 {
BlockChangeAck 0x05 {
sequence: VarInt,
}
}
def_struct! {
BlockBreakAnimation 0x06 {
BlockDestruction 0x06 {
entity_id: VarInt,
location: BlockPos,
destroy_stage: BoundedInt<u8, 0, 10>,
@ -550,49 +541,48 @@ pub mod play {
}
def_struct! {
BlockAction 0x08 {
BlockEvent 0x08 {
location: BlockPos,
action_id: u8,
action_param: u8,
block_type: VarInt,
// TODO: sequence?
block_type: VarInt, // TODO: use BlockType type.
}
}
def_struct! {
BlockChange 0x09 {
BlockUpdate 0x09 {
location: BlockPos,
block_id: VarInt,
}
}
def_struct! {
BossBar 0x0a {
BossEvent 0x0a {
uuid: Uuid,
action: BossBarAction,
action: BossEventAction,
}
}
def_enum! {
BossBarAction: VarInt {
Add: BossBarActionAdd = 0,
BossEventAction: VarInt {
Add: BossEventActionAdd = 0,
// TODO
}
}
def_struct! {
BossBarActionAdd {
BossEventActionAdd {
title: Text,
health: f32,
color: BossBarColor,
division: BossBarDivision,
color: BossEventColor,
division: BossEventDivision,
/// TODO: bitmask
flags: u8,
}
}
def_enum! {
BossBarColor: VarInt {
BossEventColor: VarInt {
Pink = 0,
Blue = 1,
Red = 2,
@ -604,7 +594,7 @@ pub mod play {
}
def_enum! {
BossBarDivision: VarInt {
BossEventDivision: VarInt {
NoDivision = 0,
SixNotches = 1,
TenNotches = 2,
@ -614,7 +604,7 @@ pub mod play {
}
def_struct! {
ServerDifficulty 0x0b {
ChangeDifficulty 0x0b {
difficulty: Difficulty,
locked: bool,
}
@ -629,51 +619,6 @@ pub mod play {
}
}
def_struct! {
ClearTitles 0x0d {
reset: bool,
}
}
def_struct! {
TabComplete 0x0e {
id: VarInt,
start: VarInt,
length: VarInt,
matches: Vec<TabCompleteMatch>,
}
}
def_struct! {
TabCompleteMatch {
value: String,
tooltip: TabCompleteTooltip,
}
}
def_enum! {
TabCompleteTooltip: u8 {
NoTooltip = 0,
Tooltip: Text = 1,
}
}
def_struct! {
WindowProperty 0x12 {
// TODO: use enums
window_id: u8,
property: i16,
value: i16,
}
}
def_struct! {
SetCooldown 0x14 {
item_id: VarInt,
cooldown_ticks: VarInt,
}
}
def_struct! {
Disconnect 0x17 {
reason: Text,
@ -681,7 +626,7 @@ pub mod play {
}
def_struct! {
EntityStatus 0x18 {
EntityEvent 0x18 {
entity_id: i32,
/// TODO: enum
entity_status: u8,
@ -689,21 +634,21 @@ pub mod play {
}
def_struct! {
UnloadChunk 0x1a {
ForgetLevelChunk 0x1a {
chunk_x: i32,
chunk_z: i32
}
}
def_struct! {
ChangeGameState 0x1b {
reason: ChangeGameStateReason,
GameEvent 0x1b {
reason: GameEventReason,
value: f32,
}
}
def_enum! {
ChangeGameStateReason: u8 {
GameEventReason: u8 {
NoRespawnBlockAvailable = 0,
EndRaining = 1,
BeginRaining = 2,
@ -719,14 +664,6 @@ pub mod play {
}
}
def_struct! {
OpenHorseWindow 0x1c {
window_id: u8,
slot_count: VarInt,
entity_id: i32,
}
}
def_struct! {
InitializeWorldBorder 0x1d {
x: f64,
@ -747,12 +684,12 @@ pub mod play {
}
def_struct! {
ChunkDataAndUpdateLight 0x1f {
LevelChunkWithLight 0x1f {
chunk_x: i32,
chunk_z: i32,
heightmaps: Nbt<ChunkDataHeightmaps>,
heightmaps: Nbt<LevelChunkHeightmaps>,
blocks_and_biomes: Vec<u8>,
block_entities: Vec<ChunkDataBlockEntity>,
block_entities: Vec<LevelChunkBlockEntity>,
trust_edges: bool,
sky_light_mask: BitVec<u64>,
block_light_mask: BitVec<u64>,
@ -764,13 +701,13 @@ pub mod play {
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ChunkDataHeightmaps {
pub struct LevelChunkHeightmaps {
#[serde(rename = "MOTION_BLOCKING", serialize_with = "nbt::i64_array")]
pub motion_blocking: Vec<i64>,
}
def_struct! {
ChunkDataBlockEntity {
LevelChunkBlockEntity {
packed_xz: i8,
y: i16,
typ: VarInt,
@ -779,7 +716,7 @@ pub mod play {
}
def_struct! {
JoinGame 0x23 {
Login 0x23 {
/// Entity ID of the joining player
entity_id: i32,
is_hardcore: bool,
@ -955,7 +892,7 @@ pub mod play {
}
def_struct! {
EntityPosition 0x26 {
MoveEntityPosition 0x26 {
entity_id: VarInt,
delta: Vec3<i16>,
on_ground: bool,
@ -963,7 +900,7 @@ pub mod play {
}
def_struct! {
EntityPositionAndRotation 0x27 {
MoveEntityPositionAndRotation 0x27 {
entity_id: VarInt,
delta: Vec3<i16>,
yaw: ByteAngle,
@ -973,7 +910,7 @@ pub mod play {
}
def_struct! {
EntityRotation 0x28 {
MoveEntityRotation 0x28 {
entity_id: VarInt,
yaw: ByteAngle,
pitch: ByteAngle,
@ -982,9 +919,9 @@ pub mod play {
}
def_struct! {
ChatMessage 0x30 {
PlayerChat 0x30 {
message: Text,
typ: ChatMessageType,
typ: PlayerChatType,
sender: Uuid,
// TODO more fields
}
@ -992,7 +929,7 @@ pub mod play {
def_enum! {
#[derive(Copy, PartialEq, Eq, Default)]
ChatMessageType: VarInt {
PlayerChatType: VarInt {
#[default]
Chat = 0,
SystemMessage = 1,
@ -1028,18 +965,18 @@ pub mod play {
}
def_struct! {
PlayerPositionAndLook 0x36 {
PlayerPosition 0x36 {
position: Vec3<f64>,
yaw: f32,
pitch: f32,
flags: PlayerPositionAndLookFlags,
flags: PlayerPositionFlags,
teleport_id: VarInt,
dismount_vehicle: bool,
}
}
def_bitfield! {
PlayerPositionAndLookFlags: u8 {
PlayerPositionFlags: u8 {
x = 0,
y = 1,
z = 2,
@ -1049,20 +986,20 @@ pub mod play {
}
def_struct! {
DestroyEntities 0x38 {
RemoveEntities 0x38 {
entities: Vec<VarInt>,
}
}
def_struct! {
EntityHeadLook 0x3c {
RotateHead 0x3c {
entity_id: VarInt,
head_yaw: ByteAngle,
}
}
def_struct! {
MultiBlockChange 0x3d {
SectionBlocksUpdate 0x3d {
chunk_section_position: i64,
invert_trust_edges: bool,
blocks: Vec<VarLong>,
@ -1070,20 +1007,20 @@ pub mod play {
}
def_struct! {
HeldItemChange 0x47 {
SetCarriedItem 0x47 {
slot: BoundedInt<u8, 0, 9>,
}
}
def_struct! {
UpdateViewPosition 0x48 {
SetChunkCacheCenter 0x48 {
chunk_x: VarInt,
chunk_z: VarInt,
}
}
def_struct! {
UpdateViewDistance 0x49 {
SetChunkCacheRadius 0x49 {
view_distance: BoundedInt<VarInt, 2, 32>,
}
}
@ -1096,21 +1033,21 @@ pub mod play {
}
def_struct! {
EntityMetadata 0x4d {
SetEntityMetadata 0x4d {
entity_id: VarInt,
metadata: RawBytes,
}
}
def_struct! {
EntityVelocity 0x4f {
SetEntityMotion 0x4f {
entity_id: VarInt,
velocity: Vec3<i16>,
}
}
def_struct! {
TimeUpdate 0x59 {
SetTime 0x59 {
/// 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.
@ -1121,21 +1058,21 @@ pub mod play {
}
def_struct! {
SystemChatMessage 0x5f {
SystemChat 0x5f {
chat: Text,
typ: ChatMessageType,
typ: PlayerChatType,
}
}
def_struct! {
PlayerListHeaderFooter 0x60 {
TabList 0x60 {
header: Text,
footer: Text,
}
}
def_struct! {
EntityTeleport 0x63 {
TeleportEntity 0x63 {
entity_id: VarInt,
position: Vec3<f64>,
yaw: ByteAngle,
@ -1200,42 +1137,42 @@ pub mod play {
}
def_s2c_play_packet_enum! {
SpawnEntity,
SpawnExperienceOrb,
SpawnPlayer,
EntityAnimation,
AcknowledgeBlockChanges,
BlockBreakAnimation,
AddEntity,
AddExperienceOrb,
AddPlayer,
Animate,
BlockChangeAck,
BlockDestruction,
BlockEntityData,
BlockAction,
BlockChange,
BossBar,
BlockEvent,
BlockUpdate,
BossEvent,
Disconnect,
EntityStatus,
UnloadChunk,
ChangeGameState,
EntityEvent,
ForgetLevelChunk,
GameEvent,
KeepAlive,
ChunkDataAndUpdateLight,
JoinGame,
EntityPosition,
EntityPositionAndRotation,
EntityRotation,
ChatMessage,
LevelChunkWithLight,
Login,
MoveEntityPosition,
MoveEntityPositionAndRotation,
MoveEntityRotation,
PlayerChat,
PlayerInfo,
PlayerPositionAndLook,
DestroyEntities,
EntityHeadLook,
MultiBlockChange,
HeldItemChange,
UpdateViewPosition,
UpdateViewDistance,
PlayerPosition,
RemoveEntities,
RotateHead,
SectionBlocksUpdate,
SetCarriedItem,
SetChunkCacheCenter,
SetChunkCacheRadius,
SpawnPosition,
EntityMetadata,
EntityVelocity,
TimeUpdate,
SystemChatMessage,
PlayerListHeaderFooter,
EntityTeleport,
SetEntityMetadata,
SetEntityMotion,
SetTime,
SystemChat,
TabList,
TeleportEntity,
}
}
@ -1243,20 +1180,20 @@ pub mod play {
use super::super::*;
def_struct! {
TeleportConfirm 0x00 {
AcceptTeleportation 0x00 {
teleport_id: VarInt
}
}
def_struct! {
QueryBlockNbt 0x01 {
BlockEntityTagQuery 0x01 {
transaction_id: VarInt,
location: BlockPos,
}
}
def_enum! {
SetDifficulty 0x02: i8 {
ChangeDifficulty 0x02: i8 {
Peaceful = 0,
Easy = 1,
Normal = 2,
@ -1273,7 +1210,7 @@ pub mod play {
}
def_struct! {
ChatMessage 0x04 {
Chat 0x04 {
message: BoundedString<0, 256>,
timestamp: u64,
salt: u64,
@ -1290,7 +1227,7 @@ pub mod play {
}
def_enum! {
ClientStatus 0x06: VarInt {
ClientCommand 0x06: VarInt {
/// Sent when ready to complete login and ready to respawn after death.
PerformRespawn = 0,
/// Sent when the statistics menu is opened.
@ -1299,7 +1236,7 @@ pub mod play {
}
def_struct! {
ClientSettings 0x07 {
ClientInformation 0x07 {
/// e.g. en_US
locale: BoundedString<0, 16>,
/// Client-side render distance in chunks.
@ -1345,7 +1282,7 @@ pub mod play {
}
def_struct! {
TabComplete 0x08 {
CommandSuggestion 0x08 {
transaction_id: VarInt,
/// Text behind the cursor without the '/'.
text: BoundedString<0, 32500>
@ -1353,20 +1290,20 @@ pub mod play {
}
def_struct! {
ClickWindowButton 0x09 {
ContainerButtonClick 0x09 {
window_id: i8,
button_id: i8,
}
}
def_struct! {
CloseWindow 0x0b {
ContainerClose 0x0b {
window_id: u8,
}
}
def_struct! {
PluginMessage 0x0c {
CustomPayload 0x0c {
channel: Ident,
data: RawBytes,
}
@ -1381,14 +1318,14 @@ pub mod play {
}
def_struct! {
QueryEntityNbt 0x0e {
EntityTagQuery 0x0e {
transaction_id: VarInt,
entity_id: VarInt,
}
}
def_struct! {
InteractEntity 0x0f {
Interact 0x0f {
entity_id: VarInt,
typ: InteractType,
sneaking: bool,
@ -1412,7 +1349,7 @@ pub mod play {
}
def_struct! {
GenerateStructure 0x10 {
JigsawGenerate 0x10 {
location: BlockPos,
levels: VarInt,
keep_jigsaws: bool,
@ -1432,14 +1369,14 @@ pub mod play {
}
def_struct! {
PlayerPosition 0x13 {
MovePlayerPosition 0x13 {
position: Vec3<f64>,
on_ground: bool,
}
}
def_struct! {
PlayerPositionAndRotation 0x14 {
MovePlayerPositionAndRotation 0x14 {
// Absolute position
position: Vec3<f64>,
/// Absolute rotation on X axis in degrees.
@ -1451,7 +1388,7 @@ pub mod play {
}
def_struct! {
PlayerRotation 0x15 {
MovePlayerRotation 0x15 {
/// Absolute rotation on X axis in degrees.
yaw: f32,
/// Absolute rotation on Y axis in degrees.
@ -1461,13 +1398,13 @@ pub mod play {
}
def_struct! {
PlayerMovement 0x16 {
MovePlayerStatusOnly 0x16 {
on_ground: bool
}
}
def_struct! {
VehicleMove 0x17 {
MoveVehicle 0x17 {
/// Absolute position
position: Vec3<f64>,
/// Degrees
@ -1478,7 +1415,7 @@ pub mod play {
}
def_struct! {
SteerBoat 0x18 {
PaddleBoat 0x18 {
left_paddle_turning: bool,
right_paddle_turning: bool,
}
@ -1491,7 +1428,7 @@ pub mod play {
}
def_struct! {
CraftRecipeRequest 0x1a {
PlaceRecipe 0x1a {
window_id: i8,
recipe: Ident,
make_all: bool,
@ -1506,7 +1443,7 @@ pub mod play {
}
def_struct! {
PlayerDigging 0x1c {
PlayerAction 0x1c {
status: DiggingStatus,
location: BlockPos,
face: BlockFace,
@ -1545,15 +1482,15 @@ pub mod play {
}
def_struct! {
EntityAction 0x1d {
PlayerCommand 0x1d {
entity_id: VarInt,
action_id: EntityActionId,
action_id: PlayerCommandId,
jump_boost: BoundedInt<VarInt, 0, 100>,
}
}
def_enum! {
EntityActionId: VarInt {
PlayerCommandId: VarInt {
StartSneaking = 0,
StopSneaking = 1,
LeaveBed = 2,
@ -1567,15 +1504,15 @@ pub mod play {
}
def_struct! {
SteerVehicle 0x1e {
PlayerInput 0x1e {
sideways: f32,
forward: f32,
flags: SteerVehicleFlags,
flags: PlayerInputFlags,
}
}
def_bitfield! {
SteerVehicleFlags: u8 {
PlayerInputFlags: u8 {
jump = 0,
unmount = 1,
}
@ -1588,7 +1525,7 @@ pub mod play {
}
def_struct! {
SetRecipeBookState 0x20 {
RecipeBookChangeSettings 0x20 {
book_id: RecipeBookId,
book_open: bool,
filter_active: bool,
@ -1605,19 +1542,19 @@ pub mod play {
}
def_struct! {
SetDisplayedRecipe 0x21 {
RecipeBookSeenRecipe 0x21 {
recipe_id: Ident,
}
}
def_struct! {
NameItem 0x22 {
RenameItem 0x22 {
item_name: BoundedString<0, 50>,
}
}
def_enum! {
ResourcePackStatus 0x23: VarInt {
ResourcePack 0x23: VarInt {
SuccessfullyLoaded = 0,
Declined = 1,
FailedDownload = 2,
@ -1626,7 +1563,7 @@ pub mod play {
}
def_enum! {
AdvancementTab 0x24: VarInt {
SeenAdvancements 0x24: VarInt {
OpenedTab: Ident = 0,
ClosedScreen = 1,
}
@ -1639,7 +1576,7 @@ pub mod play {
}
def_struct! {
SetBeaconEffect 0x26 {
SetBeacon 0x26 {
// TODO: potion ids
primary_effect: Option<VarInt>,
secondary_effect: Option<VarInt>,
@ -1647,13 +1584,13 @@ pub mod play {
}
def_struct! {
HeldItemChange 0x27 {
SetCarriedItem 0x27 {
slot: BoundedInt<i16, 0, 8>,
}
}
def_struct! {
UpdateCommandBlock 0x28 {
SetCommandBlock 0x28 {
location: BlockPos,
command: String,
mode: CommandBlockMode,
@ -1678,7 +1615,7 @@ pub mod play {
}
def_struct! {
UpdateCommandBlockMinecart 0x29 {
SetCommandBlockMinecart 0x29 {
entity_id: VarInt,
command: String,
track_output: bool,
@ -1686,14 +1623,14 @@ pub mod play {
}
def_struct! {
CreativeInventoryAction 0x2a {
SetCreativeModeSlot 0x2a {
slot: i16,
// TODO: clicked_item: Slot,
}
}
def_struct! {
UpdateJigsawBlock 0x2b {
SetJigsawBlock 0x2b {
location: BlockPos,
name: Ident,
target: Ident,
@ -1704,7 +1641,7 @@ pub mod play {
}
def_struct! {
UpdateStructureBlock 0x2c {
SetStructureBlock 0x2c {
location: BlockPos,
action: StructureBlockAction,
mode: StructureBlockMode,
@ -1764,26 +1701,26 @@ pub mod play {
}
def_struct! {
UpdateSign 0x2d {
SignUpdate 0x2d {
location: BlockPos,
lines: [BoundedString<0, 384>; 4],
}
}
def_struct! {
PlayerArmSwing 0x2e {
Swing 0x2e {
hand: Hand,
}
}
def_struct! {
Spectate 0x2f {
TeleportToEntity 0x2f {
target: Uuid,
}
}
def_struct! {
PlayerBlockPlacement 0x30 {
UseItemOn 0x30 {
hand: Hand,
location: BlockPos,
face: BlockFace,
@ -1849,54 +1786,54 @@ pub mod play {
}
def_c2s_play_packet_enum! {
TeleportConfirm,
QueryBlockNbt,
SetDifficulty,
AcceptTeleportation,
BlockEntityTagQuery,
ChangeDifficulty,
ChatCommand,
ChatMessage,
Chat,
ChatPreview,
ClientStatus,
ClientSettings,
TabComplete,
ClickWindowButton,
CloseWindow,
PluginMessage,
ClientCommand,
ClientInformation,
CommandSuggestion,
ContainerButtonClick,
ContainerClose,
CustomPayload,
EditBook,
QueryEntityNbt,
InteractEntity,
GenerateStructure,
EntityTagQuery,
Interact,
JigsawGenerate,
KeepAlive,
LockDifficulty,
PlayerPosition,
PlayerPositionAndRotation,
PlayerRotation,
PlayerMovement,
VehicleMove,
SteerBoat,
MovePlayerPosition,
MovePlayerPositionAndRotation,
MovePlayerRotation,
MovePlayerStatusOnly,
MoveVehicle,
PaddleBoat,
PickItem,
CraftRecipeRequest,
PlaceRecipe,
PlayerAbilities,
PlayerDigging,
EntityAction,
SteerVehicle,
PlayerAction,
PlayerCommand,
PlayerInput,
Pong,
SetRecipeBookState,
SetDisplayedRecipe,
NameItem,
ResourcePackStatus,
AdvancementTab,
RecipeBookChangeSettings,
RecipeBookSeenRecipe,
RenameItem,
ResourcePack,
SeenAdvancements,
SelectTrade,
SetBeaconEffect,
HeldItemChange,
UpdateCommandBlock,
UpdateCommandBlockMinecart,
CreativeInventoryAction,
UpdateJigsawBlock,
UpdateStructureBlock,
UpdateSign,
PlayerArmSwing,
Spectate,
PlayerBlockPlacement,
SetBeacon,
SetCarriedItem,
SetCommandBlock,
SetCommandBlockMinecart,
SetCreativeModeSlot,
SetJigsawBlock,
SetStructureBlock,
SignUpdate,
Swing,
TeleportToEntity,
UseItemOn,
UseItem,
}
}

View file

@ -33,8 +33,8 @@ use crate::protocol::packets::login::c2s::{EncryptionResponse, LoginStart, Verif
use crate::protocol::packets::login::s2c::{EncryptionRequest, LoginSuccess, SetCompression};
use crate::protocol::packets::play::c2s::C2sPlayPacket;
use crate::protocol::packets::play::s2c::S2cPlayPacket;
use crate::protocol::packets::status::c2s::{Ping, Request};
use crate::protocol::packets::status::s2c::{Pong, Response};
use crate::protocol::packets::status::c2s::{PingRequest, StatusRequest};
use crate::protocol::packets::status::s2c::{PongResponse, Response};
use crate::protocol::packets::{login, Property};
use crate::protocol::{BoundedArray, BoundedString, VarInt};
use crate::util::valid_username;
@ -517,7 +517,7 @@ async fn handle_status(
c: &mut Codec,
remote_addr: SocketAddr,
) -> anyhow::Result<()> {
c.1.read_packet::<Request>().await?;
c.1.read_packet::<StatusRequest>().await?;
match server.0.cfg.server_list_ping(&server, remote_addr).await {
ServerListPing::Respond {
@ -555,9 +555,9 @@ async fn handle_status(
ServerListPing::Ignore => return Ok(()),
}
let Ping { payload } = c.1.read_packet().await?;
let PingRequest { payload } = c.1.read_packet().await?;
c.0.write_packet(&Pong { payload }).await?;
c.0.write_packet(&PongResponse { payload }).await?;
Ok(())
}