Skip to main content

nurtex_protocol/packets/play/
packets.rs

1use nurtex_codec::Buffer;
2use nurtex_derive::Packet;
3use uuid::Uuid;
4
5use crate::types::{AdditionalMessageInfo, BlockPosition, ClientCommand, Experience, Face, GameEvent, InteractType, Item, LpVector3, PhysicsFlags, PlayerAction, PlayerCommand, RelativeHand, ResourcePackState, Rotation, TeleportFlags, TextComponent, Vector3};
6
7#[derive(Clone, Debug, PartialEq, Packet)]
8pub struct MultisideKeepAlive {
9  pub id: i64,
10}
11
12#[derive(Clone, Debug, PartialEq, Packet)]
13pub struct ClientsidePing {
14  pub id: i32,
15}
16
17#[derive(Clone, Debug, PartialEq, Packet)]
18pub struct ClientsidePingResponse {
19  pub timestamp: i64,
20}
21
22#[derive(Clone, Debug, PartialEq, Packet)]
23pub struct ClientsideDamageEvent {
24  #[packet(varint)]
25  pub entity_id: i32,
26  #[packet(varint)]
27  pub source_type_id: i32,
28  #[packet(varint)]
29  pub source_cause_id: i32,
30  #[packet(varint)]
31  pub source_direct_id: i32,
32  pub source_position: Vector3,
33}
34
35#[derive(Clone, Debug, PartialEq, Packet)]
36pub struct ClientsideUpdateEntityPos {
37  #[packet(varint)]
38  pub entity_id: i32,
39  pub delta_x: i16,
40  pub delta_y: i16,
41  pub delta_z: i16,
42  pub on_ground: bool,
43}
44
45#[derive(Clone, Debug, PartialEq, Packet)]
46pub struct ClientsideUpdateEntityRot {
47  #[packet(varint)]
48  pub entity_id: i32,
49  pub yaw_angle: i8,
50  pub pitch_angle: i8,
51  pub on_ground: bool,
52}
53
54#[derive(Clone, Debug, PartialEq, Packet)]
55pub struct ClientsideUpdateEntityPosRot {
56  #[packet(varint)]
57  pub entity_id: i32,
58  pub delta_x: i16,
59  pub delta_y: i16,
60  pub delta_z: i16,
61  pub yaw_angle: i8,
62  pub pitch_angle: i8,
63  pub on_ground: bool,
64}
65
66#[derive(Clone, Debug, PartialEq, Packet)]
67pub struct ClientsidePlayerPosition {
68  #[packet(varlong)]
69  pub teleport_id: i64,
70  pub position: Vector3,
71  pub velocity: Vector3,
72  pub rotation: Rotation,
73  pub teleport_flags: TeleportFlags,
74}
75
76#[derive(Clone, Debug, PartialEq, Packet)]
77pub struct ClientsidePlayerRotation {
78  pub yaw: f32,
79  pub relative_yaw: bool,
80  pub pitch: f32,
81  pub relative_pitch: bool,
82}
83
84#[derive(Clone, Debug, PartialEq, Packet)]
85pub struct ClientsidePlayerLookAt {
86  #[packet(varint)]
87  pub gaze: i32,
88  pub target_pos: Vector3,
89  pub is_entity: bool,
90  #[packet(varint)]
91  pub entity_id: Option<i32>,
92  #[packet(varint)]
93  pub entity_gaze: Option<i32>,
94}
95
96#[derive(Clone, Debug, PartialEq, Packet)]
97pub struct ClientsidePlayerCombatKill {
98  #[packet(varint)]
99  pub player_id: i32,
100}
101
102#[derive(Clone, Debug, PartialEq, Packet)]
103pub struct ClientsideSetHealth {
104  pub health: f32,
105  #[packet(varint)]
106  pub food: i32,
107  pub food_saturation: f32,
108}
109
110#[derive(Clone, Debug, PartialEq, Packet)]
111pub struct ClientsideSetExperience {
112  pub experience: Experience,
113}
114
115#[derive(Clone, Debug, PartialEq, Packet)]
116pub struct ClientsideSetPassengers {
117  #[packet(varint)]
118  pub entity_id: i32,
119  #[packet(vec_varint)]
120  pub passengers: Vec<i32>,
121}
122
123#[derive(Clone, Debug, PartialEq, Packet)]
124pub struct ClientsideSetEntityVelocity {
125  #[packet(varint)]
126  pub entity_id: i32,
127  pub velocity: LpVector3,
128}
129
130#[derive(Clone, Debug, PartialEq, Packet)]
131pub struct ClientsideSpawnEntity {
132  #[packet(varint)]
133  pub entity_id: i32,
134  pub entity_uuid: Uuid,
135  #[packet(varint)]
136  pub entity_type: i32,
137  pub position: Vector3,
138  pub velocity: LpVector3,
139  pub angle_pitch: i8,
140  pub angle_yaw: i8,
141  pub angle_head_yaw: i8,
142  #[packet(varint)]
143  pub data: i32,
144}
145
146#[derive(Clone, Debug, PartialEq, Packet)]
147pub struct ClientsideRemoveEntities {
148  #[packet(vec_varint)]
149  pub entities: Vec<i32>,
150}
151
152#[derive(Clone, Debug, PartialEq, Packet)]
153pub struct ClientsideDisconnect {
154  // Я не знаю почему, но TextComponent не подходит здесь под поле `reason`, 
155  // хотя в тех же пакетах в состоянии Configuration / Login это работает
156  // -----------------------------------------------------------------------
157  // pub reason: TextComponent,
158}
159
160#[derive(Clone, Debug, PartialEq, Packet)]
161pub struct ClientsidePlayerChat {
162  #[packet(varint)]
163  pub global_index: i32,
164  pub sender_uuid: Uuid,
165  #[packet(varint)]
166  pub index: i32,
167  pub message_signature: Option<Vec<u8>>,
168  pub message: String,
169  pub timestamp: i64,
170  pub salt: i64,
171  #[packet(varint)]
172  pub message_id: i32,
173  pub signature: Option<Vec<u8>>,
174}
175
176#[derive(Clone, Debug, PartialEq, Packet)]
177pub struct ClientsideSystemChat {
178  pub message: TextComponent,
179  pub overlay: bool,
180}
181
182#[derive(Clone, Debug, PartialEq, Packet)]
183pub struct ClientsideTransfer {
184  pub server_host: String,
185  #[packet(varint)]
186  pub server_port: i32,
187}
188
189#[derive(Clone, Debug, PartialEq, Packet)]
190pub struct ClientsideSetHeldItem {
191  #[packet(varint)]
192  pub slot: i32,
193}
194
195#[derive(Clone, Debug, PartialEq, Packet)]
196pub struct ClientsideSetEntityLink {
197  #[packet(varint)]
198  pub attached_entity_id: i32,
199  #[packet(varint)]
200  pub holding_entity_id: i32,
201}
202
203#[derive(Clone, Debug, PartialEq, Packet)]
204pub struct ClientsideChunkCacheRadius {
205  #[packet(varint)]
206  pub view_distance: i32,
207}
208
209#[derive(Clone, Debug, PartialEq, Packet)]
210pub struct ClientsideChunkCacheCenter {
211  #[packet(varint)]
212  pub chunk_x: i32,
213  #[packet(varint)]
214  pub chunk_z: i32,
215}
216
217#[derive(Clone, Debug, PartialEq, Packet)]
218pub struct ClientsideSetCamera {
219  #[packet(varint)]
220  pub camera_id: i32,
221}
222
223#[derive(Clone, Debug, PartialEq, Packet)]
224pub struct ClientsideRotateHead {
225  #[packet(varint)]
226  pub entity_id: i32,
227  pub head_yaw: i8,
228}
229
230#[derive(Clone, Debug, PartialEq, Packet)]
231pub struct ClientsideSectionBlocksUpdate {
232  pub chunk_section_position: i64,
233  #[packet(vec_varlong)]
234  pub head_yaw: Vec<i64>,
235}
236
237#[derive(Clone, Debug, PartialEq, Packet)]
238pub struct ClientsideAddResourcePack {
239  pub uuid: uuid::Uuid,
240  pub url: String,
241  pub hash: String,
242  pub forced: bool,
243}
244
245#[derive(Clone, Debug, PartialEq, Packet)]
246pub struct ClientsideRemoveResourcePack {
247  pub uuid: uuid::Uuid,
248}
249
250#[derive(Clone, Debug, PartialEq, Packet)]
251pub struct ClientsideRemoveEntityEffect {
252  #[packet(varint)]
253  pub entity_id: i32,
254  #[packet(varint)]
255  pub effect_id: i32,
256}
257
258#[derive(Clone, Debug, PartialEq, Packet)]
259pub struct ClientsideOpenContainer {
260  #[packet(varint)]
261  pub window_id: i32,
262  #[packet(varint)]
263  pub window_type: i32,
264}
265
266#[derive(Clone, Debug, PartialEq, Packet)]
267pub struct ClientsideMoveVehicle {
268  pub position: Vector3,
269  pub rotation: Rotation,
270}
271
272#[derive(Clone, Debug, PartialEq, Packet)]
273pub struct ClientsideLogin {
274  pub entity_id: i32,
275  pub is_hardcore: bool,
276  pub dimension_names: Vec<String>,
277  #[packet(varint)]
278  pub max_players: i32,
279  #[packet(varint)]
280  pub view_distance: i32,
281  #[packet(varint)]
282  pub simulation_distance: i32,
283  pub reduced_debug_info: bool,
284  pub enable_respawn_screen: bool,
285  #[packet(varint)]
286  pub dimension_type: i32,
287  pub dimension_name: String,
288  pub hashed_seed: i64,
289}
290
291#[derive(Clone, Debug, PartialEq, Packet)]
292pub struct ClientsideEntityPositionSync {
293  #[packet(varint)]
294  pub entity_id: i32,
295  pub position: Vector3,
296  pub velocity: Vector3,
297  pub rotation: Rotation,
298  pub on_ground: bool,
299}
300
301#[derive(Clone, Debug, PartialEq, Packet)]
302pub struct ClientsideExplosion {
303  pub position: Vector3,
304  pub radius: f32,
305  pub block_count: i32,
306  pub player_delta_velocity: Option<Vector3>,
307  #[packet(varint)]
308  pub explosion_particle_id: i32,
309}
310
311#[derive(Clone, Debug, PartialEq, Packet)]
312pub struct ClientsideUnloadChunk {
313  pub chunk_x: i32,
314  pub chunk_z: i32,
315}
316
317#[derive(Clone, Debug, PartialEq, Packet)]
318pub struct ClientsideGameEvent {
319  pub event: GameEvent,
320  pub value: f32,
321}
322
323#[derive(Clone, Debug, PartialEq, Packet)]
324pub struct ClientsideClearChat {
325  #[packet(varint)]
326  pub message_id: i32,
327  pub signature: Option<Vec<u8>>,
328}
329
330#[derive(Clone, Debug, PartialEq, Packet)]
331pub struct ClientsideLoadChunkWithLight {
332  pub chunk_x: i32,
333  pub chunk_z: i32,
334  pub chunk_data: Vec<u8>,
335  pub light_data: Vec<u8>,
336}
337
338#[derive(Clone, Debug, PartialEq, Packet)]
339pub struct ClientsideBlockUpdate {
340  pub block_pos: BlockPosition,
341  #[packet(varint)]
342  pub block_state: i32,
343}
344
345#[derive(Clone, Debug, PartialEq, Packet)]
346pub struct ClientsideContainerSetContent {
347  #[packet(varint)]
348  pub container_id: i32,
349  #[packet(varint)]
350  pub state_id: i32,
351  pub items: Vec<Item>,
352  pub carried_item: Item,
353}
354
355#[derive(Clone, Debug, PartialEq, Packet)]
356pub struct ClientsideContainerSetSlot {
357  #[packet(varint)]
358  pub container_id: i32,
359  #[packet(varint)]
360  pub state_id: i32,
361  pub slot: i16,
362  pub item: Item,
363}
364
365#[derive(Clone, Debug, PartialEq, Packet)]
366pub struct ClientsideChunkBatchStart;
367
368#[derive(Clone, Debug, PartialEq, Packet)]
369pub struct ClientsideChunkBatchFinished {
370  #[packet(varint)]
371  pub batch_size: i32,
372}
373
374#[derive(Clone, Debug, PartialEq, Packet)]
375pub struct ClientsideLightUpdate {
376  #[packet(varint)]
377  pub chunk_x: i32,
378  #[packet(varint)]
379  pub chunk_z: i32,
380  pub light_data: Vec<u8>,
381}
382
383#[derive(Clone, Debug, PartialEq, Packet)]
384pub struct ClientsideCloseContainer {
385  #[packet(varint)]
386  pub container_id: i32,
387}
388
389#[derive(Clone, Debug, PartialEq, Packet)]
390pub struct ClientsideContainerSetData {
391  #[packet(varint)]
392  pub container_id: i32,
393  #[packet(varint)]
394  pub property: i32,
395  #[packet(varint)]
396  pub value: i32,
397}
398
399#[derive(Clone, Debug, PartialEq, Packet)]
400pub struct ServersidePong {
401  pub id: i32,
402}
403
404#[derive(Clone, Debug, PartialEq, Packet)]
405pub struct ServersidePingRequest {
406  pub timestamp: i64,
407}
408
409#[derive(Clone, Debug, PartialEq, Packet)]
410pub struct ServersideAcceptTeleportation {
411  #[packet(varlong)]
412  pub teleport_id: i64,
413}
414
415#[derive(Clone, Debug, PartialEq, Packet)]
416pub struct ServersideSwingArm {
417  pub hand: RelativeHand,
418}
419
420#[derive(Clone, Debug, PartialEq, Packet)]
421pub struct ServersideUseItem {
422  pub hand: RelativeHand,
423  #[packet(varint)]
424  pub sequence: i32,
425  pub rotation: Rotation,
426}
427
428#[derive(Clone, Debug, PartialEq, Packet)]
429pub struct ServersideMovePlayerPos {
430  pub position: Vector3,
431  pub flags: PhysicsFlags,
432}
433
434#[derive(Clone, Debug, PartialEq, Packet)]
435pub struct ServersideMovePlayerRot {
436  pub rotation: Rotation,
437  pub flags: PhysicsFlags,
438}
439
440#[derive(Clone, Debug, PartialEq, Packet)]
441pub struct ServersideMovePlayerPosRot {
442  pub position: Vector3,
443  pub rotation: Rotation,
444  pub flags: PhysicsFlags,
445}
446
447#[derive(Clone, Debug, PartialEq, Packet)]
448pub struct ServersideMovePlayerStatusOnly {
449  pub flags: PhysicsFlags,
450}
451
452#[derive(Clone, Debug, PartialEq, Packet)]
453pub struct ServersideClientCommand {
454  pub command: ClientCommand,
455}
456
457#[derive(Clone, Debug, PartialEq, Packet)]
458pub struct ServersideChatCommand {
459  pub command: String,
460}
461
462#[derive(Clone, Debug, PartialEq, Packet)]
463pub struct ServersideChatMessage {
464  pub message: String,
465  pub timestamp: i64,
466  pub salt: i64,
467  pub signature: Option<Vec<u8>>,
468  pub additional_info: AdditionalMessageInfo,
469}
470
471#[derive(Clone, Debug, PartialEq, Packet)]
472pub struct ServersideSetHeldItem {
473  pub slot: i16,
474}
475
476#[derive(Clone, Debug, PartialEq, Packet)]
477pub struct ServersideInteract {
478  #[packet(varint)]
479  pub entity: i32,
480  pub interact_type: InteractType,
481  pub target_x: Option<f32>,
482  pub target_y: Option<f32>,
483  pub target_z: Option<f32>,
484  pub hand: Option<RelativeHand>,
485  pub sneak_key_pressed: bool,
486}
487
488#[derive(Clone, Debug, PartialEq, Packet)]
489pub struct ServersidePlayerAction {
490  pub action: PlayerAction,
491  pub block_pos: BlockPosition,
492  pub face: Face,
493  #[packet(varint)]
494  pub sequence: i32,
495}
496
497#[derive(Clone, Debug, PartialEq, Packet)]
498pub struct ServersidePlayerCommand {
499  #[packet(varint)]
500  pub entity_id: i32,
501  pub command: PlayerCommand,
502  #[packet(varint)]
503  pub jump_boost: i32,
504}
505
506#[derive(Clone, Debug, PartialEq, Packet)]
507pub struct ServersideResourcePackResponse {
508  pub uuid: Uuid,
509  pub state: ResourcePackState,
510}
511
512#[derive(Clone, Debug, PartialEq, Packet)]
513pub struct ServersideContainerClick {
514  #[packet(varint)]
515  pub container_id: i32,
516  #[packet(varint)]
517  pub state_id: i32,
518  pub slot: i16,
519  pub button: i8,
520  #[packet(varint)]
521  pub mode: i32,
522  pub clicked_item: Item,
523}
524
525#[derive(Clone, Debug, PartialEq, Packet)]
526pub struct ServersideContainerClose {
527  #[packet(varint)]
528  pub container_id: i32,
529}
530
531#[derive(Clone, Debug, PartialEq, Packet)]
532pub struct ServersideEditBook {
533  pub slot: i32,
534  pub pages: Vec<String>,
535  pub title: Option<String>,
536}