diff --git a/protocol-generator/Cargo.toml b/protocol-generator/Cargo.toml index 9b325a4..d73dba6 100644 --- a/protocol-generator/Cargo.toml +++ b/protocol-generator/Cargo.toml @@ -10,7 +10,6 @@ repository = "https://github.com/eihwaz/minecraft-protocol" keywords = ["minecraft", "cli", "protocol", "packet", "io"] [dependencies] -structopt = "0.3" serde = "1.0.120" serde_json = "1.0" handlebars = "3.5.2" diff --git a/protocol-generator/minecraft-data b/protocol-generator/minecraft-data index e656aaf..cc155f3 160000 --- a/protocol-generator/minecraft-data +++ b/protocol-generator/minecraft-data @@ -1 +1 @@ -Subproject commit e656aafb77f477d3726ed46209f0d4bb7052a04b +Subproject commit cc155f399397755abeb9275de40fc82b65a252f4 diff --git a/protocol-generator/src/backend.rs b/protocol-generator/src/backend.rs index 316d929..4e2c43b 100644 --- a/protocol-generator/src/backend.rs +++ b/protocol-generator/src/backend.rs @@ -26,7 +26,8 @@ pub struct Packets { #[serde(untagged)] pub enum Data { Type(String), - Container(Vec), + Containers(Vec), + Container(Box), Mapper { #[serde(rename = "type")] mappings_type: String, diff --git a/protocol-generator/src/frontend.rs b/protocol-generator/src/frontend.rs index 49ce8f1..90d9dab 100644 --- a/protocol-generator/src/frontend.rs +++ b/protocol-generator/src/frontend.rs @@ -1,13 +1,16 @@ -use crate::frontend; +use crate::mappings::Mappings; +use crate::{backend, frontend, transformers}; use handlebars::{Handlebars, TemplateRenderError}; use serde::Serialize; use serde_json::json; -use std::collections::HashSet; +use std::collections::{HashMap, HashSet}; use std::fmt; use std::fmt::Display; +use std::fs::{create_dir_all, File}; use std::io::Write; +use std::path::Path; -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub enum State { Handshake, Status, @@ -16,7 +19,7 @@ pub enum State { } impl State { - pub fn data_import(&self) -> &str { + pub fn data_import(&self) -> &'static str { match self { State::Handshake => "crate::data::handshake::*", State::Status => "crate::data::status::*", @@ -109,6 +112,8 @@ pub enum DataType { Int { var_int: bool, }, + #[serde(rename(serialize = "u32"))] + UnsignedInt, #[serde(rename(serialize = "i64"))] Long { var_long: bool, @@ -136,7 +141,7 @@ pub enum DataType { } impl DataType { - pub fn import<'a>(&self, state: &'a State) -> Option<&'a str> { + pub fn import(&self, state: &State) -> Option<&'static str> { match self { DataType::Uuid { .. } => Some("uuid::Uuid"), DataType::CompoundTag => Some("nbt::CompoundTag"), @@ -149,75 +154,156 @@ impl DataType { #[derive(Debug)] pub struct Protocol { - pub state: State, pub server_bound_packets: Vec, pub client_bound_packets: Vec, } impl Protocol { - pub fn new( - state: State, - server_bound_packets: Vec, - client_bound_packets: Vec, - ) -> Protocol { + pub fn new(server_bound_packets: Vec, client_bound_packets: Vec) -> Protocol { Protocol { - state, server_bound_packets, client_bound_packets, } } - pub fn data_type_imports(&self) -> HashSet<&str> { + pub fn data_type_imports(&self, state: &State) -> HashSet<&'static str> { self.server_bound_packets .iter() .chain(self.client_bound_packets.iter()) .flat_map(|p| p.fields.iter()) - .filter_map(|f| f.data_type.import(&self.state)) + .filter_map(|f| f.data_type.import(state)) .collect() } } -#[derive(Serialize)] -struct GenerateContext<'a> { - packet_enum_name: String, - packets: &'a Vec, -} - -pub fn generate_rust_file( - protocol: &frontend::Protocol, +pub fn generate_rust_files( + versions_data: HashMap, template_engine: &Handlebars, - mut writer: W, + mappings: &M, ) -> Result<(), TemplateRenderError> { - let server_bound_ctx = GenerateContext { - packet_enum_name: format!("{}{}BoundPacket", &protocol.state, frontend::Bound::Server), - packets: &protocol.server_bound_packets, - }; + generate_versions_module_file(template_engine, versions_data.keys().cloned().collect())?; - let client_bound_ctx = GenerateContext { - packet_enum_name: format!("{}{}BoundPacket", &protocol.state, frontend::Bound::Client), - packets: &protocol.client_bound_packets, - }; + for (version, data_file) in versions_data.iter() { + println!("Generating protocol data for version {}", version); - let mut imports = vec![ - "crate::DecodeError", - "crate::Decoder", - "std::io::Read", - "minecraft_protocol_derive::Packet", - ]; + let protocol_handler: backend::ProtocolHandler = + serde_json::from_reader(data_file).expect("Failed to parse protocol data"); - imports.extend(protocol.data_type_imports().iter()); + let frontend_protocols = + transformers::transform_protocol_handler(mappings, &protocol_handler); - template_engine.render_to_write( - "packet_imports", - &json!({ "imports": imports }), - &mut writer, - )?; + let formatted_version = version.replace(".", "_").replace("-", "_"); - template_engine.render_to_write("packet_enum", &server_bound_ctx, &mut writer)?; - template_engine.render_to_write("packet_enum", &client_bound_ctx, &mut writer)?; + let folder_name = format!("protocol/src/version/v_{}", formatted_version); + let folder_path = Path::new(&folder_name); - template_engine.render_to_write("packet_structs", &server_bound_ctx, &mut writer)?; - template_engine.render_to_write("packet_structs", &client_bound_ctx, &mut writer)?; + generate_protocol_module_file(template_engine, &folder_path)?; + + for (protocol, state) in frontend_protocols { + let file_name = format!("{}.rs", state.to_string().to_lowercase()); + + let mut file = File::create(folder_path.join(file_name)) + .expect("Failed to create protocol enum file"); + + generate_protocol_enum_header(template_engine, &protocol, &state, &mut file)?; + + generate_protocol_enum_content( + template_engine, + &protocol.server_bound_packets, + &state, + &Bound::Server, + &mut file, + )?; + + generate_protocol_enum_content( + template_engine, + &protocol.client_bound_packets, + &state, + &Bound::Client, + &mut file, + )?; + + generate_packets_structs(template_engine, &protocol.server_bound_packets, &mut file)?; + + generate_packets_structs(template_engine, &protocol.client_bound_packets, &mut file)?; + } + } + + Ok(()) +} + +fn generate_versions_module_file( + template_engine: &Handlebars, + versions: Vec, +) -> Result<(), TemplateRenderError> { + let mut file = + File::create("protocol/src/version/mod.rs").expect("Failed to create versions module file"); + + let ctx = json!({ "versions": versions }); + + template_engine.render_to_write("protocol_versions_module", &ctx, &mut file)?; + + Ok(()) +} + +fn generate_protocol_module_file( + template_engine: &Handlebars, + folder_path: &Path, +) -> Result<(), TemplateRenderError> { + generate_module_file(template_engine, folder_path, "protocol_module") +} + +fn generate_module_file( + template_engine: &Handlebars, + folder_path: &Path, + name: &str, +) -> Result<(), TemplateRenderError> { + create_dir_all(folder_path).expect("Failed to create module folder"); + + let mut file = File::create(folder_path.join("mod.rs")).expect("Failed to create module file"); + + template_engine.render_to_write(name, &(), &mut file)?; + + Ok(()) +} + +fn generate_protocol_enum_header( + template_engine: &Handlebars, + protocol: &frontend::Protocol, + state: &frontend::State, + write: &mut W, +) -> Result<(), TemplateRenderError> { + let imports = protocol.data_type_imports(state); + let ctx = json!({ "imports": imports }); + + template_engine.render_to_write("protocol_header", &ctx, write)?; + + Ok(()) +} + +fn generate_protocol_enum_content( + template_engine: &Handlebars, + packets: &Vec, + state: &frontend::State, + bound: &frontend::Bound, + write: &mut W, +) -> Result<(), TemplateRenderError> { + let protocol_enum_name = format!("{}Bound{}Packet", bound, state); + let ctx = json!({ "protocol_enum_name": protocol_enum_name, "packets": packets }); + + template_engine.render_to_write("protocol_enum", &ctx, write)?; + + Ok(()) +} + +fn generate_packets_structs( + template_engine: &Handlebars, + packets: &Vec, + write: &mut W, +) -> Result<(), TemplateRenderError> { + let ctx = json!({ "packets": packets }); + + template_engine.render_to_write("packets_structs", &ctx, write)?; Ok(()) } diff --git a/protocol-generator/src/main.rs b/protocol-generator/src/main.rs index ecc1d61..d16b6ca 100644 --- a/protocol-generator/src/main.rs +++ b/protocol-generator/src/main.rs @@ -1,7 +1,9 @@ use std::fs::File; use crate::mappings::CodeMappings; -use structopt::StructOpt; +use std::fs; +use std::io::Error; +use std::path::Path; pub mod backend; pub mod frontend; @@ -9,74 +11,47 @@ pub mod mappings; pub mod templates; pub mod transformers; -#[derive(StructOpt)] -#[structopt(name = "protocol-generator")] -struct Opt { - #[structopt(short, long, default_value = "1.14.4")] - protocol_version: String, -} - pub fn main() { - let opt: Opt = Opt::from_args(); + let paths = fs::read_dir("protocol-generator/minecraft-data/data/pc/") + .expect("Failed to open data folder"); + + let versions_data = paths + .into_iter() + .map(|entry| { + entry + .expect("Failed to get dir entry") + .file_name() + .into_string() + .expect("Failed to get version string") + }) + .filter(|version| match version.as_str() { + "0.30c" => false, // A very old version with a lot of incompatibility. + "1.7" => false, // Requires some fixes to support. + _ => true, + }) + .filter_map(|version| { + let protocol_data_file_name = format!( + "protocol-generator/minecraft-data/data/pc/{}/protocol.json", + version + ); + + let protocol_data_file_path = Path::new(&protocol_data_file_name); + + match protocol_data_file_path.exists() { + true => { + let protocol_data_file = File::open(protocol_data_file_path) + .expect("Failed to open protocol data file"); + + Some((version, protocol_data_file)) + } + false => None, + } + }) + .collect(); + let template_engine = templates::create_template_engine(); + let mappings = CodeMappings::new(); - let protocol_data_file_name = format!( - "protocol-generator/minecraft-data/data/pc/{}/protocol.json", - opt.protocol_version - ); - - let protocol_data_file = - File::open(protocol_data_file_name).expect("Failed to open protocol data file"); - - let protocol_handler: backend::ProtocolHandler = - serde_json::from_reader(protocol_data_file).expect("Failed to parse protocol data"); - - let mappings = CodeMappings {}; - - let protocols = vec![ - ( - transformers::transform_protocol( - &mappings, - frontend::State::Handshake, - &protocol_handler.handshaking, - ), - frontend::State::Handshake, - ), - ( - transformers::transform_protocol( - &mappings, - frontend::State::Status, - &protocol_handler.status, - ), - frontend::State::Status, - ), - ( - transformers::transform_protocol( - &mappings, - frontend::State::Login, - &protocol_handler.login, - ), - frontend::State::Login, - ), - ( - transformers::transform_protocol( - &mappings, - frontend::State::Game, - &protocol_handler.game, - ), - frontend::State::Game, - ), - ]; - - for (protocol, state) in protocols { - let file_name = format!( - "protocol/src/packet/{}.rs", - state.to_string().to_lowercase() - ); - - let file = File::create(file_name).expect("Failed to create file"); - - frontend::generate_rust_file(&protocol, &template_engine, &file) - .expect("Failed to generate rust file"); - } + frontend::generate_rust_files(versions_data, &template_engine, &mappings) + .expect("Failed to generate rust files"); } diff --git a/protocol-generator/src/mappings.rs b/protocol-generator/src/mappings.rs index 5716322..692cdca 100644 --- a/protocol-generator/src/mappings.rs +++ b/protocol-generator/src/mappings.rs @@ -15,6 +15,12 @@ pub trait Mappings { pub struct CodeMappings {} +impl CodeMappings { + pub fn new() -> CodeMappings { + CodeMappings {} + } +} + impl Mappings for CodeMappings { fn rename_packet( &self, @@ -50,15 +56,15 @@ impl Mappings for CodeMappings { fn change_field_type(&self, packet_name: &str, field: frontend::Field) -> frontend::Field { match (packet_name, field.name.as_str()) { - ("StatusResponse", "response") => field.change_type(frontend::DataType::RefType { - ref_name: "ServerStatus".to_owned(), - }), - ("Success", "uuid") => field.change_type(frontend::DataType::Uuid { hyphenated: true }), - ("Disconnect", "reason") => field.change_type(frontend::DataType::Chat), - ("ClientBoundChat", "message") => field.change_type(frontend::DataType::Chat), - ("ClientBoundChat", "position") => field.change_type(frontend::DataType::RefType { - ref_name: "MessagePosition".to_owned(), - }), + // ("StatusResponse", "response") => field.change_type(frontend::DataType::RefType { + // ref_name: "ServerStatus".to_owned(), + // }), + // ("Success", "uuid") => field.change_type(frontend::DataType::Uuid { hyphenated: true }), + // ("Disconnect", "reason") => field.change_type(frontend::DataType::Chat), + // ("ClientBoundChat", "message") => field.change_type(frontend::DataType::Chat), + // ("ClientBoundChat", "position") => field.change_type(frontend::DataType::RefType { + // ref_name: "MessagePosition".to_owned(), + // }), _ => field, } } diff --git a/protocol-generator/src/templates.rs b/protocol-generator/src/templates.rs index 2bc1993..207eec3 100644 --- a/protocol-generator/src/templates.rs +++ b/protocol-generator/src/templates.rs @@ -6,30 +6,25 @@ pub fn create_template_engine() -> Handlebars<'static> { template_engine.register_helper("snake_case", Box::new(format_snake_case)); template_engine.register_helper("packet_id", Box::new(format_packet_id)); + template_engine.register_helper( + "protocol_version_module", + Box::new(format_protocol_version_module), + ); template_engine.register_escape_fn(|s| s.to_owned()); - template_engine - .register_template_file( - "packet_imports", - "protocol-generator/templates/packet_imports.hbs", - ) - .expect("Failed to register template"); + register_template_file(&mut template_engine, "protocol_versions_module"); + register_template_file(&mut template_engine, "protocol_module"); + register_template_file(&mut template_engine, "protocol_enum"); + register_template_file(&mut template_engine, "packets_structs"); + register_template_file(&mut template_engine, "protocol_header"); template_engine - .register_template_file( - "packet_enum", - "protocol-generator/templates/packet_enum.hbs", - ) - .expect("Failed to register template"); +} +fn register_template_file(template_engine: &mut Handlebars, name: &str) { template_engine - .register_template_file( - "packet_structs", - "protocol-generator/templates/packet_structs.hbs", - ) + .register_template_file(name, format!("protocol-generator/templates/{}.hbs", name)) .expect("Failed to register template"); - - template_engine } fn format_snake_case( @@ -71,3 +66,24 @@ fn format_packet_id( out.write(packet_id_str.as_ref())?; Ok(()) } + +fn format_protocol_version_module( + h: &Helper, + _: &Handlebars, + _: &Context, + _: &mut RenderContext, + out: &mut dyn Output, +) -> Result<(), RenderError> { + let version = h + .param(0) + .and_then(|v| v.value().as_str()) + .ok_or(RenderError::new( + "Param 0 with str type is required for packet id helper.", + ))? as &str; + + let formatted_protocol_module_version = + format!("v_{}", version.replace(".", "_").replace("-", "_")); + + out.write(formatted_protocol_module_version.as_ref())?; + Ok(()) +} diff --git a/protocol-generator/src/transformers.rs b/protocol-generator/src/transformers.rs index 155bb8e..7e04aeb 100644 --- a/protocol-generator/src/transformers.rs +++ b/protocol-generator/src/transformers.rs @@ -1,12 +1,34 @@ -use crate::backend::Data; use crate::mappings::Mappings; use crate::{backend, frontend}; use heck::{CamelCase, SnakeCase}; use std::collections::HashMap; -pub fn transform_protocol( +pub fn transform_protocol_handler( + mappings: &M, + protocol_handler: &backend::ProtocolHandler, +) -> Vec<(frontend::Protocol, frontend::State)> { + vec![ + ( + transform_protocol::(&mappings, &protocol_handler.handshaking), + frontend::State::Handshake, + ), + ( + transform_protocol::(&mappings, &protocol_handler.status), + frontend::State::Status, + ), + ( + transform_protocol::(&mappings, &protocol_handler.login), + frontend::State::Login, + ), + ( + transform_protocol::(&mappings, &protocol_handler.game), + frontend::State::Game, + ), + ] +} + +fn transform_protocol( mappings: &M, - state: frontend::State, protocol: &backend::Protocol, ) -> frontend::Protocol { let server_bound_packets = transform_packets( @@ -24,7 +46,6 @@ pub fn transform_protocol( ); frontend::Protocol { - state, server_bound_packets, client_bound_packets, } @@ -36,7 +57,7 @@ fn get_packet_ids(packets: &backend::Packets) -> HashMap { .get("packet") .and_then(|d| d.get(1)) .and_then(|d| match d { - backend::Data::Container(data) => data.get(0), + backend::Data::Containers(data) => data.get(0), _ => None, }) .and_then(|c| match c { @@ -92,7 +113,7 @@ fn transform_packets( let mut fields = vec![]; for data in data_vec { - if let backend::Data::Container(container_vec) = data { + if let backend::Data::Containers(container_vec) = data { for container in container_vec { match container { backend::Container::Value { name, data } => { @@ -183,6 +204,7 @@ fn transform_data_type(name: &str) -> Option { "i64" => Some(frontend::DataType::Long { var_long: false }), "u8" => Some(frontend::DataType::UnsignedByte), "u16" => Some(frontend::DataType::UnsignedShort), + "u32" => Some(frontend::DataType::UnsignedInt), "f32" => Some(frontend::DataType::Float), "f64" => Some(frontend::DataType::Double), "varint" => Some(frontend::DataType::Int { var_int: true }), diff --git a/protocol-generator/templates/packet_structs.hbs b/protocol-generator/templates/packets_structs.hbs similarity index 98% rename from protocol-generator/templates/packet_structs.hbs rename to protocol-generator/templates/packets_structs.hbs index c6d4822..4a4b1b6 100644 --- a/protocol-generator/templates/packet_structs.hbs +++ b/protocol-generator/templates/packets_structs.hbs @@ -21,4 +21,4 @@ pub struct {{p.name}} { {{~/each}} } {{/if}} -{{~/each}} +{{~/each}} \ No newline at end of file diff --git a/protocol-generator/templates/packet_enum.hbs b/protocol-generator/templates/protocol_enum.hbs similarity index 85% rename from protocol-generator/templates/packet_enum.hbs rename to protocol-generator/templates/protocol_enum.hbs index c596a16..9fcc228 100644 --- a/protocol-generator/templates/packet_enum.hbs +++ b/protocol-generator/templates/protocol_enum.hbs @@ -1,15 +1,15 @@ {{~#if packets}} -pub enum {{packet_enum_name}} { +pub enum {{protocol_enum_name}} { {{~#each packets as |p|}} - {{p.name}}{{#if p.fields}}({{p.name}}){{/if}}{{#unless @last}},{{/unless}} + {{p.name}}{{#if p.fields}}({{p.name}}){{/if}}, {{~/each}} } -impl {{packet_enum_name}} { +impl {{protocol_enum_name}} { pub fn get_type_id(&self) -> u8 { match self { {{~#each packets as |p|}} - Self::{{p.name}}{{#if p.fields}}(_){{/if}} => {{packet_id p.id}}{{#unless @last}},{{/unless}} + Self::{{p.name}}{{#if p.fields}}(_){{/if}} => {{packet_id p.id}}, {{~/each}} } } @@ -36,7 +36,7 @@ impl {{packet_enum_name}} { {{~#if p.fields}} let {{snake_case p.name}} = {{p.name}} { {{~#each p.fields as |f|}} - {{f.name}}{{#unless @last}},{{/unless}} + {{f.name}}, {{~/each}} }; diff --git a/protocol-generator/templates/protocol_header.hbs b/protocol-generator/templates/protocol_header.hbs new file mode 100644 index 0000000..7a835db --- /dev/null +++ b/protocol-generator/templates/protocol_header.hbs @@ -0,0 +1,10 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use std::io::Read; +use minecraft_protocol_derive::Packet; + +{{#each imports as |i|~}} +use {{i}}; +{{/each~}} diff --git a/protocol-generator/templates/packet_imports.hbs b/protocol-generator/templates/protocol_module.hbs similarity index 56% rename from protocol-generator/templates/packet_imports.hbs rename to protocol-generator/templates/protocol_module.hbs index a97ad24..5b823c9 100644 --- a/protocol-generator/templates/packet_imports.hbs +++ b/protocol-generator/templates/protocol_module.hbs @@ -1,5 +1,6 @@ // This file is automatically generated. // It is not intended for manual editing. -{{#each imports as |i|~}} -use {{i}}; -{{/each~}} +pub mod handshake; +pub mod status; +pub mod login; +pub mod game; diff --git a/protocol-generator/templates/protocol_versions_module.hbs b/protocol-generator/templates/protocol_versions_module.hbs new file mode 100644 index 0000000..0d562af --- /dev/null +++ b/protocol-generator/templates/protocol_versions_module.hbs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +{{#each versions as |v|~}} +#[cfg(feature = "{{v}}")] +pub mod {{protocol_version_module v}}; +{{/each~}} diff --git a/protocol/src/data/game.rs b/protocol/src/data/game.rs deleted file mode 100644 index fdc6860..0000000 --- a/protocol/src/data/game.rs +++ /dev/null @@ -1,47 +0,0 @@ -use crate::impl_enum_encoder_decoder; -use nbt::CompoundTag; -use num_derive::{FromPrimitive, ToPrimitive}; -use std::io::{Read, Write}; - -#[derive(Debug, Eq, PartialEq, FromPrimitive, ToPrimitive)] -pub enum MessagePosition { - Chat, - System, - HotBar, -} - -impl_enum_encoder_decoder!(MessagePosition); - -#[derive(Debug, Eq, PartialEq, FromPrimitive, ToPrimitive)] -pub enum GameMode { - Survival = 0, - Creative = 1, - Adventure = 2, - Spectator = 3, - Hardcore = 8, -} - -impl_enum_encoder_decoder!(GameMode); - -#[derive(Debug, Eq, PartialEq)] -pub struct Position { - pub x: i32, - pub y: i16, - pub z: i32, -} - -#[derive(Debug)] -pub struct Slot { - pub id: i32, - pub amount: u8, - pub compound_tag: CompoundTag, -} - -#[derive(Debug)] -pub struct Metadata {} - -#[derive(Debug)] -pub struct TagsMap {} - -#[derive(Debug)] -pub struct ParticleData {} diff --git a/protocol/src/data/mod.rs b/protocol/src/data/mod.rs index 02b3360..a9b9724 100644 --- a/protocol/src/data/mod.rs +++ b/protocol/src/data/mod.rs @@ -1,3 +1,2 @@ pub mod chat; -pub mod game; -pub mod status; +pub mod server_status; diff --git a/protocol/src/data/status.rs b/protocol/src/data/server_status.rs similarity index 100% rename from protocol/src/data/status.rs rename to protocol/src/data/server_status.rs diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index 9c3adbd..0ec9af1 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -10,12 +10,11 @@ use uuid::Uuid; use data::chat::Message; -use crate::data::game::{Metadata, ParticleData, Position, Slot, TagsMap}; use crate::error::{DecodeError, EncodeError}; pub mod data; pub mod error; -pub mod packet; +pub mod version; /// Current supported protocol version. pub const PROTOCOL_VERSION: u32 = 498; @@ -510,123 +509,6 @@ macro_rules! impl_json_encoder_decoder ( ); ); -impl Encoder for Position { - fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { - let encoded_x = (self.x & 0x3FFFFFF) as i64; - let encoded_y = (self.y & 0xFFF) as i64; - let encoded_z = (self.z & 0x3FFFFFF) as i64; - - writer.write_i64::((encoded_x << 38) | (encoded_z << 12) | encoded_y)?; - Ok(()) - } -} - -impl Decoder for Position { - type Output = Self; - - fn decode(reader: &mut R) -> Result { - let encoded = reader.read_i64::()?; - - let x = (encoded >> 38) as i32; - let y = (encoded & 0xFFF) as i16; - let z = (encoded << 26 >> 38) as i32; - - Ok(Position { x, y, z }) - } -} - -impl Encoder for Option { - fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { - match self { - Some(slot) => { - writer.write_bool(true)?; - slot.encode(writer) - } - None => writer.write_bool(false), - } - } -} - -impl Decoder for Option { - type Output = Self; - - fn decode(reader: &mut R) -> Result { - if reader.read_bool()? { - Ok(Some(Slot::decode(reader)?)) - } else { - Ok(None) - } - } -} - -impl Encoder for Slot { - fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { - writer.write_var_i32(self.id)?; - writer.write_u8(self.amount)?; - writer.write_compound_tag(&self.compound_tag)?; - - Ok(()) - } -} - -impl Decoder for Slot { - type Output = Self; - - fn decode(reader: &mut R) -> Result { - let id = reader.read_var_i32()?; - let amount = reader.read_u8()?; - let compound_tag = reader.read_compound_tag()?; - - Ok(Slot { - id, - amount, - compound_tag, - }) - } -} - -impl Encoder for Metadata { - fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { - unimplemented!() - } -} - -impl Decoder for Metadata { - type Output = Self; - - fn decode(reader: &mut R) -> Result { - unimplemented!() - } -} - -impl Encoder for TagsMap { - fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { - unimplemented!() - } -} - -impl Decoder for TagsMap { - type Output = Self; - - fn decode(reader: &mut R) -> Result { - unimplemented!() - } -} - -impl Encoder for ParticleData { - fn encode(&self, writer: &mut W) -> Result<(), EncodeError> { - unimplemented!() - } -} - -impl Decoder for ParticleData { - type Output = Self; - - fn decode(reader: &mut R) -> Result { - unimplemented!() - } -} - mod var_int { use std::io::{Read, Write}; diff --git a/protocol/src/packet/mod.rs b/protocol/src/packet/mod.rs deleted file mode 100644 index 29a91c1..0000000 --- a/protocol/src/packet/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod game; -pub mod handshake; -pub mod login; -pub mod status; diff --git a/protocol/src/version/mod.rs b/protocol/src/version/mod.rs new file mode 100644 index 0000000..c2ed117 --- /dev/null +++ b/protocol/src/version/mod.rs @@ -0,0 +1,72 @@ +// This file is automatically generated. +// It is not intended for manual editing. +#[cfg(feature = "15w40b")] +pub mod v_15w40b; +#[cfg(feature = "16w20a")] +pub mod v_16w20a; +#[cfg(feature = "16w35a")] +pub mod v_16w35a; +#[cfg(feature = "17w15a")] +pub mod v_17w15a; +#[cfg(feature = "17w18b")] +pub mod v_17w18b; +#[cfg(feature = "17w50a")] +pub mod v_17w50a; +#[cfg(feature = "1.10")] +pub mod v_1_10; +#[cfg(feature = "1.10-pre1")] +pub mod v_1_10_pre1; +#[cfg(feature = "1.11")] +pub mod v_1_11; +#[cfg(feature = "1.12")] +pub mod v_1_12; +#[cfg(feature = "1.12.1")] +pub mod v_1_12_1; +#[cfg(feature = "1.12.2")] +pub mod v_1_12_2; +#[cfg(feature = "1.12-pre4")] +pub mod v_1_12_pre4; +#[cfg(feature = "1.13")] +pub mod v_1_13; +#[cfg(feature = "1.13.1")] +pub mod v_1_13_1; +#[cfg(feature = "1.13.2")] +pub mod v_1_13_2; +#[cfg(feature = "1.13.2-pre1")] +pub mod v_1_13_2_pre1; +#[cfg(feature = "1.13.2-pre2")] +pub mod v_1_13_2_pre2; +#[cfg(feature = "1.14")] +pub mod v_1_14; +#[cfg(feature = "1.14.1")] +pub mod v_1_14_1; +#[cfg(feature = "1.14.3")] +pub mod v_1_14_3; +#[cfg(feature = "1.14.4")] +pub mod v_1_14_4; +#[cfg(feature = "1.15")] +pub mod v_1_15; +#[cfg(feature = "1.15.1")] +pub mod v_1_15_1; +#[cfg(feature = "1.15.2")] +pub mod v_1_15_2; +#[cfg(feature = "1.16")] +pub mod v_1_16; +#[cfg(feature = "1.16.1")] +pub mod v_1_16_1; +#[cfg(feature = "1.16.2")] +pub mod v_1_16_2; +#[cfg(feature = "1.16-rc1")] +pub mod v_1_16_rc1; +#[cfg(feature = "1.8")] +pub mod v_1_8; +#[cfg(feature = "1.9")] +pub mod v_1_9; +#[cfg(feature = "1.9.1-pre2")] +pub mod v_1_9_1_pre2; +#[cfg(feature = "1.9.2")] +pub mod v_1_9_2; +#[cfg(feature = "1.9.4")] +pub mod v_1_9_4; +#[cfg(feature = "20w13b")] +pub mod v_20w13b; diff --git a/protocol/src/version/v_15w40b/game.rs b/protocol/src/version/v_15w40b/game.rs new file mode 100644 index 0000000..9031633 --- /dev/null +++ b/protocol/src/version/v_15w40b/game.rs @@ -0,0 +1,2555 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundChat(ServerBoundChat), + UseEntity(UseEntity), + Flying(Flying), + ServerBoundPosition(ServerBoundPosition), + Look(Look), + PositionLook(PositionLook), + BlockDig(BlockDig), + BlockPlace(BlockPlace), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + ArmAnimation(ArmAnimation), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + ServerBoundCloseWindow(ServerBoundCloseWindow), + WindowClick(WindowClick), + ServerBoundTransaction(ServerBoundTransaction), + SetCreativeSlot(SetCreativeSlot), + EnchantItem(EnchantItem), + ServerBoundUpdateSign(ServerBoundUpdateSign), + ServerBoundAbilities(ServerBoundAbilities), + ServerBoundTabComplete(ServerBoundTabComplete), + Settings(Settings), + ClientCommand(ClientCommand), + ServerBoundCustomPayload(ServerBoundCustomPayload), + Spectate(Spectate), + ResourcePackReceive(ResourcePackReceive), + UseItem(UseItem), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::ServerBoundKeepAlive(_) => 0x0A, + Self::ServerBoundChat(_) => 0x01, + Self::UseEntity(_) => 0x09, + Self::Flying(_) => 0x0E, + Self::ServerBoundPosition(_) => 0x0B, + Self::Look(_) => 0x0D, + Self::PositionLook(_) => 0x0C, + Self::BlockDig(_) => 0x10, + Self::BlockPlace(_) => 0x19, + Self::ServerBoundHeldItemSlot(_) => 0x14, + Self::ArmAnimation(_) => 0x17, + Self::EntityAction(_) => 0x11, + Self::SteerVehicle(_) => 0x12, + Self::ServerBoundCloseWindow(_) => 0x07, + Self::WindowClick(_) => 0x06, + Self::ServerBoundTransaction(_) => 0x04, + Self::SetCreativeSlot(_) => 0x15, + Self::EnchantItem(_) => 0x05, + Self::ServerBoundUpdateSign(_) => 0x16, + Self::ServerBoundAbilities(_) => 0x0F, + Self::ServerBoundTabComplete(_) => 0x00, + Self::Settings(_) => 0x03, + Self::ClientCommand(_) => 0x02, + Self::ServerBoundCustomPayload(_) => 0x08, + Self::Spectate(_) => 0x18, + Self::ResourcePackReceive(_) => 0x13, + Self::UseItem(_) => 0x1A, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x0A => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x01 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x09 => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0E => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x0B => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0D => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0C => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x10 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x19 => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x14 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x17 => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x11 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x12 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x07 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x06 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x04 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x15 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x05 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x16 => { + let server_bound_update_sign = ServerBoundUpdateSign::decode(reader)?; + + Ok(Self::ServerBoundUpdateSign(server_bound_update_sign)) + } + 0x0F => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x00 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x02 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x08 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x18 => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x13 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x1A => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: i8, + cursor_y: i8, + cursor_z: i8, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn server_bound_update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let server_bound_update_sign = ServerBoundUpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::ServerBoundUpdateSign(server_bound_update_sign) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn server_bound_tab_complete(text: String, block: Position) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { text, block }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn client_command(payload: i32) -> Self { + let client_command = ClientCommand { payload }; + + Self::ClientCommand(client_command) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn resource_pack_receive(hash: String, result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { hash, result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } +} + +pub enum ClientBoundGamePacket { + ClientBoundKeepAlive(ClientBoundKeepAlive), + JoinGame(JoinGame), + ClientBoundChat(ClientBoundChat), + UpdateTime(UpdateTime), + EntityEquipment(EntityEquipment), + SpawnPosition(SpawnPosition), + UpdateHealth(UpdateHealth), + Respawn(Respawn), + ClientBoundPosition(ClientBoundPosition), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + Bed(Bed), + Animation(Animation), + NamedEntitySpawn(NamedEntitySpawn), + Collect(Collect), + SpawnEntity(SpawnEntity), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + EntityVelocity(EntityVelocity), + EntityDestroy, + Entity(Entity), + RelEntityMove(RelEntityMove), + EntityLook(EntityLook), + EntityMoveLook(EntityMoveLook), + EntityTeleport(EntityTeleport), + EntityHeadRotation(EntityHeadRotation), + EntityStatus(EntityStatus), + AttachEntity(AttachEntity), + EntityMetadata(EntityMetadata), + EntityEffect(EntityEffect), + RemoveEntityEffect(RemoveEntityEffect), + Experience(Experience), + UpdateAttributes(UpdateAttributes), + MapChunk(MapChunk), + MultiBlockChange(MultiBlockChange), + BlockChange(BlockChange), + BlockAction(BlockAction), + BlockBreakAnimation(BlockBreakAnimation), + Explosion(Explosion), + WorldEvent(WorldEvent), + NamedSoundEffect(NamedSoundEffect), + WorldParticles(WorldParticles), + GameStateChange(GameStateChange), + SpawnEntityWeather(SpawnEntityWeather), + OpenWindow(OpenWindow), + ClientBoundCloseWindow(ClientBoundCloseWindow), + SetSlot(SetSlot), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundUpdateSign(ClientBoundUpdateSign), + Map(Map), + TileEntityData(TileEntityData), + OpenSignEntity(OpenSignEntity), + Statistics, + PlayerInfo(PlayerInfo), + ClientBoundAbilities(ClientBoundAbilities), + ClientBoundTabComplete, + ScoreboardObjective(ScoreboardObjective), + ScoreboardScore(ScoreboardScore), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + ScoreboardTeam(ScoreboardTeam), + ClientBoundCustomPayload(ClientBoundCustomPayload), + KickDisconnect(KickDisconnect), + Difficulty(Difficulty), + CombatEvent(CombatEvent), + Camera(Camera), + WorldBorder(WorldBorder), + Title(Title), + SetCompression(SetCompression), + PlayerlistHeader(PlayerlistHeader), + ResourcePackSend(ResourcePackSend), + BossBar(BossBar), + SetCooldown(SetCooldown), + UnloadChunk(UnloadChunk), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::JoinGame(_) => 0x24, + Self::ClientBoundChat(_) => 0x0F, + Self::UpdateTime(_) => 0x43, + Self::EntityEquipment(_) => 0x3C, + Self::SpawnPosition(_) => 0x42, + Self::UpdateHealth(_) => 0x3E, + Self::Respawn(_) => 0x33, + Self::ClientBoundPosition(_) => 0x2E, + Self::ClientBoundHeldItemSlot(_) => 0x37, + Self::Bed(_) => 0x2F, + Self::Animation(_) => 0x06, + Self::NamedEntitySpawn(_) => 0x05, + Self::Collect(_) => 0x47, + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::EntityVelocity(_) => 0x3B, + Self::EntityDestroy => 0x30, + Self::Entity(_) => 0x29, + Self::RelEntityMove(_) => 0x26, + Self::EntityLook(_) => 0x28, + Self::EntityMoveLook(_) => 0x27, + Self::EntityTeleport(_) => 0x48, + Self::EntityHeadRotation(_) => 0x34, + Self::EntityStatus(_) => 0x1A, + Self::AttachEntity(_) => 0x3A, + Self::EntityMetadata(_) => 0x39, + Self::EntityEffect(_) => 0x4A, + Self::RemoveEntityEffect(_) => 0x31, + Self::Experience(_) => 0x3D, + Self::UpdateAttributes(_) => 0x49, + Self::MapChunk(_) => 0x20, + Self::MultiBlockChange(_) => 0x10, + Self::BlockChange(_) => 0x0B, + Self::BlockAction(_) => 0x0A, + Self::BlockBreakAnimation(_) => 0x08, + Self::Explosion(_) => 0x1B, + Self::WorldEvent(_) => 0x21, + Self::NamedSoundEffect(_) => 0x23, + Self::WorldParticles(_) => 0x22, + Self::GameStateChange(_) => 0x1E, + Self::SpawnEntityWeather(_) => 0x02, + Self::OpenWindow(_) => 0x13, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::SetSlot(_) => 0x16, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundUpdateSign(_) => 0x45, + Self::Map(_) => 0x25, + Self::TileEntityData(_) => 0x09, + Self::OpenSignEntity(_) => 0x2A, + Self::Statistics => 0x07, + Self::PlayerInfo(_) => 0x2D, + Self::ClientBoundAbilities(_) => 0x2B, + Self::ClientBoundTabComplete => 0x0E, + Self::ScoreboardObjective(_) => 0x3F, + Self::ScoreboardScore(_) => 0x41, + Self::ScoreboardDisplayObjective(_) => 0x38, + Self::ScoreboardTeam(_) => 0x40, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::KickDisconnect(_) => 0x19, + Self::Difficulty(_) => 0x0D, + Self::CombatEvent(_) => 0x2C, + Self::Camera(_) => 0x36, + Self::WorldBorder(_) => 0x35, + Self::Title(_) => 0x44, + Self::SetCompression(_) => 0x1D, + Self::PlayerlistHeader(_) => 0x46, + Self::ResourcePackSend(_) => 0x32, + Self::BossBar(_) => 0x0C, + Self::SetCooldown(_) => 0x17, + Self::UnloadChunk(_) => 0x1C, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x24 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x43 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x3C => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x42 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x3E => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x33 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x2E => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x37 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x2F => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x47 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x3B => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x30 => Ok(Self::EntityDestroy), + 0x29 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x26 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x28 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x27 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x48 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x34 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x1A => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x3A => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x39 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x4A => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x31 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x3D => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x49 => { + let update_attributes = UpdateAttributes::decode(reader)?; + + Ok(Self::UpdateAttributes(update_attributes)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x1B => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x23 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x13 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x45 => { + let client_bound_update_sign = ClientBoundUpdateSign::decode(reader)?; + + Ok(Self::ClientBoundUpdateSign(client_bound_update_sign)) + } + 0x25 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x2A => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x07 => Ok(Self::Statistics), + 0x2D => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2B => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x0E => Ok(Self::ClientBoundTabComplete), + 0x3F => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x41 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x38 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x40 => { + let scoreboard_team = ScoreboardTeam::decode(reader)?; + + Ok(Self::ScoreboardTeam(scoreboard_team)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x2C => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x36 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x35 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x44 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x1D => { + let set_compression = SetCompression::decode(reader)?; + + Ok(Self::SetCompression(set_compression)) + } + 0x46 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x32 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x1C => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i8, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn client_bound_position(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, flags: i8) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: i32, + y: i32, + z: i32, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn collect(collected_entity_id: i32, collector_entity_id: i32) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + }; + + Self::Collect(collect) + } + + pub fn spawn_entity( + entity_id: i32, + entity_uuid: Uuid, + type_: i8, + x: i32, + y: i32, + z: i32, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + entity_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: u8, + x: i32, + y: i32, + z: i32, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: i32, y: i32, z: i32, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i8, d_y: i8, d_z: i8, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i8, + d_y: i8, + d_z: i8, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_teleport( + entity_id: i32, + x: i32, + y: i32, + z: i32, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32, leash: bool) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + leash, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: bool, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_attributes(entity_id: i32) -> Self { + let update_attributes = UpdateAttributes { entity_id }; + + Self::UpdateAttributes(update_attributes) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn named_sound_effect( + sound_name: String, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: u8, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: i32, y: i32, z: i32) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let client_bound_update_sign = ClientBoundUpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::ClientBoundUpdateSign(client_bound_update_sign) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn scoreboard_team(team: String, mode: i8) -> Self { + let scoreboard_team = ScoreboardTeam { team, mode }; + + Self::ScoreboardTeam(scoreboard_team) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn set_compression(threshold: i32) -> Self { + let set_compression = SetCompression { threshold }; + + Self::SetCompression(set_compression) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: i8, + pub cursor_y: i8, + pub cursor_z: i8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundUpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub block: Position, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub payload: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + pub hash: String, + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i8, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: i32, + pub y: i32, + pub z: i32, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub type_: i8, + pub x: i32, + pub y: i32, + pub z: i32, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub type_: u8, + pub x: i32, + pub y: i32, + pub z: i32, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i8, + pub d_y: i8, + pub d_z: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i8, + pub d_y: i8, + pub d_z: i8, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, + pub leash: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: u8, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: i32, + pub y: i32, + pub z: i32, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundUpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardTeam { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SetCompression { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} diff --git a/protocol/src/packet/handshake.rs b/protocol/src/version/v_15w40b/handshake.rs similarity index 94% rename from protocol/src/packet/handshake.rs rename to protocol/src/version/v_15w40b/handshake.rs index 90d4683..0ca7960 100644 --- a/protocol/src/packet/handshake.rs +++ b/protocol/src/version/v_15w40b/handshake.rs @@ -5,11 +5,11 @@ use crate::Decoder; use minecraft_protocol_derive::Packet; use std::io::Read; -pub enum HandshakeServerBoundPacket { +pub enum ServerBoundHandshakePacket { SetProtocol(SetProtocol), } -impl HandshakeServerBoundPacket { +impl ServerBoundHandshakePacket { pub fn get_type_id(&self) -> u8 { match self { Self::SetProtocol(_) => 0x00, diff --git a/protocol/src/version/v_15w40b/login.rs b/protocol/src/version/v_15w40b/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_15w40b/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_15w40b/mod.rs b/protocol/src/version/v_15w40b/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_15w40b/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/packet/status.rs b/protocol/src/version/v_15w40b/status.rs similarity index 89% rename from protocol/src/packet/status.rs rename to protocol/src/version/v_15w40b/status.rs index 6392a83..20fb7b7 100644 --- a/protocol/src/packet/status.rs +++ b/protocol/src/version/v_15w40b/status.rs @@ -1,17 +1,16 @@ // This file is automatically generated. // It is not intended for manual editing. -use crate::data::status::*; use crate::DecodeError; use crate::Decoder; use minecraft_protocol_derive::Packet; use std::io::Read; -pub enum StatusServerBoundPacket { +pub enum ServerBoundStatusPacket { StatusRequest, PingRequest(PingRequest), } -impl StatusServerBoundPacket { +impl ServerBoundStatusPacket { pub fn get_type_id(&self) -> u8 { match self { Self::StatusRequest => 0x00, @@ -42,12 +41,12 @@ impl StatusServerBoundPacket { } } -pub enum StatusClientBoundPacket { +pub enum ClientBoundStatusPacket { StatusResponse(StatusResponse), PingResponse(PingResponse), } -impl StatusClientBoundPacket { +impl ClientBoundStatusPacket { pub fn get_type_id(&self) -> u8 { match self { Self::StatusResponse(_) => 0x00, @@ -71,7 +70,7 @@ impl StatusClientBoundPacket { } } - pub fn status_response(response: ServerStatus) -> Self { + pub fn status_response(response: String) -> Self { let status_response = StatusResponse { response }; Self::StatusResponse(status_response) @@ -91,7 +90,7 @@ pub struct PingRequest { #[derive(Packet, Debug)] pub struct StatusResponse { - pub response: ServerStatus, + pub response: String, } #[derive(Packet, Debug)] diff --git a/protocol/src/version/v_16w20a/game.rs b/protocol/src/version/v_16w20a/game.rs new file mode 100644 index 0000000..a656231 --- /dev/null +++ b/protocol/src/version/v_16w20a/game.rs @@ -0,0 +1,2685 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::ServerBoundTabComplete(_) => 0x01, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x05, + Self::EnchantItem(_) => 0x06, + Self::WindowClick(_) => 0x07, + Self::ServerBoundCloseWindow(_) => 0x08, + Self::ServerBoundCustomPayload(_) => 0x09, + Self::UseEntity(_) => 0x0A, + Self::ServerBoundKeepAlive(_) => 0x0B, + Self::ServerBoundPosition(_) => 0x0C, + Self::PositionLook(_) => 0x0D, + Self::Look(_) => 0x0E, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x10, + Self::SteerBoat(_) => 0x11, + Self::ServerBoundAbilities(_) => 0x12, + Self::BlockDig(_) => 0x13, + Self::EntityAction(_) => 0x14, + Self::SteerVehicle(_) => 0x15, + Self::ResourcePackReceive(_) => 0x16, + Self::ServerBoundHeldItemSlot(_) => 0x17, + Self::SetCreativeSlot(_) => 0x18, + Self::UpdateSign(_) => 0x19, + Self::ArmAnimation(_) => 0x1A, + Self::Spectate(_) => 0x1B, + Self::BlockPlace(_) => 0x1C, + Self::UseItem(_) => 0x1D, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x05 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x06 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x07 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x08 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x09 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0A => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0B => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0C => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0D => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0E => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x10 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x11 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x12 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x13 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x14 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x15 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x16 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x17 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x18 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x19 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x1A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x1D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn resource_pack_receive(hash: String, result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { hash, result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: i8, + cursor_y: i8, + cursor_z: i8, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete => 0x0E, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::OpenWindow(_) => 0x13, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::MapChunk(_) => 0x20, + Self::WorldEvent(_) => 0x21, + Self::WorldParticles(_) => 0x22, + Self::JoinGame(_) => 0x23, + Self::Map(_) => 0x24, + Self::RelEntityMove(_) => 0x25, + Self::EntityMoveLook(_) => 0x26, + Self::EntityLook(_) => 0x27, + Self::Entity(_) => 0x28, + Self::ClientBoundVehicleMove(_) => 0x29, + Self::OpenSignEntity(_) => 0x2A, + Self::ClientBoundAbilities(_) => 0x2B, + Self::CombatEvent(_) => 0x2C, + Self::PlayerInfo(_) => 0x2D, + Self::ClientBoundPosition(_) => 0x2E, + Self::Bed(_) => 0x2F, + Self::EntityDestroy => 0x30, + Self::RemoveEntityEffect(_) => 0x31, + Self::ResourcePackSend(_) => 0x32, + Self::Respawn(_) => 0x33, + Self::EntityHeadRotation(_) => 0x34, + Self::WorldBorder(_) => 0x35, + Self::Camera(_) => 0x36, + Self::ClientBoundHeldItemSlot(_) => 0x37, + Self::ScoreboardDisplayObjective(_) => 0x38, + Self::EntityMetadata(_) => 0x39, + Self::AttachEntity(_) => 0x3A, + Self::EntityVelocity(_) => 0x3B, + Self::EntityEquipment(_) => 0x3C, + Self::Experience(_) => 0x3D, + Self::UpdateHealth(_) => 0x3E, + Self::ScoreboardObjective(_) => 0x3F, + Self::SetPassengers(_) => 0x40, + Self::Teams(_) => 0x41, + Self::ScoreboardScore(_) => 0x42, + Self::SpawnPosition(_) => 0x43, + Self::UpdateTime(_) => 0x44, + Self::Title(_) => 0x45, + Self::SoundEffect(_) => 0x46, + Self::PlayerlistHeader(_) => 0x47, + Self::Collect(_) => 0x48, + Self::EntityTeleport(_) => 0x49, + Self::EntityUpdateAttributes(_) => 0x4A, + Self::EntityEffect(_) => 0x4B, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0E => Ok(Self::ClientBoundTabComplete), + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x13 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x23 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x24 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x25 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x26 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x27 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x28 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x29 => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2A => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2B => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2C => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2D => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2E => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x2F => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x30 => Ok(Self::EntityDestroy), + 0x31 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x32 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x33 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x34 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x35 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x36 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x37 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x38 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x39 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3A => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3B => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3C => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x3D => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x3E => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x3F => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x40 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x41 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x42 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x43 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x44 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x45 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x46 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x47 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x48 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x49 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4A => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4B => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: u8, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect(collected_entity_id: i32, collector_entity_id: i32) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + pub hash: String, + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: i8, + pub cursor_y: i8, + pub cursor_z: i8, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub type_: u8, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} diff --git a/protocol/src/version/v_16w20a/handshake.rs b/protocol/src/version/v_16w20a/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_16w20a/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_16w20a/login.rs b/protocol/src/version/v_16w20a/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_16w20a/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_16w20a/mod.rs b/protocol/src/version/v_16w20a/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_16w20a/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_16w20a/status.rs b/protocol/src/version/v_16w20a/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_16w20a/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_16w35a/game.rs b/protocol/src/version/v_16w35a/game.rs new file mode 100644 index 0000000..51ad83d --- /dev/null +++ b/protocol/src/version/v_16w35a/game.rs @@ -0,0 +1,2692 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::ServerBoundTabComplete(_) => 0x01, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x05, + Self::EnchantItem(_) => 0x06, + Self::WindowClick(_) => 0x07, + Self::ServerBoundCloseWindow(_) => 0x08, + Self::ServerBoundCustomPayload(_) => 0x09, + Self::UseEntity(_) => 0x0A, + Self::ServerBoundKeepAlive(_) => 0x0B, + Self::ServerBoundPosition(_) => 0x0C, + Self::PositionLook(_) => 0x0D, + Self::Look(_) => 0x0E, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x10, + Self::SteerBoat(_) => 0x11, + Self::ServerBoundAbilities(_) => 0x12, + Self::BlockDig(_) => 0x13, + Self::EntityAction(_) => 0x14, + Self::SteerVehicle(_) => 0x15, + Self::ResourcePackReceive(_) => 0x16, + Self::ServerBoundHeldItemSlot(_) => 0x17, + Self::SetCreativeSlot(_) => 0x18, + Self::UpdateSign(_) => 0x19, + Self::ArmAnimation(_) => 0x1A, + Self::Spectate(_) => 0x1B, + Self::BlockPlace(_) => 0x1C, + Self::UseItem(_) => 0x1D, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x05 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x06 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x07 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x08 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x09 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0A => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0B => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0C => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0D => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0E => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x10 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x11 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x12 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x13 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x14 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x15 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x16 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x17 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x18 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x19 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x1A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x1D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: i8, + cursor_y: i8, + cursor_z: i8, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete => 0x0E, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::OpenWindow(_) => 0x13, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::MapChunk(_) => 0x20, + Self::WorldEvent(_) => 0x21, + Self::WorldParticles(_) => 0x22, + Self::JoinGame(_) => 0x23, + Self::Map(_) => 0x24, + Self::RelEntityMove(_) => 0x25, + Self::EntityMoveLook(_) => 0x26, + Self::EntityLook(_) => 0x27, + Self::Entity(_) => 0x28, + Self::ClientBoundVehicleMove(_) => 0x29, + Self::OpenSignEntity(_) => 0x2A, + Self::ClientBoundAbilities(_) => 0x2B, + Self::CombatEvent(_) => 0x2C, + Self::PlayerInfo(_) => 0x2D, + Self::ClientBoundPosition(_) => 0x2E, + Self::Bed(_) => 0x2F, + Self::EntityDestroy => 0x30, + Self::RemoveEntityEffect(_) => 0x31, + Self::ResourcePackSend(_) => 0x32, + Self::Respawn(_) => 0x33, + Self::EntityHeadRotation(_) => 0x34, + Self::WorldBorder(_) => 0x35, + Self::Camera(_) => 0x36, + Self::ClientBoundHeldItemSlot(_) => 0x37, + Self::ScoreboardDisplayObjective(_) => 0x38, + Self::EntityMetadata(_) => 0x39, + Self::AttachEntity(_) => 0x3A, + Self::EntityVelocity(_) => 0x3B, + Self::EntityEquipment(_) => 0x3C, + Self::Experience(_) => 0x3D, + Self::UpdateHealth(_) => 0x3E, + Self::ScoreboardObjective(_) => 0x3F, + Self::SetPassengers(_) => 0x40, + Self::Teams(_) => 0x41, + Self::ScoreboardScore(_) => 0x42, + Self::SpawnPosition(_) => 0x43, + Self::UpdateTime(_) => 0x44, + Self::Title(_) => 0x45, + Self::SoundEffect(_) => 0x46, + Self::PlayerlistHeader(_) => 0x47, + Self::Collect(_) => 0x48, + Self::EntityTeleport(_) => 0x49, + Self::EntityUpdateAttributes(_) => 0x4A, + Self::EntityEffect(_) => 0x4B, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0E => Ok(Self::ClientBoundTabComplete), + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x13 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x23 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x24 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x25 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x26 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x27 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x28 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x29 => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2A => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2B => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2C => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2D => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2E => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x2F => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x30 => Ok(Self::EntityDestroy), + 0x31 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x32 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x33 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x34 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x35 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x36 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x37 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x38 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x39 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3A => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3B => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3C => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x3D => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x3E => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x3F => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x40 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x41 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x42 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x43 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x44 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x45 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x46 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x47 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x48 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x49 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4A => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4B => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: i8, + pub cursor_y: i8, + pub cursor_z: i8, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} diff --git a/protocol/src/version/v_16w35a/handshake.rs b/protocol/src/version/v_16w35a/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_16w35a/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_16w35a/login.rs b/protocol/src/version/v_16w35a/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_16w35a/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_16w35a/mod.rs b/protocol/src/version/v_16w35a/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_16w35a/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_16w35a/status.rs b/protocol/src/version/v_16w35a/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_16w35a/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_17w15a/game.rs b/protocol/src/version/v_17w15a/game.rs new file mode 100644 index 0000000..f671a15 --- /dev/null +++ b/protocol/src/version/v_17w15a/game.rs @@ -0,0 +1,2781 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + PrepareCraftingGrid(PrepareCraftingGrid), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::PrepareCraftingGrid(_) => 0x01, + Self::ServerBoundTabComplete(_) => 0x02, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x06, + Self::EnchantItem(_) => 0x07, + Self::WindowClick(_) => 0x08, + Self::ServerBoundCloseWindow(_) => 0x09, + Self::ServerBoundCustomPayload(_) => 0x0A, + Self::UseEntity(_) => 0x0B, + Self::ServerBoundKeepAlive(_) => 0x0C, + Self::ServerBoundPosition(_) => 0x0D, + Self::PositionLook(_) => 0x0E, + Self::Look(_) => 0x0F, + Self::Flying(_) => 0x10, + Self::ServerBoundVehicleMove(_) => 0x11, + Self::SteerBoat(_) => 0x12, + Self::ServerBoundAbilities(_) => 0x13, + Self::BlockDig(_) => 0x14, + Self::EntityAction(_) => 0x15, + Self::SteerVehicle(_) => 0x16, + Self::CraftingBookData(_) => 0x17, + Self::ResourcePackReceive(_) => 0x18, + Self::ServerBoundHeldItemSlot(_) => 0x19, + Self::SetCreativeSlot(_) => 0x1A, + Self::UpdateSign(_) => 0x1B, + Self::ArmAnimation(_) => 0x1C, + Self::Spectate(_) => 0x1D, + Self::BlockPlace(_) => 0x1E, + Self::UseItem(_) => 0x1F, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let prepare_crafting_grid = PrepareCraftingGrid::decode(reader)?; + + Ok(Self::PrepareCraftingGrid(prepare_crafting_grid)) + } + 0x02 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x06 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x07 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x08 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x09 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0A => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0B => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0C => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0D => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0E => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0F => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x10 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x11 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x12 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x13 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x14 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x15 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x16 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x17 => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x18 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x19 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x1A => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x1B => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x1C => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1D => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1E => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x1F => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn prepare_crafting_grid(window_id: u8, action_number: u16) -> Self { + let prepare_crafting_grid = PrepareCraftingGrid { + window_id, + action_number, + }; + + Self::PrepareCraftingGrid(prepare_crafting_grid) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: u32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x08, + Self::BlockBreakAnimation(_) => 0x09, + Self::TileEntityData(_) => 0x0A, + Self::BlockAction(_) => 0x0B, + Self::BlockChange(_) => 0x0C, + Self::BossBar(_) => 0x0D, + Self::Difficulty(_) => 0x0E, + Self::ClientBoundTabComplete => 0x0F, + Self::ClientBoundChat(_) => 0x10, + Self::MultiBlockChange(_) => 0x11, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x14, + Self::WindowItems(_) => 0x15, + Self::CraftProgressBar(_) => 0x16, + Self::SetSlot(_) => 0x17, + Self::SetCooldown(_) => 0x18, + Self::ClientBoundCustomPayload(_) => 0x19, + Self::NamedSoundEffect(_) => 0x1A, + Self::KickDisconnect(_) => 0x1B, + Self::EntityStatus(_) => 0x1C, + Self::Explosion(_) => 0x1D, + Self::UnloadChunk(_) => 0x1E, + Self::GameStateChange(_) => 0x1F, + Self::ClientBoundKeepAlive(_) => 0x20, + Self::MapChunk(_) => 0x21, + Self::WorldEvent(_) => 0x22, + Self::WorldParticles(_) => 0x23, + Self::JoinGame(_) => 0x24, + Self::Map(_) => 0x25, + Self::RelEntityMove(_) => 0x26, + Self::EntityMoveLook(_) => 0x27, + Self::EntityLook(_) => 0x28, + Self::Entity(_) => 0x29, + Self::ClientBoundVehicleMove(_) => 0x2A, + Self::OpenSignEntity(_) => 0x2B, + Self::ClientBoundAbilities(_) => 0x2C, + Self::CombatEvent(_) => 0x2D, + Self::PlayerInfo(_) => 0x2E, + Self::ClientBoundPosition(_) => 0x2F, + Self::Bed(_) => 0x30, + Self::UnlockRecipes(_) => 0x31, + Self::EntityDestroy => 0x32, + Self::RemoveEntityEffect(_) => 0x33, + Self::ResourcePackSend(_) => 0x34, + Self::Respawn(_) => 0x35, + Self::EntityHeadRotation(_) => 0x36, + Self::WorldBorder(_) => 0x37, + Self::Camera(_) => 0x38, + Self::ClientBoundHeldItemSlot(_) => 0x39, + Self::ScoreboardDisplayObjective(_) => 0x3A, + Self::EntityMetadata(_) => 0x3B, + Self::AttachEntity(_) => 0x3C, + Self::EntityVelocity(_) => 0x3D, + Self::EntityEquipment(_) => 0x3E, + Self::Experience(_) => 0x3F, + Self::UpdateHealth(_) => 0x40, + Self::ScoreboardObjective(_) => 0x41, + Self::SetPassengers(_) => 0x42, + Self::Teams(_) => 0x43, + Self::ScoreboardScore(_) => 0x44, + Self::SpawnPosition(_) => 0x45, + Self::UpdateTime(_) => 0x46, + Self::Title(_) => 0x47, + Self::SoundEffect(_) => 0x48, + Self::PlayerlistHeader(_) => 0x49, + Self::Collect(_) => 0x4A, + Self::EntityTeleport(_) => 0x4B, + Self::EntityUpdateAttributes(_) => 0x4C, + Self::EntityEffect(_) => 0x4D, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x08 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x09 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x0A => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0B => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0C => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0D => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0E => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0F => Ok(Self::ClientBoundTabComplete), + 0x10 => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x11 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x14 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x15 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x16 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x17 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x18 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x19 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x1A => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1B => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1C => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1D => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1E => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1F => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x20 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x21 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x22 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x23 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x24 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x25 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x26 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x27 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x28 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x29 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2A => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2B => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2C => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2D => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2E => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2F => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x30 => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x31 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x32 => Ok(Self::EntityDestroy), + 0x33 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x34 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x35 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x36 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x37 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x38 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x39 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x3A => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x3B => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3C => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3D => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3E => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x3F => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x40 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x41 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x42 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x43 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x44 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x45 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x46 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x47 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x48 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x49 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x4A => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x4B => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4C => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4D => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn unlock_recipes( + notification: bool, + crafting_book_open: bool, + filtering_craftable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + notification, + crafting_book_open, + filtering_craftable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn sound_effect( + sound_category: i32, + sound_id: i32, + parrotted_entity_type: String, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_category, + sound_id, + parrotted_entity_type, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PrepareCraftingGrid { + pub window_id: u8, + pub action_number: u16, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + pub type_: u32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + pub notification: bool, + pub crafting_book_open: bool, + pub filtering_craftable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_category: i32, + #[packet(with = "var_int")] + pub sound_id: i32, + pub parrotted_entity_type: String, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} diff --git a/protocol/src/version/v_17w15a/handshake.rs b/protocol/src/version/v_17w15a/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_17w15a/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_17w15a/login.rs b/protocol/src/version/v_17w15a/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_17w15a/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_17w15a/mod.rs b/protocol/src/version/v_17w15a/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_17w15a/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_17w15a/status.rs b/protocol/src/version/v_17w15a/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_17w15a/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_17w18b/game.rs b/protocol/src/version/v_17w18b/game.rs new file mode 100644 index 0000000..6bca036 --- /dev/null +++ b/protocol/src/version/v_17w18b/game.rs @@ -0,0 +1,2778 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + PrepareCraftingGrid(PrepareCraftingGrid), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::PrepareCraftingGrid(_) => 0x01, + Self::ServerBoundTabComplete(_) => 0x02, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x06, + Self::EnchantItem(_) => 0x07, + Self::WindowClick(_) => 0x08, + Self::ServerBoundCloseWindow(_) => 0x09, + Self::ServerBoundCustomPayload(_) => 0x0A, + Self::UseEntity(_) => 0x0B, + Self::ServerBoundKeepAlive(_) => 0x0C, + Self::ServerBoundPosition(_) => 0x0D, + Self::PositionLook(_) => 0x0E, + Self::Look(_) => 0x0F, + Self::Flying(_) => 0x10, + Self::ServerBoundVehicleMove(_) => 0x11, + Self::SteerBoat(_) => 0x12, + Self::ServerBoundAbilities(_) => 0x13, + Self::BlockDig(_) => 0x14, + Self::EntityAction(_) => 0x15, + Self::SteerVehicle(_) => 0x16, + Self::CraftingBookData(_) => 0x17, + Self::ResourcePackReceive(_) => 0x18, + Self::ServerBoundHeldItemSlot(_) => 0x19, + Self::SetCreativeSlot(_) => 0x1A, + Self::UpdateSign(_) => 0x1B, + Self::ArmAnimation(_) => 0x1C, + Self::Spectate(_) => 0x1D, + Self::BlockPlace(_) => 0x1E, + Self::UseItem(_) => 0x1F, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let prepare_crafting_grid = PrepareCraftingGrid::decode(reader)?; + + Ok(Self::PrepareCraftingGrid(prepare_crafting_grid)) + } + 0x02 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x06 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x07 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x08 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x09 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0A => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0B => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0C => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0D => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0E => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0F => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x10 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x11 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x12 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x13 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x14 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x15 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x16 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x17 => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x18 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x19 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x1A => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x1B => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x1C => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1D => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1E => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x1F => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn prepare_crafting_grid(window_id: u8, action_number: u16) -> Self { + let prepare_crafting_grid = PrepareCraftingGrid { + window_id, + action_number, + }; + + Self::PrepareCraftingGrid(prepare_crafting_grid) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: u32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x08, + Self::BlockBreakAnimation(_) => 0x09, + Self::TileEntityData(_) => 0x0A, + Self::BlockAction(_) => 0x0B, + Self::BlockChange(_) => 0x0C, + Self::BossBar(_) => 0x0D, + Self::Difficulty(_) => 0x0E, + Self::ClientBoundTabComplete => 0x0F, + Self::ClientBoundChat(_) => 0x10, + Self::MultiBlockChange(_) => 0x11, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x14, + Self::WindowItems(_) => 0x15, + Self::CraftProgressBar(_) => 0x16, + Self::SetSlot(_) => 0x17, + Self::SetCooldown(_) => 0x18, + Self::ClientBoundCustomPayload(_) => 0x19, + Self::NamedSoundEffect(_) => 0x1A, + Self::KickDisconnect(_) => 0x1B, + Self::EntityStatus(_) => 0x1C, + Self::Explosion(_) => 0x1D, + Self::UnloadChunk(_) => 0x1E, + Self::GameStateChange(_) => 0x1F, + Self::ClientBoundKeepAlive(_) => 0x20, + Self::MapChunk(_) => 0x21, + Self::WorldEvent(_) => 0x22, + Self::WorldParticles(_) => 0x23, + Self::JoinGame(_) => 0x24, + Self::Map(_) => 0x25, + Self::RelEntityMove(_) => 0x26, + Self::EntityMoveLook(_) => 0x27, + Self::EntityLook(_) => 0x28, + Self::Entity(_) => 0x29, + Self::ClientBoundVehicleMove(_) => 0x2A, + Self::OpenSignEntity(_) => 0x2B, + Self::ClientBoundAbilities(_) => 0x2C, + Self::CombatEvent(_) => 0x2D, + Self::PlayerInfo(_) => 0x2E, + Self::ClientBoundPosition(_) => 0x2F, + Self::Bed(_) => 0x30, + Self::UnlockRecipes(_) => 0x31, + Self::EntityDestroy => 0x32, + Self::RemoveEntityEffect(_) => 0x33, + Self::ResourcePackSend(_) => 0x34, + Self::Respawn(_) => 0x35, + Self::EntityHeadRotation(_) => 0x36, + Self::WorldBorder(_) => 0x37, + Self::Camera(_) => 0x38, + Self::ClientBoundHeldItemSlot(_) => 0x39, + Self::ScoreboardDisplayObjective(_) => 0x3A, + Self::EntityMetadata(_) => 0x3B, + Self::AttachEntity(_) => 0x3C, + Self::EntityVelocity(_) => 0x3D, + Self::EntityEquipment(_) => 0x3E, + Self::Experience(_) => 0x3F, + Self::UpdateHealth(_) => 0x40, + Self::ScoreboardObjective(_) => 0x41, + Self::SetPassengers(_) => 0x42, + Self::Teams(_) => 0x43, + Self::ScoreboardScore(_) => 0x44, + Self::SpawnPosition(_) => 0x45, + Self::UpdateTime(_) => 0x46, + Self::Title(_) => 0x47, + Self::SoundEffect(_) => 0x48, + Self::PlayerlistHeader(_) => 0x49, + Self::Collect(_) => 0x4A, + Self::EntityTeleport(_) => 0x4B, + Self::EntityUpdateAttributes(_) => 0x4C, + Self::EntityEffect(_) => 0x4D, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x08 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x09 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x0A => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0B => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0C => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0D => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0E => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0F => Ok(Self::ClientBoundTabComplete), + 0x10 => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x11 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x14 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x15 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x16 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x17 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x18 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x19 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x1A => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1B => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1C => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1D => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1E => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1F => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x20 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x21 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x22 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x23 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x24 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x25 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x26 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x27 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x28 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x29 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2A => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2B => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2C => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2D => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2E => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2F => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x30 => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x31 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x32 => Ok(Self::EntityDestroy), + 0x33 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x34 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x35 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x36 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x37 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x38 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x39 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x3A => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x3B => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3C => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3D => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3E => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x3F => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x40 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x41 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x42 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x43 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x44 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x45 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x46 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x47 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x48 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x49 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x4A => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x4B => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4C => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4D => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn unlock_recipes( + action: i16, + crafting_book_open: bool, + filtering_craftable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PrepareCraftingGrid { + pub window_id: u8, + pub action_number: u16, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + pub type_: u32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + pub action: i16, + pub crafting_book_open: bool, + pub filtering_craftable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} diff --git a/protocol/src/version/v_17w18b/handshake.rs b/protocol/src/version/v_17w18b/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_17w18b/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_17w18b/login.rs b/protocol/src/version/v_17w18b/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_17w18b/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_17w18b/mod.rs b/protocol/src/version/v_17w18b/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_17w18b/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_17w18b/status.rs b/protocol/src/version/v_17w18b/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_17w18b/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_17w50a/game.rs b/protocol/src/version/v_17w50a/game.rs new file mode 100644 index 0000000..c35d566 --- /dev/null +++ b/protocol/src/version/v_17w50a/game.rs @@ -0,0 +1,2917 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::ServerBoundTabComplete(_) => 0x04, + Self::ServerBoundChat(_) => 0x01, + Self::ClientCommand(_) => 0x02, + Self::Settings(_) => 0x03, + Self::ServerBoundTransaction(_) => 0x05, + Self::EnchantItem(_) => 0x06, + Self::WindowClick(_) => 0x07, + Self::ServerBoundCloseWindow(_) => 0x08, + Self::ServerBoundCustomPayload(_) => 0x09, + Self::UseEntity(_) => 0x0A, + Self::ServerBoundKeepAlive(_) => 0x0B, + Self::ServerBoundPosition(_) => 0x0D, + Self::PositionLook(_) => 0x0E, + Self::Look(_) => 0x0F, + Self::Flying(_) => 0x0C, + Self::ServerBoundVehicleMove(_) => 0x10, + Self::SteerBoat(_) => 0x11, + Self::CraftRecipeRequest(_) => 0x12, + Self::ServerBoundAbilities(_) => 0x13, + Self::BlockDig(_) => 0x14, + Self::EntityAction(_) => 0x15, + Self::SteerVehicle(_) => 0x16, + Self::CraftingBookData(_) => 0x17, + Self::ResourcePackReceive(_) => 0x18, + Self::ServerBoundHeldItemSlot(_) => 0x1A, + Self::SetCreativeSlot(_) => 0x1B, + Self::UpdateSign(_) => 0x1C, + Self::ArmAnimation(_) => 0x1D, + Self::Spectate(_) => 0x1E, + Self::BlockPlace(_) => 0x1F, + Self::UseItem(_) => 0x20, + Self::AdvancementTab(_) => 0x19, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x04 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x01 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x02 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x03 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x05 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x06 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x07 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x08 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x09 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0A => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0B => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0D => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0E => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0F => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0C => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x10 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x11 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x12 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x13 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x14 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x15 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x16 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x17 => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x18 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x1A => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x1B => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x1C => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x1D => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1E => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1F => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x20 => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x19 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x4F, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete(_) => 0x10, + Self::DeclareCommands(_) => 0x11, + Self::ClientBoundChat(_) => 0x0E, + Self::MultiBlockChange(_) => 0x0F, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x14, + Self::WindowItems(_) => 0x15, + Self::CraftProgressBar(_) => 0x16, + Self::SetSlot(_) => 0x17, + Self::SetCooldown(_) => 0x18, + Self::ClientBoundCustomPayload(_) => 0x19, + Self::NamedSoundEffect(_) => 0x1A, + Self::KickDisconnect(_) => 0x1B, + Self::EntityStatus(_) => 0x1C, + Self::Explosion(_) => 0x1D, + Self::UnloadChunk(_) => 0x1E, + Self::GameStateChange(_) => 0x1F, + Self::ClientBoundKeepAlive(_) => 0x20, + Self::MapChunk(_) => 0x21, + Self::WorldEvent(_) => 0x22, + Self::WorldParticles(_) => 0x23, + Self::JoinGame(_) => 0x24, + Self::Map(_) => 0x25, + Self::RelEntityMove(_) => 0x27, + Self::EntityMoveLook(_) => 0x28, + Self::EntityLook(_) => 0x29, + Self::Entity(_) => 0x26, + Self::ClientBoundVehicleMove(_) => 0x2A, + Self::OpenSignEntity(_) => 0x2B, + Self::CraftRecipeResponse(_) => 0x2C, + Self::ClientBoundAbilities(_) => 0x2D, + Self::CombatEvent(_) => 0x2E, + Self::PlayerInfo(_) => 0x2F, + Self::ClientBoundPosition(_) => 0x30, + Self::Bed(_) => 0x31, + Self::UnlockRecipes(_) => 0x32, + Self::EntityDestroy => 0x33, + Self::RemoveEntityEffect(_) => 0x34, + Self::ResourcePackSend(_) => 0x35, + Self::Respawn(_) => 0x36, + Self::EntityHeadRotation(_) => 0x37, + Self::WorldBorder(_) => 0x39, + Self::Camera(_) => 0x3A, + Self::ClientBoundHeldItemSlot(_) => 0x3B, + Self::ScoreboardDisplayObjective(_) => 0x3C, + Self::EntityMetadata(_) => 0x3D, + Self::AttachEntity(_) => 0x3E, + Self::EntityVelocity(_) => 0x3F, + Self::EntityEquipment(_) => 0x40, + Self::Experience(_) => 0x41, + Self::UpdateHealth(_) => 0x42, + Self::ScoreboardObjective(_) => 0x43, + Self::SetPassengers(_) => 0x44, + Self::Teams(_) => 0x45, + Self::ScoreboardScore(_) => 0x46, + Self::SpawnPosition(_) => 0x47, + Self::UpdateTime(_) => 0x48, + Self::Title(_) => 0x49, + Self::StopSound(_) => 0x4A, + Self::SoundEffect(_) => 0x4B, + Self::PlayerlistHeader(_) => 0x4C, + Self::Collect(_) => 0x4D, + Self::EntityTeleport(_) => 0x4E, + Self::EntityUpdateAttributes(_) => 0x50, + Self::EntityEffect(_) => 0x51, + Self::SelectAdvancementTab(_) => 0x38, + Self::DeclareRecipes => 0x52, + Self::Tags(_) => 0x53, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x4F => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x10 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x11 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x0E => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x0F => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x14 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x15 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x16 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x17 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x18 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x19 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x1A => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1B => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1C => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1D => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1E => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1F => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x20 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x21 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x22 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x23 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x24 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x25 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x27 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x28 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x29 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x26 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2A => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2B => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2C => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x2D => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2E => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2F => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x30 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x31 => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x32 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x33 => Ok(Self::EntityDestroy), + 0x34 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x35 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x36 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x37 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x39 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3A => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3B => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x3C => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x3D => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3E => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3F => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x40 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x41 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x42 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x43 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x44 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x45 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x46 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x47 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x48 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x49 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x4A => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x4B => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x4C => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x4D => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x4E => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x50 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x51 => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x38 => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x52 => Ok(Self::DeclareRecipes), + 0x53 => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags(block_tags: TagsMap, item_tags: TagsMap) -> Self { + let tags = Tags { + block_tags, + item_tags, + }; + + Self::Tags(tags) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, +} diff --git a/protocol/src/version/v_17w50a/handshake.rs b/protocol/src/version/v_17w50a/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_17w50a/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_17w50a/login.rs b/protocol/src/version/v_17w50a/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_17w50a/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_17w50a/mod.rs b/protocol/src/version/v_17w50a/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_17w50a/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_17w50a/status.rs b/protocol/src/version/v_17w50a/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_17w50a/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_10/game.rs b/protocol/src/version/v_1_10/game.rs new file mode 100644 index 0000000..c9ee17b --- /dev/null +++ b/protocol/src/version/v_1_10/game.rs @@ -0,0 +1,2684 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::ServerBoundTabComplete(_) => 0x01, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x05, + Self::EnchantItem(_) => 0x06, + Self::WindowClick(_) => 0x07, + Self::ServerBoundCloseWindow(_) => 0x08, + Self::ServerBoundCustomPayload(_) => 0x09, + Self::UseEntity(_) => 0x0A, + Self::ServerBoundKeepAlive(_) => 0x0B, + Self::ServerBoundPosition(_) => 0x0C, + Self::PositionLook(_) => 0x0D, + Self::Look(_) => 0x0E, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x10, + Self::SteerBoat(_) => 0x11, + Self::ServerBoundAbilities(_) => 0x12, + Self::BlockDig(_) => 0x13, + Self::EntityAction(_) => 0x14, + Self::SteerVehicle(_) => 0x15, + Self::ResourcePackReceive(_) => 0x16, + Self::ServerBoundHeldItemSlot(_) => 0x17, + Self::SetCreativeSlot(_) => 0x18, + Self::UpdateSign(_) => 0x19, + Self::ArmAnimation(_) => 0x1A, + Self::Spectate(_) => 0x1B, + Self::BlockPlace(_) => 0x1C, + Self::UseItem(_) => 0x1D, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x05 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x06 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x07 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x08 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x09 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0A => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0B => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0C => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0D => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0E => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x10 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x11 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x12 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x13 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x14 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x15 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x16 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x17 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x18 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x19 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x1A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x1D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: i8, + cursor_y: i8, + cursor_z: i8, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete => 0x0E, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::OpenWindow(_) => 0x13, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::MapChunk(_) => 0x20, + Self::WorldEvent(_) => 0x21, + Self::WorldParticles(_) => 0x22, + Self::JoinGame(_) => 0x23, + Self::Map(_) => 0x24, + Self::RelEntityMove(_) => 0x25, + Self::EntityMoveLook(_) => 0x26, + Self::EntityLook(_) => 0x27, + Self::Entity(_) => 0x28, + Self::ClientBoundVehicleMove(_) => 0x29, + Self::OpenSignEntity(_) => 0x2A, + Self::ClientBoundAbilities(_) => 0x2B, + Self::CombatEvent(_) => 0x2C, + Self::PlayerInfo(_) => 0x2D, + Self::ClientBoundPosition(_) => 0x2E, + Self::Bed(_) => 0x2F, + Self::EntityDestroy => 0x30, + Self::RemoveEntityEffect(_) => 0x31, + Self::ResourcePackSend(_) => 0x32, + Self::Respawn(_) => 0x33, + Self::EntityHeadRotation(_) => 0x34, + Self::WorldBorder(_) => 0x35, + Self::Camera(_) => 0x36, + Self::ClientBoundHeldItemSlot(_) => 0x37, + Self::ScoreboardDisplayObjective(_) => 0x38, + Self::EntityMetadata(_) => 0x39, + Self::AttachEntity(_) => 0x3A, + Self::EntityVelocity(_) => 0x3B, + Self::EntityEquipment(_) => 0x3C, + Self::Experience(_) => 0x3D, + Self::UpdateHealth(_) => 0x3E, + Self::ScoreboardObjective(_) => 0x3F, + Self::SetPassengers(_) => 0x40, + Self::Teams(_) => 0x41, + Self::ScoreboardScore(_) => 0x42, + Self::SpawnPosition(_) => 0x43, + Self::UpdateTime(_) => 0x44, + Self::Title(_) => 0x45, + Self::SoundEffect(_) => 0x46, + Self::PlayerlistHeader(_) => 0x47, + Self::Collect(_) => 0x48, + Self::EntityTeleport(_) => 0x49, + Self::EntityUpdateAttributes(_) => 0x4A, + Self::EntityEffect(_) => 0x4B, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0E => Ok(Self::ClientBoundTabComplete), + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x13 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x23 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x24 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x25 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x26 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x27 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x28 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x29 => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2A => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2B => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2C => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2D => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2E => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x2F => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x30 => Ok(Self::EntityDestroy), + 0x31 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x32 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x33 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x34 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x35 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x36 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x37 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x38 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x39 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3A => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3B => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3C => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x3D => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x3E => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x3F => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x40 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x41 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x42 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x43 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x44 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x45 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x46 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x47 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x48 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x49 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4A => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4B => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: u8, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect(collected_entity_id: i32, collector_entity_id: i32) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: i8, + pub cursor_y: i8, + pub cursor_z: i8, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub type_: u8, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} diff --git a/protocol/src/version/v_1_10/handshake.rs b/protocol/src/version/v_1_10/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_10/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_10/login.rs b/protocol/src/version/v_1_10/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_1_10/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_1_10/mod.rs b/protocol/src/version/v_1_10/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_10/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_10/status.rs b/protocol/src/version/v_1_10/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_10/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_10_pre1/game.rs b/protocol/src/version/v_1_10_pre1/game.rs new file mode 100644 index 0000000..c9ee17b --- /dev/null +++ b/protocol/src/version/v_1_10_pre1/game.rs @@ -0,0 +1,2684 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::ServerBoundTabComplete(_) => 0x01, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x05, + Self::EnchantItem(_) => 0x06, + Self::WindowClick(_) => 0x07, + Self::ServerBoundCloseWindow(_) => 0x08, + Self::ServerBoundCustomPayload(_) => 0x09, + Self::UseEntity(_) => 0x0A, + Self::ServerBoundKeepAlive(_) => 0x0B, + Self::ServerBoundPosition(_) => 0x0C, + Self::PositionLook(_) => 0x0D, + Self::Look(_) => 0x0E, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x10, + Self::SteerBoat(_) => 0x11, + Self::ServerBoundAbilities(_) => 0x12, + Self::BlockDig(_) => 0x13, + Self::EntityAction(_) => 0x14, + Self::SteerVehicle(_) => 0x15, + Self::ResourcePackReceive(_) => 0x16, + Self::ServerBoundHeldItemSlot(_) => 0x17, + Self::SetCreativeSlot(_) => 0x18, + Self::UpdateSign(_) => 0x19, + Self::ArmAnimation(_) => 0x1A, + Self::Spectate(_) => 0x1B, + Self::BlockPlace(_) => 0x1C, + Self::UseItem(_) => 0x1D, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x05 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x06 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x07 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x08 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x09 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0A => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0B => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0C => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0D => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0E => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x10 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x11 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x12 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x13 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x14 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x15 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x16 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x17 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x18 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x19 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x1A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x1D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: i8, + cursor_y: i8, + cursor_z: i8, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete => 0x0E, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::OpenWindow(_) => 0x13, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::MapChunk(_) => 0x20, + Self::WorldEvent(_) => 0x21, + Self::WorldParticles(_) => 0x22, + Self::JoinGame(_) => 0x23, + Self::Map(_) => 0x24, + Self::RelEntityMove(_) => 0x25, + Self::EntityMoveLook(_) => 0x26, + Self::EntityLook(_) => 0x27, + Self::Entity(_) => 0x28, + Self::ClientBoundVehicleMove(_) => 0x29, + Self::OpenSignEntity(_) => 0x2A, + Self::ClientBoundAbilities(_) => 0x2B, + Self::CombatEvent(_) => 0x2C, + Self::PlayerInfo(_) => 0x2D, + Self::ClientBoundPosition(_) => 0x2E, + Self::Bed(_) => 0x2F, + Self::EntityDestroy => 0x30, + Self::RemoveEntityEffect(_) => 0x31, + Self::ResourcePackSend(_) => 0x32, + Self::Respawn(_) => 0x33, + Self::EntityHeadRotation(_) => 0x34, + Self::WorldBorder(_) => 0x35, + Self::Camera(_) => 0x36, + Self::ClientBoundHeldItemSlot(_) => 0x37, + Self::ScoreboardDisplayObjective(_) => 0x38, + Self::EntityMetadata(_) => 0x39, + Self::AttachEntity(_) => 0x3A, + Self::EntityVelocity(_) => 0x3B, + Self::EntityEquipment(_) => 0x3C, + Self::Experience(_) => 0x3D, + Self::UpdateHealth(_) => 0x3E, + Self::ScoreboardObjective(_) => 0x3F, + Self::SetPassengers(_) => 0x40, + Self::Teams(_) => 0x41, + Self::ScoreboardScore(_) => 0x42, + Self::SpawnPosition(_) => 0x43, + Self::UpdateTime(_) => 0x44, + Self::Title(_) => 0x45, + Self::SoundEffect(_) => 0x46, + Self::PlayerlistHeader(_) => 0x47, + Self::Collect(_) => 0x48, + Self::EntityTeleport(_) => 0x49, + Self::EntityUpdateAttributes(_) => 0x4A, + Self::EntityEffect(_) => 0x4B, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0E => Ok(Self::ClientBoundTabComplete), + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x13 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x23 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x24 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x25 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x26 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x27 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x28 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x29 => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2A => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2B => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2C => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2D => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2E => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x2F => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x30 => Ok(Self::EntityDestroy), + 0x31 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x32 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x33 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x34 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x35 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x36 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x37 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x38 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x39 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3A => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3B => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3C => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x3D => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x3E => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x3F => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x40 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x41 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x42 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x43 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x44 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x45 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x46 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x47 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x48 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x49 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4A => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4B => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: u8, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect(collected_entity_id: i32, collector_entity_id: i32) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: i8, + pub cursor_y: i8, + pub cursor_z: i8, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub type_: u8, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} diff --git a/protocol/src/version/v_1_10_pre1/handshake.rs b/protocol/src/version/v_1_10_pre1/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_10_pre1/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_10_pre1/login.rs b/protocol/src/version/v_1_10_pre1/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_1_10_pre1/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_1_10_pre1/mod.rs b/protocol/src/version/v_1_10_pre1/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_10_pre1/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_10_pre1/status.rs b/protocol/src/version/v_1_10_pre1/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_10_pre1/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_11/game.rs b/protocol/src/version/v_1_11/game.rs new file mode 100644 index 0000000..3dd337b --- /dev/null +++ b/protocol/src/version/v_1_11/game.rs @@ -0,0 +1,2692 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::ServerBoundTabComplete(_) => 0x01, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x05, + Self::EnchantItem(_) => 0x06, + Self::WindowClick(_) => 0x07, + Self::ServerBoundCloseWindow(_) => 0x08, + Self::ServerBoundCustomPayload(_) => 0x09, + Self::UseEntity(_) => 0x0A, + Self::ServerBoundKeepAlive(_) => 0x0B, + Self::ServerBoundPosition(_) => 0x0C, + Self::PositionLook(_) => 0x0D, + Self::Look(_) => 0x0E, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x10, + Self::SteerBoat(_) => 0x11, + Self::ServerBoundAbilities(_) => 0x12, + Self::BlockDig(_) => 0x13, + Self::EntityAction(_) => 0x14, + Self::SteerVehicle(_) => 0x15, + Self::ResourcePackReceive(_) => 0x16, + Self::ServerBoundHeldItemSlot(_) => 0x17, + Self::SetCreativeSlot(_) => 0x18, + Self::UpdateSign(_) => 0x19, + Self::ArmAnimation(_) => 0x1A, + Self::Spectate(_) => 0x1B, + Self::BlockPlace(_) => 0x1C, + Self::UseItem(_) => 0x1D, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x05 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x06 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x07 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x08 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x09 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0A => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0B => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0C => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0D => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0E => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x10 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x11 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x12 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x13 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x14 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x15 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x16 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x17 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x18 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x19 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x1A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x1D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete => 0x0E, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::OpenWindow(_) => 0x13, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::MapChunk(_) => 0x20, + Self::WorldEvent(_) => 0x21, + Self::WorldParticles(_) => 0x22, + Self::JoinGame(_) => 0x23, + Self::Map(_) => 0x24, + Self::RelEntityMove(_) => 0x25, + Self::EntityMoveLook(_) => 0x26, + Self::EntityLook(_) => 0x27, + Self::Entity(_) => 0x28, + Self::ClientBoundVehicleMove(_) => 0x29, + Self::OpenSignEntity(_) => 0x2A, + Self::ClientBoundAbilities(_) => 0x2B, + Self::CombatEvent(_) => 0x2C, + Self::PlayerInfo(_) => 0x2D, + Self::ClientBoundPosition(_) => 0x2E, + Self::Bed(_) => 0x2F, + Self::EntityDestroy => 0x30, + Self::RemoveEntityEffect(_) => 0x31, + Self::ResourcePackSend(_) => 0x32, + Self::Respawn(_) => 0x33, + Self::EntityHeadRotation(_) => 0x34, + Self::WorldBorder(_) => 0x35, + Self::Camera(_) => 0x36, + Self::ClientBoundHeldItemSlot(_) => 0x37, + Self::ScoreboardDisplayObjective(_) => 0x38, + Self::EntityMetadata(_) => 0x39, + Self::AttachEntity(_) => 0x3A, + Self::EntityVelocity(_) => 0x3B, + Self::EntityEquipment(_) => 0x3C, + Self::Experience(_) => 0x3D, + Self::UpdateHealth(_) => 0x3E, + Self::ScoreboardObjective(_) => 0x3F, + Self::SetPassengers(_) => 0x40, + Self::Teams(_) => 0x41, + Self::ScoreboardScore(_) => 0x42, + Self::SpawnPosition(_) => 0x43, + Self::UpdateTime(_) => 0x44, + Self::Title(_) => 0x45, + Self::SoundEffect(_) => 0x46, + Self::PlayerlistHeader(_) => 0x47, + Self::Collect(_) => 0x48, + Self::EntityTeleport(_) => 0x49, + Self::EntityUpdateAttributes(_) => 0x4A, + Self::EntityEffect(_) => 0x4B, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0E => Ok(Self::ClientBoundTabComplete), + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x13 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x23 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x24 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x25 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x26 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x27 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x28 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x29 => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2A => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2B => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2C => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2D => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2E => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x2F => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x30 => Ok(Self::EntityDestroy), + 0x31 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x32 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x33 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x34 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x35 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x36 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x37 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x38 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x39 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3A => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3B => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3C => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x3D => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x3E => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x3F => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x40 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x41 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x42 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x43 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x44 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x45 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x46 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x47 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x48 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x49 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4A => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4B => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} diff --git a/protocol/src/version/v_1_11/handshake.rs b/protocol/src/version/v_1_11/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_11/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_11/login.rs b/protocol/src/version/v_1_11/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_1_11/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_1_11/mod.rs b/protocol/src/version/v_1_11/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_11/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_11/status.rs b/protocol/src/version/v_1_11/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_11/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_12/game.rs b/protocol/src/version/v_1_12/game.rs new file mode 100644 index 0000000..7b5e8a0 --- /dev/null +++ b/protocol/src/version/v_1_12/game.rs @@ -0,0 +1,2817 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + PrepareCraftingGrid(PrepareCraftingGrid), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::PrepareCraftingGrid(_) => 0x01, + Self::ServerBoundTabComplete(_) => 0x02, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x06, + Self::EnchantItem(_) => 0x07, + Self::WindowClick(_) => 0x08, + Self::ServerBoundCloseWindow(_) => 0x09, + Self::ServerBoundCustomPayload(_) => 0x0A, + Self::UseEntity(_) => 0x0B, + Self::ServerBoundKeepAlive(_) => 0x0C, + Self::ServerBoundPosition(_) => 0x0E, + Self::PositionLook(_) => 0x0F, + Self::Look(_) => 0x10, + Self::Flying(_) => 0x0D, + Self::ServerBoundVehicleMove(_) => 0x11, + Self::SteerBoat(_) => 0x12, + Self::ServerBoundAbilities(_) => 0x13, + Self::BlockDig(_) => 0x14, + Self::EntityAction(_) => 0x15, + Self::SteerVehicle(_) => 0x16, + Self::CraftingBookData(_) => 0x17, + Self::ResourcePackReceive(_) => 0x18, + Self::ServerBoundHeldItemSlot(_) => 0x1A, + Self::SetCreativeSlot(_) => 0x1B, + Self::UpdateSign(_) => 0x1C, + Self::ArmAnimation(_) => 0x1D, + Self::Spectate(_) => 0x1E, + Self::BlockPlace(_) => 0x1F, + Self::UseItem(_) => 0x20, + Self::AdvancementTab(_) => 0x19, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let prepare_crafting_grid = PrepareCraftingGrid::decode(reader)?; + + Ok(Self::PrepareCraftingGrid(prepare_crafting_grid)) + } + 0x02 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x06 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x07 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x08 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x09 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0A => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0B => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0C => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0E => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0F => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x10 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0D => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x11 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x12 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x13 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x14 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x15 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x16 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x17 => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x18 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x1A => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x1B => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x1C => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x1D => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1E => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1F => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x20 => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x19 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn prepare_crafting_grid(window_id: u8, action_number: u16) -> Self { + let prepare_crafting_grid = PrepareCraftingGrid { + window_id, + action_number, + }; + + Self::PrepareCraftingGrid(prepare_crafting_grid) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x4C, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete => 0x0E, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::OpenWindow(_) => 0x13, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::MapChunk(_) => 0x20, + Self::WorldEvent(_) => 0x21, + Self::WorldParticles(_) => 0x22, + Self::JoinGame(_) => 0x23, + Self::Map(_) => 0x24, + Self::RelEntityMove(_) => 0x26, + Self::EntityMoveLook(_) => 0x27, + Self::EntityLook(_) => 0x28, + Self::Entity(_) => 0x25, + Self::ClientBoundVehicleMove(_) => 0x29, + Self::OpenSignEntity(_) => 0x2A, + Self::ClientBoundAbilities(_) => 0x2B, + Self::CombatEvent(_) => 0x2C, + Self::PlayerInfo(_) => 0x2D, + Self::ClientBoundPosition(_) => 0x2E, + Self::Bed(_) => 0x2F, + Self::UnlockRecipes(_) => 0x30, + Self::EntityDestroy => 0x31, + Self::RemoveEntityEffect(_) => 0x32, + Self::ResourcePackSend(_) => 0x33, + Self::Respawn(_) => 0x34, + Self::EntityHeadRotation(_) => 0x35, + Self::WorldBorder(_) => 0x37, + Self::Camera(_) => 0x38, + Self::ClientBoundHeldItemSlot(_) => 0x39, + Self::ScoreboardDisplayObjective(_) => 0x3A, + Self::EntityMetadata(_) => 0x3B, + Self::AttachEntity(_) => 0x3C, + Self::EntityVelocity(_) => 0x3D, + Self::EntityEquipment(_) => 0x3E, + Self::Experience(_) => 0x3F, + Self::UpdateHealth(_) => 0x40, + Self::ScoreboardObjective(_) => 0x41, + Self::SetPassengers(_) => 0x42, + Self::Teams(_) => 0x43, + Self::ScoreboardScore(_) => 0x44, + Self::SpawnPosition(_) => 0x45, + Self::UpdateTime(_) => 0x46, + Self::Title(_) => 0x47, + Self::SoundEffect(_) => 0x48, + Self::PlayerlistHeader(_) => 0x49, + Self::Collect(_) => 0x4A, + Self::EntityTeleport(_) => 0x4B, + Self::EntityUpdateAttributes(_) => 0x4D, + Self::EntityEffect(_) => 0x4E, + Self::SelectAdvancementTab(_) => 0x36, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x4C => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0E => Ok(Self::ClientBoundTabComplete), + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x13 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x23 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x24 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x26 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x27 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x28 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x25 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x29 => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2A => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2B => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2C => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2D => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2E => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x2F => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x30 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x31 => Ok(Self::EntityDestroy), + 0x32 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x33 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x34 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x35 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x37 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x38 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x39 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x3A => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x3B => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3C => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3D => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3E => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x3F => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x40 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x41 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x42 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x43 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x44 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x45 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x46 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x47 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x48 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x49 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x4A => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x4B => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4D => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4E => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x36 => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PrepareCraftingGrid { + pub window_id: u8, + pub action_number: u16, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} diff --git a/protocol/src/version/v_1_12/handshake.rs b/protocol/src/version/v_1_12/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_12/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_12/login.rs b/protocol/src/version/v_1_12/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_1_12/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_1_12/mod.rs b/protocol/src/version/v_1_12/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_12/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_12/status.rs b/protocol/src/version/v_1_12/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_12/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_12_1/game.rs b/protocol/src/version/v_1_12_1/game.rs new file mode 100644 index 0000000..1612b90 --- /dev/null +++ b/protocol/src/version/v_1_12_1/game.rs @@ -0,0 +1,2840 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::ServerBoundTabComplete(_) => 0x01, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x05, + Self::EnchantItem(_) => 0x06, + Self::WindowClick(_) => 0x07, + Self::ServerBoundCloseWindow(_) => 0x08, + Self::ServerBoundCustomPayload(_) => 0x09, + Self::UseEntity(_) => 0x0A, + Self::ServerBoundKeepAlive(_) => 0x0B, + Self::ServerBoundPosition(_) => 0x0D, + Self::PositionLook(_) => 0x0E, + Self::Look(_) => 0x0F, + Self::Flying(_) => 0x0C, + Self::ServerBoundVehicleMove(_) => 0x10, + Self::SteerBoat(_) => 0x11, + Self::CraftRecipeRequest(_) => 0x12, + Self::ServerBoundAbilities(_) => 0x13, + Self::BlockDig(_) => 0x14, + Self::EntityAction(_) => 0x15, + Self::SteerVehicle(_) => 0x16, + Self::CraftingBookData(_) => 0x17, + Self::ResourcePackReceive(_) => 0x18, + Self::ServerBoundHeldItemSlot(_) => 0x1A, + Self::SetCreativeSlot(_) => 0x1B, + Self::UpdateSign(_) => 0x1C, + Self::ArmAnimation(_) => 0x1D, + Self::Spectate(_) => 0x1E, + Self::BlockPlace(_) => 0x1F, + Self::UseItem(_) => 0x20, + Self::AdvancementTab(_) => 0x19, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x05 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x06 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x07 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x08 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x09 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0A => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0B => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0D => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0E => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0F => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0C => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x10 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x11 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x12 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x13 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x14 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x15 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x16 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x17 => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x18 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x1A => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x1B => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x1C => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x1D => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1E => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1F => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x20 => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x19 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: i32, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x4D, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete => 0x0E, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::OpenWindow(_) => 0x13, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::MapChunk(_) => 0x20, + Self::WorldEvent(_) => 0x21, + Self::WorldParticles(_) => 0x22, + Self::JoinGame(_) => 0x23, + Self::Map(_) => 0x24, + Self::RelEntityMove(_) => 0x26, + Self::EntityMoveLook(_) => 0x27, + Self::EntityLook(_) => 0x28, + Self::Entity(_) => 0x25, + Self::ClientBoundVehicleMove(_) => 0x29, + Self::OpenSignEntity(_) => 0x2A, + Self::CraftRecipeResponse(_) => 0x2B, + Self::ClientBoundAbilities(_) => 0x2C, + Self::CombatEvent(_) => 0x2D, + Self::PlayerInfo(_) => 0x2E, + Self::ClientBoundPosition(_) => 0x2F, + Self::Bed(_) => 0x30, + Self::UnlockRecipes(_) => 0x31, + Self::EntityDestroy => 0x32, + Self::RemoveEntityEffect(_) => 0x33, + Self::ResourcePackSend(_) => 0x34, + Self::Respawn(_) => 0x35, + Self::EntityHeadRotation(_) => 0x36, + Self::WorldBorder(_) => 0x38, + Self::Camera(_) => 0x39, + Self::ClientBoundHeldItemSlot(_) => 0x3A, + Self::ScoreboardDisplayObjective(_) => 0x3B, + Self::EntityMetadata(_) => 0x3C, + Self::AttachEntity(_) => 0x3D, + Self::EntityVelocity(_) => 0x3E, + Self::EntityEquipment(_) => 0x3F, + Self::Experience(_) => 0x40, + Self::UpdateHealth(_) => 0x41, + Self::ScoreboardObjective(_) => 0x42, + Self::SetPassengers(_) => 0x43, + Self::Teams(_) => 0x44, + Self::ScoreboardScore(_) => 0x45, + Self::SpawnPosition(_) => 0x46, + Self::UpdateTime(_) => 0x47, + Self::Title(_) => 0x48, + Self::SoundEffect(_) => 0x49, + Self::PlayerlistHeader(_) => 0x4A, + Self::Collect(_) => 0x4B, + Self::EntityTeleport(_) => 0x4C, + Self::EntityUpdateAttributes(_) => 0x4E, + Self::EntityEffect(_) => 0x4F, + Self::SelectAdvancementTab(_) => 0x37, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x4D => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0E => Ok(Self::ClientBoundTabComplete), + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x13 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x23 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x24 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x26 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x27 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x28 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x25 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x29 => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2A => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2B => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x2C => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2D => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2E => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2F => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x30 => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x31 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x32 => Ok(Self::EntityDestroy), + 0x33 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x34 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x35 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x36 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x38 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x39 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3A => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x3B => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x3C => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3D => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3E => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3F => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x40 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x41 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x42 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x43 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x44 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x45 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x46 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x47 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x48 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x49 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x4A => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x4B => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x4C => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4E => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4F => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x37 => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: i32) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + #[packet(with = "var_int")] + pub recipe: i32, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + #[packet(with = "var_int")] + pub recipe: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} diff --git a/protocol/src/version/v_1_12_1/handshake.rs b/protocol/src/version/v_1_12_1/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_12_1/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_12_1/login.rs b/protocol/src/version/v_1_12_1/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_1_12_1/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_1_12_1/mod.rs b/protocol/src/version/v_1_12_1/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_12_1/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_12_1/status.rs b/protocol/src/version/v_1_12_1/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_12_1/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_12_2/game.rs b/protocol/src/version/v_1_12_2/game.rs new file mode 100644 index 0000000..a94df04 --- /dev/null +++ b/protocol/src/version/v_1_12_2/game.rs @@ -0,0 +1,2838 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::ServerBoundTabComplete(_) => 0x01, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x05, + Self::EnchantItem(_) => 0x06, + Self::WindowClick(_) => 0x07, + Self::ServerBoundCloseWindow(_) => 0x08, + Self::ServerBoundCustomPayload(_) => 0x09, + Self::UseEntity(_) => 0x0A, + Self::ServerBoundKeepAlive(_) => 0x0B, + Self::ServerBoundPosition(_) => 0x0D, + Self::PositionLook(_) => 0x0E, + Self::Look(_) => 0x0F, + Self::Flying(_) => 0x0C, + Self::ServerBoundVehicleMove(_) => 0x10, + Self::SteerBoat(_) => 0x11, + Self::CraftRecipeRequest(_) => 0x12, + Self::ServerBoundAbilities(_) => 0x13, + Self::BlockDig(_) => 0x14, + Self::EntityAction(_) => 0x15, + Self::SteerVehicle(_) => 0x16, + Self::CraftingBookData(_) => 0x17, + Self::ResourcePackReceive(_) => 0x18, + Self::ServerBoundHeldItemSlot(_) => 0x1A, + Self::SetCreativeSlot(_) => 0x1B, + Self::UpdateSign(_) => 0x1C, + Self::ArmAnimation(_) => 0x1D, + Self::Spectate(_) => 0x1E, + Self::BlockPlace(_) => 0x1F, + Self::UseItem(_) => 0x20, + Self::AdvancementTab(_) => 0x19, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x05 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x06 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x07 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x08 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x09 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0A => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0B => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0D => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0E => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0F => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0C => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x10 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x11 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x12 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x13 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x14 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x15 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x16 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x17 => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x18 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x1A => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x1B => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x1C => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x1D => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1E => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1F => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x20 => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x19 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: i32, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x4D, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete => 0x0E, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::OpenWindow(_) => 0x13, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::MapChunk(_) => 0x20, + Self::WorldEvent(_) => 0x21, + Self::WorldParticles(_) => 0x22, + Self::JoinGame(_) => 0x23, + Self::Map(_) => 0x24, + Self::RelEntityMove(_) => 0x26, + Self::EntityMoveLook(_) => 0x27, + Self::EntityLook(_) => 0x28, + Self::Entity(_) => 0x25, + Self::ClientBoundVehicleMove(_) => 0x29, + Self::OpenSignEntity(_) => 0x2A, + Self::CraftRecipeResponse(_) => 0x2B, + Self::ClientBoundAbilities(_) => 0x2C, + Self::CombatEvent(_) => 0x2D, + Self::PlayerInfo(_) => 0x2E, + Self::ClientBoundPosition(_) => 0x2F, + Self::Bed(_) => 0x30, + Self::UnlockRecipes(_) => 0x31, + Self::EntityDestroy => 0x32, + Self::RemoveEntityEffect(_) => 0x33, + Self::ResourcePackSend(_) => 0x34, + Self::Respawn(_) => 0x35, + Self::EntityHeadRotation(_) => 0x36, + Self::WorldBorder(_) => 0x38, + Self::Camera(_) => 0x39, + Self::ClientBoundHeldItemSlot(_) => 0x3A, + Self::ScoreboardDisplayObjective(_) => 0x3B, + Self::EntityMetadata(_) => 0x3C, + Self::AttachEntity(_) => 0x3D, + Self::EntityVelocity(_) => 0x3E, + Self::EntityEquipment(_) => 0x3F, + Self::Experience(_) => 0x40, + Self::UpdateHealth(_) => 0x41, + Self::ScoreboardObjective(_) => 0x42, + Self::SetPassengers(_) => 0x43, + Self::Teams(_) => 0x44, + Self::ScoreboardScore(_) => 0x45, + Self::SpawnPosition(_) => 0x46, + Self::UpdateTime(_) => 0x47, + Self::Title(_) => 0x48, + Self::SoundEffect(_) => 0x49, + Self::PlayerlistHeader(_) => 0x4A, + Self::Collect(_) => 0x4B, + Self::EntityTeleport(_) => 0x4C, + Self::EntityUpdateAttributes(_) => 0x4E, + Self::EntityEffect(_) => 0x4F, + Self::SelectAdvancementTab(_) => 0x37, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x4D => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0E => Ok(Self::ClientBoundTabComplete), + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x13 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x23 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x24 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x26 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x27 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x28 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x25 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x29 => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2A => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2B => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x2C => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2D => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2E => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2F => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x30 => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x31 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x32 => Ok(Self::EntityDestroy), + 0x33 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x34 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x35 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x36 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x38 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x39 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3A => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x3B => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x3C => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3D => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3E => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3F => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x40 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x41 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x42 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x43 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x44 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x45 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x46 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x47 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x48 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x49 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x4A => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x4B => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x4C => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4E => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4F => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x37 => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: i32) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + #[packet(with = "var_int")] + pub recipe: i32, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + #[packet(with = "var_int")] + pub recipe: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} diff --git a/protocol/src/version/v_1_12_2/handshake.rs b/protocol/src/version/v_1_12_2/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_12_2/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_12_2/login.rs b/protocol/src/version/v_1_12_2/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_1_12_2/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_1_12_2/mod.rs b/protocol/src/version/v_1_12_2/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_12_2/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_12_2/status.rs b/protocol/src/version/v_1_12_2/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_12_2/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_12_pre4/game.rs b/protocol/src/version/v_1_12_pre4/game.rs new file mode 100644 index 0000000..8ead441 --- /dev/null +++ b/protocol/src/version/v_1_12_pre4/game.rs @@ -0,0 +1,2815 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + PrepareCraftingGrid(PrepareCraftingGrid), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::PrepareCraftingGrid(_) => 0x01, + Self::ServerBoundTabComplete(_) => 0x02, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x06, + Self::EnchantItem(_) => 0x07, + Self::WindowClick(_) => 0x08, + Self::ServerBoundCloseWindow(_) => 0x09, + Self::ServerBoundCustomPayload(_) => 0x0A, + Self::UseEntity(_) => 0x0B, + Self::ServerBoundKeepAlive(_) => 0x0C, + Self::ServerBoundPosition(_) => 0x0D, + Self::PositionLook(_) => 0x0E, + Self::Look(_) => 0x0F, + Self::Flying(_) => 0x10, + Self::ServerBoundVehicleMove(_) => 0x11, + Self::SteerBoat(_) => 0x12, + Self::ServerBoundAbilities(_) => 0x13, + Self::BlockDig(_) => 0x14, + Self::EntityAction(_) => 0x15, + Self::SteerVehicle(_) => 0x16, + Self::CraftingBookData(_) => 0x17, + Self::ResourcePackReceive(_) => 0x18, + Self::ServerBoundHeldItemSlot(_) => 0x19, + Self::SetCreativeSlot(_) => 0x1A, + Self::UpdateSign(_) => 0x1B, + Self::ArmAnimation(_) => 0x1C, + Self::Spectate(_) => 0x1D, + Self::BlockPlace(_) => 0x1E, + Self::UseItem(_) => 0x1F, + Self::AdvancementTab(_) => 0x20, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let prepare_crafting_grid = PrepareCraftingGrid::decode(reader)?; + + Ok(Self::PrepareCraftingGrid(prepare_crafting_grid)) + } + 0x02 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x06 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x07 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x08 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x09 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0A => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0B => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0C => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0D => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0E => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0F => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x10 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x11 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x12 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x13 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x14 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x15 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x16 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x17 => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x18 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x19 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x1A => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x1B => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x1C => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1D => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1E => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x1F => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x20 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn prepare_crafting_grid(window_id: u8, action_number: u16) -> Self { + let prepare_crafting_grid = PrepareCraftingGrid { + window_id, + action_number, + }; + + Self::PrepareCraftingGrid(prepare_crafting_grid) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: u32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + AdvancementProgress(AdvancementProgress), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x08, + Self::BlockBreakAnimation(_) => 0x09, + Self::TileEntityData(_) => 0x0A, + Self::BlockAction(_) => 0x0B, + Self::BlockChange(_) => 0x0C, + Self::BossBar(_) => 0x0D, + Self::Difficulty(_) => 0x0E, + Self::ClientBoundTabComplete => 0x0F, + Self::ClientBoundChat(_) => 0x10, + Self::MultiBlockChange(_) => 0x11, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x14, + Self::WindowItems(_) => 0x15, + Self::CraftProgressBar(_) => 0x16, + Self::SetSlot(_) => 0x17, + Self::SetCooldown(_) => 0x18, + Self::ClientBoundCustomPayload(_) => 0x19, + Self::NamedSoundEffect(_) => 0x1A, + Self::KickDisconnect(_) => 0x1B, + Self::EntityStatus(_) => 0x1C, + Self::Explosion(_) => 0x1D, + Self::UnloadChunk(_) => 0x1E, + Self::GameStateChange(_) => 0x1F, + Self::ClientBoundKeepAlive(_) => 0x20, + Self::MapChunk(_) => 0x21, + Self::WorldEvent(_) => 0x22, + Self::WorldParticles(_) => 0x23, + Self::JoinGame(_) => 0x24, + Self::Map(_) => 0x25, + Self::RelEntityMove(_) => 0x26, + Self::EntityMoveLook(_) => 0x27, + Self::EntityLook(_) => 0x28, + Self::Entity(_) => 0x29, + Self::ClientBoundVehicleMove(_) => 0x2A, + Self::OpenSignEntity(_) => 0x2B, + Self::ClientBoundAbilities(_) => 0x2C, + Self::CombatEvent(_) => 0x2D, + Self::PlayerInfo(_) => 0x2E, + Self::ClientBoundPosition(_) => 0x2F, + Self::Bed(_) => 0x30, + Self::UnlockRecipes(_) => 0x31, + Self::EntityDestroy => 0x32, + Self::RemoveEntityEffect(_) => 0x33, + Self::ResourcePackSend(_) => 0x34, + Self::Respawn(_) => 0x35, + Self::EntityHeadRotation(_) => 0x36, + Self::WorldBorder(_) => 0x37, + Self::Camera(_) => 0x38, + Self::ClientBoundHeldItemSlot(_) => 0x39, + Self::ScoreboardDisplayObjective(_) => 0x3A, + Self::EntityMetadata(_) => 0x3B, + Self::AttachEntity(_) => 0x3C, + Self::EntityVelocity(_) => 0x3D, + Self::EntityEquipment(_) => 0x3E, + Self::Experience(_) => 0x3F, + Self::UpdateHealth(_) => 0x40, + Self::ScoreboardObjective(_) => 0x41, + Self::SetPassengers(_) => 0x42, + Self::Teams(_) => 0x43, + Self::ScoreboardScore(_) => 0x44, + Self::SpawnPosition(_) => 0x45, + Self::UpdateTime(_) => 0x46, + Self::Title(_) => 0x47, + Self::SoundEffect(_) => 0x48, + Self::PlayerlistHeader(_) => 0x49, + Self::Collect(_) => 0x4A, + Self::EntityTeleport(_) => 0x4B, + Self::EntityUpdateAttributes(_) => 0x4C, + Self::EntityEffect(_) => 0x4D, + Self::AdvancementProgress(_) => 0x4E, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x08 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x09 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x0A => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0B => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0C => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0D => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0E => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0F => Ok(Self::ClientBoundTabComplete), + 0x10 => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x11 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x14 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x15 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x16 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x17 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x18 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x19 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x1A => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1B => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1C => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1D => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1E => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1F => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x20 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x21 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x22 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x23 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x24 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x25 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x26 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x27 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x28 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x29 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2A => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2B => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2C => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2D => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2E => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2F => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x30 => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x31 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x32 => Ok(Self::EntityDestroy), + 0x33 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x34 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x35 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x36 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x37 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x38 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x39 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x3A => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x3B => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3C => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3D => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3E => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x3F => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x40 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x41 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x42 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x43 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x44 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x45 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x46 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x47 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x48 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x49 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x4A => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x4B => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4C => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4D => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x4E => { + let advancement_progress = AdvancementProgress::decode(reader)?; + + Ok(Self::AdvancementProgress(advancement_progress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn unlock_recipes( + action: i16, + crafting_book_open: bool, + filtering_craftable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn advancement_progress(id: String) -> Self { + let advancement_progress = AdvancementProgress { id }; + + Self::AdvancementProgress(advancement_progress) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PrepareCraftingGrid { + pub window_id: u8, + pub action_number: u16, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + pub type_: u32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + pub action: i16, + pub crafting_book_open: bool, + pub filtering_craftable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct AdvancementProgress { + pub id: String, +} diff --git a/protocol/src/version/v_1_12_pre4/handshake.rs b/protocol/src/version/v_1_12_pre4/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_12_pre4/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_12_pre4/login.rs b/protocol/src/version/v_1_12_pre4/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_1_12_pre4/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_1_12_pre4/mod.rs b/protocol/src/version/v_1_12_pre4/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_12_pre4/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_12_pre4/status.rs b/protocol/src/version/v_1_12_pre4/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_12_pre4/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_13/game.rs b/protocol/src/version/v_1_13/game.rs new file mode 100644 index 0000000..7a325a6 --- /dev/null +++ b/protocol/src/version/v_1_13/game.rs @@ -0,0 +1,3257 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::EditBook(_) => 0x0B, + Self::QueryEntityNbt(_) => 0x0C, + Self::PickItem(_) => 0x15, + Self::NameItem(_) => 0x1C, + Self::SelectTrade(_) => 0x1F, + Self::SetBeaconEffect(_) => 0x20, + Self::UpdateCommandBlock(_) => 0x22, + Self::UpdateCommandBlockMinecart(_) => 0x23, + Self::UpdateStructureBlock(_) => 0x25, + Self::ServerBoundTabComplete(_) => 0x05, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x06, + Self::EnchantItem(_) => 0x07, + Self::WindowClick(_) => 0x08, + Self::ServerBoundCloseWindow(_) => 0x09, + Self::ServerBoundCustomPayload(_) => 0x0A, + Self::UseEntity(_) => 0x0D, + Self::ServerBoundKeepAlive(_) => 0x0E, + Self::ServerBoundPosition(_) => 0x10, + Self::PositionLook(_) => 0x11, + Self::Look(_) => 0x12, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x13, + Self::SteerBoat(_) => 0x14, + Self::CraftRecipeRequest(_) => 0x16, + Self::ServerBoundAbilities(_) => 0x17, + Self::BlockDig(_) => 0x18, + Self::EntityAction(_) => 0x19, + Self::SteerVehicle(_) => 0x1A, + Self::CraftingBookData(_) => 0x1B, + Self::ResourcePackReceive(_) => 0x1D, + Self::ServerBoundHeldItemSlot(_) => 0x21, + Self::SetCreativeSlot(_) => 0x24, + Self::UpdateSign(_) => 0x26, + Self::ArmAnimation(_) => 0x27, + Self::Spectate(_) => 0x28, + Self::BlockPlace(_) => 0x29, + Self::UseItem(_) => 0x2A, + Self::AdvancementTab(_) => 0x1E, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x0B => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0C => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x15 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1C => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x1F => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x20 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x22 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x23 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x25 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x05 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x06 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x07 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x08 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x09 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0A => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0D => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0E => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x10 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x11 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x12 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x13 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x14 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x16 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x17 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x18 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x19 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1A => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1B => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x1D => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x21 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x24 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x26 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x27 => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x28 => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x29 => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2A => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x1E => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn edit_book(new_book: Option, signing: bool) -> Self { + let edit_book = EditBook { new_book, signing }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x51, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete(_) => 0x10, + Self::DeclareCommands(_) => 0x11, + Self::FacePlayer(_) => 0x31, + Self::NbtQueryResponse(_) => 0x1D, + Self::ClientBoundChat(_) => 0x0E, + Self::MultiBlockChange(_) => 0x0F, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x14, + Self::WindowItems(_) => 0x15, + Self::CraftProgressBar(_) => 0x16, + Self::SetSlot(_) => 0x17, + Self::SetCooldown(_) => 0x18, + Self::ClientBoundCustomPayload(_) => 0x19, + Self::NamedSoundEffect(_) => 0x1A, + Self::KickDisconnect(_) => 0x1B, + Self::EntityStatus(_) => 0x1C, + Self::Explosion(_) => 0x1E, + Self::UnloadChunk(_) => 0x1F, + Self::GameStateChange(_) => 0x20, + Self::ClientBoundKeepAlive(_) => 0x21, + Self::MapChunk(_) => 0x22, + Self::WorldEvent(_) => 0x23, + Self::WorldParticles(_) => 0x24, + Self::JoinGame(_) => 0x25, + Self::Map(_) => 0x26, + Self::RelEntityMove(_) => 0x28, + Self::EntityMoveLook(_) => 0x29, + Self::EntityLook(_) => 0x2A, + Self::Entity(_) => 0x27, + Self::ClientBoundVehicleMove(_) => 0x2B, + Self::OpenSignEntity(_) => 0x2C, + Self::CraftRecipeResponse(_) => 0x2D, + Self::ClientBoundAbilities(_) => 0x2E, + Self::CombatEvent(_) => 0x2F, + Self::PlayerInfo(_) => 0x30, + Self::ClientBoundPosition(_) => 0x32, + Self::Bed(_) => 0x33, + Self::UnlockRecipes(_) => 0x34, + Self::EntityDestroy => 0x35, + Self::RemoveEntityEffect(_) => 0x36, + Self::ResourcePackSend(_) => 0x37, + Self::Respawn(_) => 0x38, + Self::EntityHeadRotation(_) => 0x39, + Self::WorldBorder(_) => 0x3B, + Self::Camera(_) => 0x3C, + Self::ClientBoundHeldItemSlot(_) => 0x3D, + Self::ScoreboardDisplayObjective(_) => 0x3E, + Self::EntityMetadata(_) => 0x3F, + Self::AttachEntity(_) => 0x40, + Self::EntityVelocity(_) => 0x41, + Self::EntityEquipment(_) => 0x42, + Self::Experience(_) => 0x43, + Self::UpdateHealth(_) => 0x44, + Self::ScoreboardObjective(_) => 0x45, + Self::SetPassengers(_) => 0x46, + Self::Teams(_) => 0x47, + Self::ScoreboardScore(_) => 0x48, + Self::SpawnPosition(_) => 0x49, + Self::UpdateTime(_) => 0x4A, + Self::Title(_) => 0x4B, + Self::StopSound(_) => 0x4C, + Self::SoundEffect(_) => 0x4D, + Self::PlayerlistHeader(_) => 0x4E, + Self::Collect(_) => 0x4F, + Self::EntityTeleport(_) => 0x50, + Self::EntityUpdateAttributes(_) => 0x52, + Self::EntityEffect(_) => 0x53, + Self::SelectAdvancementTab(_) => 0x3A, + Self::DeclareRecipes => 0x54, + Self::Tags(_) => 0x55, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x51 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x10 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x11 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x31 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x1D => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0E => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x0F => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x14 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x15 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x16 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x17 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x18 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x19 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x1A => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1B => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1C => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1E => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1F => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x20 => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x21 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x22 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x23 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x24 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x25 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x26 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x28 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x29 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2A => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x27 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2B => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2C => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2D => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x2E => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2F => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x30 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x32 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x33 => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x34 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x35 => Ok(Self::EntityDestroy), + 0x36 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x37 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x38 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x39 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3B => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3C => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3D => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x3E => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x3F => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x40 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x41 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x42 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x43 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x44 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x45 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x46 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x47 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x48 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x49 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4A => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x4B => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x4C => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x4D => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x4E => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x4F => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x50 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x52 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x53 => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3A => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x54 => Ok(Self::DeclareRecipes), + 0x55 => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags(block_tags: TagsMap, item_tags: TagsMap, fluid_tags: TagsMap) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + }; + + Self::Tags(tags) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, +} diff --git a/protocol/src/version/v_1_13/handshake.rs b/protocol/src/version/v_1_13/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_13/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_13/login.rs b/protocol/src/version/v_1_13/login.rs new file mode 100644 index 0000000..fcbf5cc --- /dev/null +++ b/protocol/src/version/v_1_13/login.rs @@ -0,0 +1,209 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_13/mod.rs b/protocol/src/version/v_1_13/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_13/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_13/status.rs b/protocol/src/version/v_1_13/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_13/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_13_1/game.rs b/protocol/src/version/v_1_13_1/game.rs new file mode 100644 index 0000000..396a73f --- /dev/null +++ b/protocol/src/version/v_1_13_1/game.rs @@ -0,0 +1,3263 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::EditBook(_) => 0x0B, + Self::QueryEntityNbt(_) => 0x0C, + Self::PickItem(_) => 0x15, + Self::NameItem(_) => 0x1C, + Self::SelectTrade(_) => 0x1F, + Self::SetBeaconEffect(_) => 0x20, + Self::UpdateCommandBlock(_) => 0x22, + Self::UpdateCommandBlockMinecart(_) => 0x23, + Self::UpdateStructureBlock(_) => 0x25, + Self::ServerBoundTabComplete(_) => 0x05, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x06, + Self::EnchantItem(_) => 0x07, + Self::WindowClick(_) => 0x08, + Self::ServerBoundCloseWindow(_) => 0x09, + Self::ServerBoundCustomPayload(_) => 0x0A, + Self::UseEntity(_) => 0x0D, + Self::ServerBoundKeepAlive(_) => 0x0E, + Self::ServerBoundPosition(_) => 0x10, + Self::PositionLook(_) => 0x11, + Self::Look(_) => 0x12, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x13, + Self::SteerBoat(_) => 0x14, + Self::CraftRecipeRequest(_) => 0x16, + Self::ServerBoundAbilities(_) => 0x17, + Self::BlockDig(_) => 0x18, + Self::EntityAction(_) => 0x19, + Self::SteerVehicle(_) => 0x1A, + Self::CraftingBookData(_) => 0x1B, + Self::ResourcePackReceive(_) => 0x1D, + Self::ServerBoundHeldItemSlot(_) => 0x21, + Self::SetCreativeSlot(_) => 0x24, + Self::UpdateSign(_) => 0x26, + Self::ArmAnimation(_) => 0x27, + Self::Spectate(_) => 0x28, + Self::BlockPlace(_) => 0x29, + Self::UseItem(_) => 0x2A, + Self::AdvancementTab(_) => 0x1E, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x0B => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0C => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x15 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1C => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x1F => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x20 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x22 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x23 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x25 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x05 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x06 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x07 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x08 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x09 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0A => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0D => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0E => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x10 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x11 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x12 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x13 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x14 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x16 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x17 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x18 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x19 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1A => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1B => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x1D => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x21 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x24 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x26 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x27 => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x28 => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x29 => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2A => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x1E => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x51, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete(_) => 0x10, + Self::DeclareCommands(_) => 0x11, + Self::FacePlayer(_) => 0x31, + Self::NbtQueryResponse(_) => 0x1D, + Self::ClientBoundChat(_) => 0x0E, + Self::MultiBlockChange(_) => 0x0F, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x14, + Self::WindowItems(_) => 0x15, + Self::CraftProgressBar(_) => 0x16, + Self::SetSlot(_) => 0x17, + Self::SetCooldown(_) => 0x18, + Self::ClientBoundCustomPayload(_) => 0x19, + Self::NamedSoundEffect(_) => 0x1A, + Self::KickDisconnect(_) => 0x1B, + Self::EntityStatus(_) => 0x1C, + Self::Explosion(_) => 0x1E, + Self::UnloadChunk(_) => 0x1F, + Self::GameStateChange(_) => 0x20, + Self::ClientBoundKeepAlive(_) => 0x21, + Self::MapChunk(_) => 0x22, + Self::WorldEvent(_) => 0x23, + Self::WorldParticles(_) => 0x24, + Self::JoinGame(_) => 0x25, + Self::Map(_) => 0x26, + Self::RelEntityMove(_) => 0x28, + Self::EntityMoveLook(_) => 0x29, + Self::EntityLook(_) => 0x2A, + Self::Entity(_) => 0x27, + Self::ClientBoundVehicleMove(_) => 0x2B, + Self::OpenSignEntity(_) => 0x2C, + Self::CraftRecipeResponse(_) => 0x2D, + Self::ClientBoundAbilities(_) => 0x2E, + Self::CombatEvent(_) => 0x2F, + Self::PlayerInfo(_) => 0x30, + Self::ClientBoundPosition(_) => 0x32, + Self::Bed(_) => 0x33, + Self::UnlockRecipes(_) => 0x34, + Self::EntityDestroy => 0x35, + Self::RemoveEntityEffect(_) => 0x36, + Self::ResourcePackSend(_) => 0x37, + Self::Respawn(_) => 0x38, + Self::EntityHeadRotation(_) => 0x39, + Self::WorldBorder(_) => 0x3B, + Self::Camera(_) => 0x3C, + Self::ClientBoundHeldItemSlot(_) => 0x3D, + Self::ScoreboardDisplayObjective(_) => 0x3E, + Self::EntityMetadata(_) => 0x3F, + Self::AttachEntity(_) => 0x40, + Self::EntityVelocity(_) => 0x41, + Self::EntityEquipment(_) => 0x42, + Self::Experience(_) => 0x43, + Self::UpdateHealth(_) => 0x44, + Self::ScoreboardObjective(_) => 0x45, + Self::SetPassengers(_) => 0x46, + Self::Teams(_) => 0x47, + Self::ScoreboardScore(_) => 0x48, + Self::SpawnPosition(_) => 0x49, + Self::UpdateTime(_) => 0x4A, + Self::Title(_) => 0x4B, + Self::StopSound(_) => 0x4C, + Self::SoundEffect(_) => 0x4D, + Self::PlayerlistHeader(_) => 0x4E, + Self::Collect(_) => 0x4F, + Self::EntityTeleport(_) => 0x50, + Self::EntityUpdateAttributes(_) => 0x52, + Self::EntityEffect(_) => 0x53, + Self::SelectAdvancementTab(_) => 0x3A, + Self::DeclareRecipes => 0x54, + Self::Tags(_) => 0x55, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x51 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x10 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x11 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x31 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x1D => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0E => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x0F => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x14 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x15 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x16 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x17 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x18 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x19 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x1A => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1B => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1C => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1E => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1F => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x20 => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x21 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x22 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x23 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x24 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x25 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x26 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x28 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x29 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2A => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x27 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2B => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2C => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2D => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x2E => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2F => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x30 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x32 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x33 => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x34 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x35 => Ok(Self::EntityDestroy), + 0x36 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x37 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x38 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x39 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3B => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3C => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3D => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x3E => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x3F => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x40 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x41 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x42 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x43 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x44 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x45 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x46 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x47 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x48 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x49 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4A => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x4B => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x4C => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x4D => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x4E => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x4F => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x50 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x52 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x53 => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3A => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x54 => Ok(Self::DeclareRecipes), + 0x55 => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags(block_tags: TagsMap, item_tags: TagsMap, fluid_tags: TagsMap) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + }; + + Self::Tags(tags) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, +} diff --git a/protocol/src/version/v_1_13_1/handshake.rs b/protocol/src/version/v_1_13_1/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_13_1/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_13_1/login.rs b/protocol/src/version/v_1_13_1/login.rs new file mode 100644 index 0000000..fcbf5cc --- /dev/null +++ b/protocol/src/version/v_1_13_1/login.rs @@ -0,0 +1,209 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_13_1/mod.rs b/protocol/src/version/v_1_13_1/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_13_1/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_13_1/status.rs b/protocol/src/version/v_1_13_1/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_13_1/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_13_2/game.rs b/protocol/src/version/v_1_13_2/game.rs new file mode 100644 index 0000000..396a73f --- /dev/null +++ b/protocol/src/version/v_1_13_2/game.rs @@ -0,0 +1,3263 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::EditBook(_) => 0x0B, + Self::QueryEntityNbt(_) => 0x0C, + Self::PickItem(_) => 0x15, + Self::NameItem(_) => 0x1C, + Self::SelectTrade(_) => 0x1F, + Self::SetBeaconEffect(_) => 0x20, + Self::UpdateCommandBlock(_) => 0x22, + Self::UpdateCommandBlockMinecart(_) => 0x23, + Self::UpdateStructureBlock(_) => 0x25, + Self::ServerBoundTabComplete(_) => 0x05, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x06, + Self::EnchantItem(_) => 0x07, + Self::WindowClick(_) => 0x08, + Self::ServerBoundCloseWindow(_) => 0x09, + Self::ServerBoundCustomPayload(_) => 0x0A, + Self::UseEntity(_) => 0x0D, + Self::ServerBoundKeepAlive(_) => 0x0E, + Self::ServerBoundPosition(_) => 0x10, + Self::PositionLook(_) => 0x11, + Self::Look(_) => 0x12, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x13, + Self::SteerBoat(_) => 0x14, + Self::CraftRecipeRequest(_) => 0x16, + Self::ServerBoundAbilities(_) => 0x17, + Self::BlockDig(_) => 0x18, + Self::EntityAction(_) => 0x19, + Self::SteerVehicle(_) => 0x1A, + Self::CraftingBookData(_) => 0x1B, + Self::ResourcePackReceive(_) => 0x1D, + Self::ServerBoundHeldItemSlot(_) => 0x21, + Self::SetCreativeSlot(_) => 0x24, + Self::UpdateSign(_) => 0x26, + Self::ArmAnimation(_) => 0x27, + Self::Spectate(_) => 0x28, + Self::BlockPlace(_) => 0x29, + Self::UseItem(_) => 0x2A, + Self::AdvancementTab(_) => 0x1E, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x0B => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0C => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x15 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1C => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x1F => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x20 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x22 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x23 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x25 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x05 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x06 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x07 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x08 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x09 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0A => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0D => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0E => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x10 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x11 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x12 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x13 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x14 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x16 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x17 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x18 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x19 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1A => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1B => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x1D => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x21 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x24 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x26 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x27 => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x28 => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x29 => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2A => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x1E => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x51, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete(_) => 0x10, + Self::DeclareCommands(_) => 0x11, + Self::FacePlayer(_) => 0x31, + Self::NbtQueryResponse(_) => 0x1D, + Self::ClientBoundChat(_) => 0x0E, + Self::MultiBlockChange(_) => 0x0F, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x14, + Self::WindowItems(_) => 0x15, + Self::CraftProgressBar(_) => 0x16, + Self::SetSlot(_) => 0x17, + Self::SetCooldown(_) => 0x18, + Self::ClientBoundCustomPayload(_) => 0x19, + Self::NamedSoundEffect(_) => 0x1A, + Self::KickDisconnect(_) => 0x1B, + Self::EntityStatus(_) => 0x1C, + Self::Explosion(_) => 0x1E, + Self::UnloadChunk(_) => 0x1F, + Self::GameStateChange(_) => 0x20, + Self::ClientBoundKeepAlive(_) => 0x21, + Self::MapChunk(_) => 0x22, + Self::WorldEvent(_) => 0x23, + Self::WorldParticles(_) => 0x24, + Self::JoinGame(_) => 0x25, + Self::Map(_) => 0x26, + Self::RelEntityMove(_) => 0x28, + Self::EntityMoveLook(_) => 0x29, + Self::EntityLook(_) => 0x2A, + Self::Entity(_) => 0x27, + Self::ClientBoundVehicleMove(_) => 0x2B, + Self::OpenSignEntity(_) => 0x2C, + Self::CraftRecipeResponse(_) => 0x2D, + Self::ClientBoundAbilities(_) => 0x2E, + Self::CombatEvent(_) => 0x2F, + Self::PlayerInfo(_) => 0x30, + Self::ClientBoundPosition(_) => 0x32, + Self::Bed(_) => 0x33, + Self::UnlockRecipes(_) => 0x34, + Self::EntityDestroy => 0x35, + Self::RemoveEntityEffect(_) => 0x36, + Self::ResourcePackSend(_) => 0x37, + Self::Respawn(_) => 0x38, + Self::EntityHeadRotation(_) => 0x39, + Self::WorldBorder(_) => 0x3B, + Self::Camera(_) => 0x3C, + Self::ClientBoundHeldItemSlot(_) => 0x3D, + Self::ScoreboardDisplayObjective(_) => 0x3E, + Self::EntityMetadata(_) => 0x3F, + Self::AttachEntity(_) => 0x40, + Self::EntityVelocity(_) => 0x41, + Self::EntityEquipment(_) => 0x42, + Self::Experience(_) => 0x43, + Self::UpdateHealth(_) => 0x44, + Self::ScoreboardObjective(_) => 0x45, + Self::SetPassengers(_) => 0x46, + Self::Teams(_) => 0x47, + Self::ScoreboardScore(_) => 0x48, + Self::SpawnPosition(_) => 0x49, + Self::UpdateTime(_) => 0x4A, + Self::Title(_) => 0x4B, + Self::StopSound(_) => 0x4C, + Self::SoundEffect(_) => 0x4D, + Self::PlayerlistHeader(_) => 0x4E, + Self::Collect(_) => 0x4F, + Self::EntityTeleport(_) => 0x50, + Self::EntityUpdateAttributes(_) => 0x52, + Self::EntityEffect(_) => 0x53, + Self::SelectAdvancementTab(_) => 0x3A, + Self::DeclareRecipes => 0x54, + Self::Tags(_) => 0x55, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x51 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x10 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x11 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x31 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x1D => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0E => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x0F => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x14 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x15 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x16 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x17 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x18 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x19 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x1A => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1B => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1C => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1E => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1F => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x20 => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x21 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x22 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x23 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x24 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x25 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x26 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x28 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x29 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2A => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x27 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2B => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2C => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2D => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x2E => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2F => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x30 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x32 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x33 => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x34 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x35 => Ok(Self::EntityDestroy), + 0x36 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x37 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x38 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x39 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3B => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3C => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3D => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x3E => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x3F => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x40 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x41 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x42 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x43 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x44 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x45 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x46 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x47 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x48 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x49 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4A => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x4B => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x4C => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x4D => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x4E => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x4F => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x50 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x52 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x53 => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3A => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x54 => Ok(Self::DeclareRecipes), + 0x55 => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags(block_tags: TagsMap, item_tags: TagsMap, fluid_tags: TagsMap) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + }; + + Self::Tags(tags) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, +} diff --git a/protocol/src/version/v_1_13_2/handshake.rs b/protocol/src/version/v_1_13_2/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_13_2/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_13_2/login.rs b/protocol/src/version/v_1_13_2/login.rs new file mode 100644 index 0000000..fcbf5cc --- /dev/null +++ b/protocol/src/version/v_1_13_2/login.rs @@ -0,0 +1,209 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_13_2/mod.rs b/protocol/src/version/v_1_13_2/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_13_2/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_13_2/status.rs b/protocol/src/version/v_1_13_2/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_13_2/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_13_2_pre1/game.rs b/protocol/src/version/v_1_13_2_pre1/game.rs new file mode 100644 index 0000000..396a73f --- /dev/null +++ b/protocol/src/version/v_1_13_2_pre1/game.rs @@ -0,0 +1,3263 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::EditBook(_) => 0x0B, + Self::QueryEntityNbt(_) => 0x0C, + Self::PickItem(_) => 0x15, + Self::NameItem(_) => 0x1C, + Self::SelectTrade(_) => 0x1F, + Self::SetBeaconEffect(_) => 0x20, + Self::UpdateCommandBlock(_) => 0x22, + Self::UpdateCommandBlockMinecart(_) => 0x23, + Self::UpdateStructureBlock(_) => 0x25, + Self::ServerBoundTabComplete(_) => 0x05, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x06, + Self::EnchantItem(_) => 0x07, + Self::WindowClick(_) => 0x08, + Self::ServerBoundCloseWindow(_) => 0x09, + Self::ServerBoundCustomPayload(_) => 0x0A, + Self::UseEntity(_) => 0x0D, + Self::ServerBoundKeepAlive(_) => 0x0E, + Self::ServerBoundPosition(_) => 0x10, + Self::PositionLook(_) => 0x11, + Self::Look(_) => 0x12, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x13, + Self::SteerBoat(_) => 0x14, + Self::CraftRecipeRequest(_) => 0x16, + Self::ServerBoundAbilities(_) => 0x17, + Self::BlockDig(_) => 0x18, + Self::EntityAction(_) => 0x19, + Self::SteerVehicle(_) => 0x1A, + Self::CraftingBookData(_) => 0x1B, + Self::ResourcePackReceive(_) => 0x1D, + Self::ServerBoundHeldItemSlot(_) => 0x21, + Self::SetCreativeSlot(_) => 0x24, + Self::UpdateSign(_) => 0x26, + Self::ArmAnimation(_) => 0x27, + Self::Spectate(_) => 0x28, + Self::BlockPlace(_) => 0x29, + Self::UseItem(_) => 0x2A, + Self::AdvancementTab(_) => 0x1E, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x0B => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0C => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x15 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1C => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x1F => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x20 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x22 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x23 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x25 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x05 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x06 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x07 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x08 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x09 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0A => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0D => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0E => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x10 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x11 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x12 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x13 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x14 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x16 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x17 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x18 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x19 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1A => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1B => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x1D => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x21 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x24 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x26 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x27 => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x28 => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x29 => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2A => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x1E => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x51, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete(_) => 0x10, + Self::DeclareCommands(_) => 0x11, + Self::FacePlayer(_) => 0x31, + Self::NbtQueryResponse(_) => 0x1D, + Self::ClientBoundChat(_) => 0x0E, + Self::MultiBlockChange(_) => 0x0F, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x14, + Self::WindowItems(_) => 0x15, + Self::CraftProgressBar(_) => 0x16, + Self::SetSlot(_) => 0x17, + Self::SetCooldown(_) => 0x18, + Self::ClientBoundCustomPayload(_) => 0x19, + Self::NamedSoundEffect(_) => 0x1A, + Self::KickDisconnect(_) => 0x1B, + Self::EntityStatus(_) => 0x1C, + Self::Explosion(_) => 0x1E, + Self::UnloadChunk(_) => 0x1F, + Self::GameStateChange(_) => 0x20, + Self::ClientBoundKeepAlive(_) => 0x21, + Self::MapChunk(_) => 0x22, + Self::WorldEvent(_) => 0x23, + Self::WorldParticles(_) => 0x24, + Self::JoinGame(_) => 0x25, + Self::Map(_) => 0x26, + Self::RelEntityMove(_) => 0x28, + Self::EntityMoveLook(_) => 0x29, + Self::EntityLook(_) => 0x2A, + Self::Entity(_) => 0x27, + Self::ClientBoundVehicleMove(_) => 0x2B, + Self::OpenSignEntity(_) => 0x2C, + Self::CraftRecipeResponse(_) => 0x2D, + Self::ClientBoundAbilities(_) => 0x2E, + Self::CombatEvent(_) => 0x2F, + Self::PlayerInfo(_) => 0x30, + Self::ClientBoundPosition(_) => 0x32, + Self::Bed(_) => 0x33, + Self::UnlockRecipes(_) => 0x34, + Self::EntityDestroy => 0x35, + Self::RemoveEntityEffect(_) => 0x36, + Self::ResourcePackSend(_) => 0x37, + Self::Respawn(_) => 0x38, + Self::EntityHeadRotation(_) => 0x39, + Self::WorldBorder(_) => 0x3B, + Self::Camera(_) => 0x3C, + Self::ClientBoundHeldItemSlot(_) => 0x3D, + Self::ScoreboardDisplayObjective(_) => 0x3E, + Self::EntityMetadata(_) => 0x3F, + Self::AttachEntity(_) => 0x40, + Self::EntityVelocity(_) => 0x41, + Self::EntityEquipment(_) => 0x42, + Self::Experience(_) => 0x43, + Self::UpdateHealth(_) => 0x44, + Self::ScoreboardObjective(_) => 0x45, + Self::SetPassengers(_) => 0x46, + Self::Teams(_) => 0x47, + Self::ScoreboardScore(_) => 0x48, + Self::SpawnPosition(_) => 0x49, + Self::UpdateTime(_) => 0x4A, + Self::Title(_) => 0x4B, + Self::StopSound(_) => 0x4C, + Self::SoundEffect(_) => 0x4D, + Self::PlayerlistHeader(_) => 0x4E, + Self::Collect(_) => 0x4F, + Self::EntityTeleport(_) => 0x50, + Self::EntityUpdateAttributes(_) => 0x52, + Self::EntityEffect(_) => 0x53, + Self::SelectAdvancementTab(_) => 0x3A, + Self::DeclareRecipes => 0x54, + Self::Tags(_) => 0x55, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x51 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x10 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x11 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x31 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x1D => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0E => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x0F => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x14 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x15 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x16 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x17 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x18 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x19 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x1A => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1B => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1C => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1E => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1F => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x20 => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x21 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x22 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x23 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x24 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x25 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x26 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x28 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x29 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2A => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x27 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2B => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2C => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2D => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x2E => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2F => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x30 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x32 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x33 => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x34 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x35 => Ok(Self::EntityDestroy), + 0x36 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x37 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x38 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x39 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3B => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3C => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3D => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x3E => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x3F => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x40 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x41 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x42 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x43 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x44 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x45 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x46 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x47 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x48 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x49 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4A => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x4B => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x4C => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x4D => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x4E => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x4F => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x50 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x52 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x53 => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3A => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x54 => Ok(Self::DeclareRecipes), + 0x55 => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags(block_tags: TagsMap, item_tags: TagsMap, fluid_tags: TagsMap) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + }; + + Self::Tags(tags) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, +} diff --git a/protocol/src/version/v_1_13_2_pre1/handshake.rs b/protocol/src/version/v_1_13_2_pre1/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_13_2_pre1/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_13_2_pre1/login.rs b/protocol/src/version/v_1_13_2_pre1/login.rs new file mode 100644 index 0000000..fcbf5cc --- /dev/null +++ b/protocol/src/version/v_1_13_2_pre1/login.rs @@ -0,0 +1,209 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_13_2_pre1/mod.rs b/protocol/src/version/v_1_13_2_pre1/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_13_2_pre1/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_13_2_pre1/status.rs b/protocol/src/version/v_1_13_2_pre1/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_13_2_pre1/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_13_2_pre2/game.rs b/protocol/src/version/v_1_13_2_pre2/game.rs new file mode 100644 index 0000000..396a73f --- /dev/null +++ b/protocol/src/version/v_1_13_2_pre2/game.rs @@ -0,0 +1,3263 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::EditBook(_) => 0x0B, + Self::QueryEntityNbt(_) => 0x0C, + Self::PickItem(_) => 0x15, + Self::NameItem(_) => 0x1C, + Self::SelectTrade(_) => 0x1F, + Self::SetBeaconEffect(_) => 0x20, + Self::UpdateCommandBlock(_) => 0x22, + Self::UpdateCommandBlockMinecart(_) => 0x23, + Self::UpdateStructureBlock(_) => 0x25, + Self::ServerBoundTabComplete(_) => 0x05, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x06, + Self::EnchantItem(_) => 0x07, + Self::WindowClick(_) => 0x08, + Self::ServerBoundCloseWindow(_) => 0x09, + Self::ServerBoundCustomPayload(_) => 0x0A, + Self::UseEntity(_) => 0x0D, + Self::ServerBoundKeepAlive(_) => 0x0E, + Self::ServerBoundPosition(_) => 0x10, + Self::PositionLook(_) => 0x11, + Self::Look(_) => 0x12, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x13, + Self::SteerBoat(_) => 0x14, + Self::CraftRecipeRequest(_) => 0x16, + Self::ServerBoundAbilities(_) => 0x17, + Self::BlockDig(_) => 0x18, + Self::EntityAction(_) => 0x19, + Self::SteerVehicle(_) => 0x1A, + Self::CraftingBookData(_) => 0x1B, + Self::ResourcePackReceive(_) => 0x1D, + Self::ServerBoundHeldItemSlot(_) => 0x21, + Self::SetCreativeSlot(_) => 0x24, + Self::UpdateSign(_) => 0x26, + Self::ArmAnimation(_) => 0x27, + Self::Spectate(_) => 0x28, + Self::BlockPlace(_) => 0x29, + Self::UseItem(_) => 0x2A, + Self::AdvancementTab(_) => 0x1E, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x0B => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0C => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x15 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1C => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x1F => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x20 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x22 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x23 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x25 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x05 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x06 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x07 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x08 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x09 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0A => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0D => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0E => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x10 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x11 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x12 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x13 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x14 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x16 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x17 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x18 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x19 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1A => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1B => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x1D => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x21 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x24 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x26 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x27 => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x28 => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x29 => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2A => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x1E => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x51, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete(_) => 0x10, + Self::DeclareCommands(_) => 0x11, + Self::FacePlayer(_) => 0x31, + Self::NbtQueryResponse(_) => 0x1D, + Self::ClientBoundChat(_) => 0x0E, + Self::MultiBlockChange(_) => 0x0F, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x14, + Self::WindowItems(_) => 0x15, + Self::CraftProgressBar(_) => 0x16, + Self::SetSlot(_) => 0x17, + Self::SetCooldown(_) => 0x18, + Self::ClientBoundCustomPayload(_) => 0x19, + Self::NamedSoundEffect(_) => 0x1A, + Self::KickDisconnect(_) => 0x1B, + Self::EntityStatus(_) => 0x1C, + Self::Explosion(_) => 0x1E, + Self::UnloadChunk(_) => 0x1F, + Self::GameStateChange(_) => 0x20, + Self::ClientBoundKeepAlive(_) => 0x21, + Self::MapChunk(_) => 0x22, + Self::WorldEvent(_) => 0x23, + Self::WorldParticles(_) => 0x24, + Self::JoinGame(_) => 0x25, + Self::Map(_) => 0x26, + Self::RelEntityMove(_) => 0x28, + Self::EntityMoveLook(_) => 0x29, + Self::EntityLook(_) => 0x2A, + Self::Entity(_) => 0x27, + Self::ClientBoundVehicleMove(_) => 0x2B, + Self::OpenSignEntity(_) => 0x2C, + Self::CraftRecipeResponse(_) => 0x2D, + Self::ClientBoundAbilities(_) => 0x2E, + Self::CombatEvent(_) => 0x2F, + Self::PlayerInfo(_) => 0x30, + Self::ClientBoundPosition(_) => 0x32, + Self::Bed(_) => 0x33, + Self::UnlockRecipes(_) => 0x34, + Self::EntityDestroy => 0x35, + Self::RemoveEntityEffect(_) => 0x36, + Self::ResourcePackSend(_) => 0x37, + Self::Respawn(_) => 0x38, + Self::EntityHeadRotation(_) => 0x39, + Self::WorldBorder(_) => 0x3B, + Self::Camera(_) => 0x3C, + Self::ClientBoundHeldItemSlot(_) => 0x3D, + Self::ScoreboardDisplayObjective(_) => 0x3E, + Self::EntityMetadata(_) => 0x3F, + Self::AttachEntity(_) => 0x40, + Self::EntityVelocity(_) => 0x41, + Self::EntityEquipment(_) => 0x42, + Self::Experience(_) => 0x43, + Self::UpdateHealth(_) => 0x44, + Self::ScoreboardObjective(_) => 0x45, + Self::SetPassengers(_) => 0x46, + Self::Teams(_) => 0x47, + Self::ScoreboardScore(_) => 0x48, + Self::SpawnPosition(_) => 0x49, + Self::UpdateTime(_) => 0x4A, + Self::Title(_) => 0x4B, + Self::StopSound(_) => 0x4C, + Self::SoundEffect(_) => 0x4D, + Self::PlayerlistHeader(_) => 0x4E, + Self::Collect(_) => 0x4F, + Self::EntityTeleport(_) => 0x50, + Self::EntityUpdateAttributes(_) => 0x52, + Self::EntityEffect(_) => 0x53, + Self::SelectAdvancementTab(_) => 0x3A, + Self::DeclareRecipes => 0x54, + Self::Tags(_) => 0x55, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x51 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x10 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x11 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x31 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x1D => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0E => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x0F => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x14 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x15 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x16 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x17 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x18 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x19 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x1A => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1B => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1C => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1E => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1F => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x20 => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x21 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x22 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x23 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x24 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x25 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x26 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x28 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x29 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2A => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x27 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2B => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2C => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2D => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x2E => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2F => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x30 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x32 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x33 => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x34 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x35 => Ok(Self::EntityDestroy), + 0x36 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x37 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x38 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x39 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3B => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3C => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3D => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x3E => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x3F => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x40 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x41 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x42 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x43 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x44 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x45 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x46 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x47 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x48 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x49 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4A => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x4B => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x4C => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x4D => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x4E => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x4F => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x50 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x52 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x53 => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3A => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x54 => Ok(Self::DeclareRecipes), + 0x55 => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags(block_tags: TagsMap, item_tags: TagsMap, fluid_tags: TagsMap) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + }; + + Self::Tags(tags) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, +} diff --git a/protocol/src/version/v_1_13_2_pre2/handshake.rs b/protocol/src/version/v_1_13_2_pre2/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_13_2_pre2/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_13_2_pre2/login.rs b/protocol/src/version/v_1_13_2_pre2/login.rs new file mode 100644 index 0000000..fcbf5cc --- /dev/null +++ b/protocol/src/version/v_1_13_2_pre2/login.rs @@ -0,0 +1,209 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_13_2_pre2/mod.rs b/protocol/src/version/v_1_13_2_pre2/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_13_2_pre2/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_13_2_pre2/status.rs b/protocol/src/version/v_1_13_2_pre2/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_13_2_pre2/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_14/game.rs b/protocol/src/version/v_1_14/game.rs new file mode 100644 index 0000000..ed76c79 --- /dev/null +++ b/protocol/src/version/v_1_14/game.rs @@ -0,0 +1,3535 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + SetDifficulty(SetDifficulty), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + LockDifficulty(LockDifficulty), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateJigsawBlock(UpdateJigsawBlock), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::SetDifficulty(_) => 0x02, + Self::EditBook(_) => 0x0C, + Self::QueryEntityNbt(_) => 0x0D, + Self::PickItem(_) => 0x17, + Self::NameItem(_) => 0x1E, + Self::SelectTrade(_) => 0x21, + Self::SetBeaconEffect(_) => 0x22, + Self::UpdateCommandBlock(_) => 0x24, + Self::UpdateCommandBlockMinecart(_) => 0x25, + Self::UpdateStructureBlock(_) => 0x28, + Self::ServerBoundTabComplete(_) => 0x06, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x07, + Self::EnchantItem(_) => 0x08, + Self::WindowClick(_) => 0x09, + Self::ServerBoundCloseWindow(_) => 0x0A, + Self::ServerBoundCustomPayload(_) => 0x0B, + Self::UseEntity(_) => 0x0E, + Self::ServerBoundKeepAlive(_) => 0x0F, + Self::LockDifficulty(_) => 0x10, + Self::ServerBoundPosition(_) => 0x11, + Self::PositionLook(_) => 0x12, + Self::Look(_) => 0x13, + Self::Flying(_) => 0x14, + Self::ServerBoundVehicleMove(_) => 0x15, + Self::SteerBoat(_) => 0x16, + Self::CraftRecipeRequest(_) => 0x18, + Self::ServerBoundAbilities(_) => 0x19, + Self::BlockDig(_) => 0x1A, + Self::EntityAction(_) => 0x1B, + Self::SteerVehicle(_) => 0x1C, + Self::CraftingBookData(_) => 0x1D, + Self::ResourcePackReceive(_) => 0x1F, + Self::ServerBoundHeldItemSlot(_) => 0x23, + Self::SetCreativeSlot(_) => 0x26, + Self::UpdateJigsawBlock(_) => 0x27, + Self::UpdateSign(_) => 0x29, + Self::ArmAnimation(_) => 0x2A, + Self::Spectate(_) => 0x2B, + Self::BlockPlace(_) => 0x2C, + Self::UseItem(_) => 0x2D, + Self::AdvancementTab(_) => 0x20, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x02 => { + let set_difficulty = SetDifficulty::decode(reader)?; + + Ok(Self::SetDifficulty(set_difficulty)) + } + 0x0C => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0D => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x17 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1E => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x21 => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x22 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x24 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x25 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x28 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x06 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x07 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x08 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x09 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x0A => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0B => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0E => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0F => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x10 => { + let lock_difficulty = LockDifficulty::decode(reader)?; + + Ok(Self::LockDifficulty(lock_difficulty)) + } + 0x11 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x12 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x13 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x14 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x15 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x16 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x18 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x19 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x1A => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x1B => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1C => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1D => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x1F => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x23 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x26 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x27 => { + let update_jigsaw_block = UpdateJigsawBlock::decode(reader)?; + + Ok(Self::UpdateJigsawBlock(update_jigsaw_block)) + } + 0x29 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x2A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x2B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x2C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x20 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn set_difficulty(new_difficulty: u8) -> Self { + let set_difficulty = SetDifficulty { new_difficulty }; + + Self::SetDifficulty(set_difficulty) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn lock_difficulty(locked: bool) -> Self { + let lock_difficulty = LockDifficulty { locked }; + + Self::LockDifficulty(lock_difficulty) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_jigsaw_block( + location: Position, + attachment_type: String, + target_pool: String, + final_state: String, + ) -> Self { + let update_jigsaw_block = UpdateJigsawBlock { + location, + attachment_type, + target_pool, + final_state, + }; + + Self::UpdateJigsawBlock(update_jigsaw_block) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + hand: i32, + location: Position, + direction: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + inside_block: bool, + ) -> Self { + let block_place = BlockPlace { + hand, + location, + direction, + cursor_x, + cursor_y, + cursor_z, + inside_block, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + OpenHorseWindow(OpenHorseWindow), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + UpdateLight(UpdateLight), + JoinGame(JoinGame), + Map(Map), + TradeList(TradeList), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenBook(OpenBook), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + UpdateViewPosition(UpdateViewPosition), + UpdateViewDistance(UpdateViewDistance), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + EntitySoundEffect(EntitySoundEffect), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x57, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete(_) => 0x10, + Self::DeclareCommands(_) => 0x11, + Self::FacePlayer(_) => 0x34, + Self::NbtQueryResponse(_) => 0x54, + Self::ClientBoundChat(_) => 0x0E, + Self::MultiBlockChange(_) => 0x0F, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x2E, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::OpenHorseWindow(_) => 0x1F, + Self::ClientBoundKeepAlive(_) => 0x20, + Self::MapChunk(_) => 0x21, + Self::WorldEvent(_) => 0x22, + Self::WorldParticles(_) => 0x23, + Self::UpdateLight(_) => 0x24, + Self::JoinGame(_) => 0x25, + Self::Map(_) => 0x26, + Self::TradeList(_) => 0x27, + Self::RelEntityMove(_) => 0x28, + Self::EntityMoveLook(_) => 0x29, + Self::EntityLook(_) => 0x2A, + Self::Entity(_) => 0x2B, + Self::ClientBoundVehicleMove(_) => 0x2C, + Self::OpenBook(_) => 0x2D, + Self::OpenSignEntity(_) => 0x2F, + Self::CraftRecipeResponse(_) => 0x30, + Self::ClientBoundAbilities(_) => 0x31, + Self::CombatEvent(_) => 0x32, + Self::PlayerInfo(_) => 0x33, + Self::ClientBoundPosition(_) => 0x35, + Self::UnlockRecipes(_) => 0x36, + Self::EntityDestroy => 0x37, + Self::RemoveEntityEffect(_) => 0x38, + Self::ResourcePackSend(_) => 0x39, + Self::Respawn(_) => 0x3A, + Self::EntityHeadRotation(_) => 0x3B, + Self::WorldBorder(_) => 0x3D, + Self::Camera(_) => 0x3E, + Self::ClientBoundHeldItemSlot(_) => 0x3F, + Self::UpdateViewPosition(_) => 0x40, + Self::UpdateViewDistance(_) => 0x41, + Self::ScoreboardDisplayObjective(_) => 0x42, + Self::EntityMetadata(_) => 0x43, + Self::AttachEntity(_) => 0x44, + Self::EntityVelocity(_) => 0x45, + Self::EntityEquipment(_) => 0x46, + Self::Experience(_) => 0x47, + Self::UpdateHealth(_) => 0x48, + Self::ScoreboardObjective(_) => 0x49, + Self::SetPassengers(_) => 0x4A, + Self::Teams(_) => 0x4B, + Self::ScoreboardScore(_) => 0x4C, + Self::SpawnPosition(_) => 0x4D, + Self::UpdateTime(_) => 0x4E, + Self::Title(_) => 0x4F, + Self::EntitySoundEffect(_) => 0x50, + Self::StopSound(_) => 0x52, + Self::SoundEffect(_) => 0x51, + Self::PlayerlistHeader(_) => 0x53, + Self::Collect(_) => 0x55, + Self::EntityTeleport(_) => 0x56, + Self::EntityUpdateAttributes(_) => 0x58, + Self::EntityEffect(_) => 0x59, + Self::SelectAdvancementTab(_) => 0x3C, + Self::DeclareRecipes => 0x5A, + Self::Tags(_) => 0x5B, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x57 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x10 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x11 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x34 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x54 => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0E => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x0F => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x2E => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let open_horse_window = OpenHorseWindow::decode(reader)?; + + Ok(Self::OpenHorseWindow(open_horse_window)) + } + 0x20 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x21 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x22 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x23 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x24 => { + let update_light = UpdateLight::decode(reader)?; + + Ok(Self::UpdateLight(update_light)) + } + 0x25 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x26 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x27 => { + let trade_list = TradeList::decode(reader)?; + + Ok(Self::TradeList(trade_list)) + } + 0x28 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x29 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2A => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x2B => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2C => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2D => { + let open_book = OpenBook::decode(reader)?; + + Ok(Self::OpenBook(open_book)) + } + 0x2F => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x30 => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x31 => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x32 => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x33 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x35 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x36 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x37 => Ok(Self::EntityDestroy), + 0x38 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x39 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x3A => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x3B => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3D => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3E => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3F => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x40 => { + let update_view_position = UpdateViewPosition::decode(reader)?; + + Ok(Self::UpdateViewPosition(update_view_position)) + } + 0x41 => { + let update_view_distance = UpdateViewDistance::decode(reader)?; + + Ok(Self::UpdateViewDistance(update_view_distance)) + } + 0x42 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x43 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x44 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x45 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x46 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x47 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x48 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x49 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x4A => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x4B => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x4C => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x4D => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4E => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x4F => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x50 => { + let entity_sound_effect = EntitySoundEffect::decode(reader)?; + + Ok(Self::EntitySoundEffect(entity_sound_effect)) + } + 0x52 => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x51 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x53 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x55 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x56 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x58 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x59 => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3C => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x5A => Ok(Self::DeclareRecipes), + 0x5B => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8, difficulty_locked: bool) -> Self { + let difficulty = Difficulty { + difficulty, + difficulty_locked, + }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window(window_id: i32, inventory_type: i32, window_title: String) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn open_horse_window(window_id: u8, nb_slots: i32, entity_id: i32) -> Self { + let open_horse_window = OpenHorseWindow { + window_id, + nb_slots, + entity_id, + }; + + Self::OpenHorseWindow(open_horse_window) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk( + x: i32, + z: i32, + ground_up: bool, + bit_map: i32, + heightmaps: CompoundTag, + chunk_data: Vec, + ) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + heightmaps, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn update_light( + chunk_x: i32, + chunk_z: i32, + sky_light_mask: i32, + block_light_mask: i32, + empty_sky_light_mask: i32, + empty_block_light_mask: i32, + data: Vec, + ) -> Self { + let update_light = UpdateLight { + chunk_x, + chunk_z, + sky_light_mask, + block_light_mask, + empty_sky_light_mask, + empty_block_light_mask, + data, + }; + + Self::UpdateLight(update_light) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + max_players: u8, + level_type: String, + view_distance: i32, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + max_players, + level_type, + view_distance, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map( + item_damage: i32, + scale: i8, + tracking_position: bool, + locked: bool, + columns: i8, + ) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + locked, + columns, + }; + + Self::Map(map) + } + + pub fn trade_list( + window_id: i32, + villager_level: i32, + experience: i32, + is_regular_villager: bool, + ) -> Self { + let trade_list = TradeList { + window_id, + villager_level, + experience, + is_regular_villager, + }; + + Self::TradeList(trade_list) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_book(hand: i32) -> Self { + let open_book = OpenBook { hand }; + + Self::OpenBook(open_book) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn update_view_position(chunk_x: i32, chunk_z: i32) -> Self { + let update_view_position = UpdateViewPosition { chunk_x, chunk_z }; + + Self::UpdateViewPosition(update_view_position) + } + + pub fn update_view_distance(view_distance: i32) -> Self { + let update_view_distance = UpdateViewDistance { view_distance }; + + Self::UpdateViewDistance(update_view_distance) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn entity_sound_effect( + sound_id: i32, + sound_category: i32, + entity_id: i32, + volume: f32, + pitch: f32, + ) -> Self { + let entity_sound_effect = EntitySoundEffect { + sound_id, + sound_category, + entity_id, + volume, + pitch, + }; + + Self::EntitySoundEffect(entity_sound_effect) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags( + block_tags: TagsMap, + item_tags: TagsMap, + fluid_tags: TagsMap, + entity_tags: TagsMap, + ) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + entity_tags, + }; + + Self::Tags(tags) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct SetDifficulty { + pub new_difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct LockDifficulty { + pub locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateJigsawBlock { + pub location: Position, + pub attachment_type: String, + pub target_pool: String, + pub final_state: String, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + #[packet(with = "var_int")] + pub hand: i32, + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, + pub inside_block: bool, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, + pub difficulty_locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub inventory_type: i32, + pub window_title: String, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenHorseWindow { + pub window_id: u8, + #[packet(with = "var_int")] + pub nb_slots: i32, + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub heightmaps: CompoundTag, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct UpdateLight { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, + #[packet(with = "var_int")] + pub sky_light_mask: i32, + #[packet(with = "var_int")] + pub block_light_mask: i32, + #[packet(with = "var_int")] + pub empty_sky_light_mask: i32, + #[packet(with = "var_int")] + pub empty_block_light_mask: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub max_players: u8, + pub level_type: String, + #[packet(with = "var_int")] + pub view_distance: i32, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub locked: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct TradeList { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub villager_level: i32, + #[packet(with = "var_int")] + pub experience: i32, + pub is_regular_villager: bool, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenBook { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewPosition { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewDistance { + #[packet(with = "var_int")] + pub view_distance: i32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct EntitySoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + #[packet(with = "var_int")] + pub entity_id: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, + pub entity_tags: TagsMap, +} diff --git a/protocol/src/version/v_1_14/handshake.rs b/protocol/src/version/v_1_14/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_14/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_14/login.rs b/protocol/src/version/v_1_14/login.rs new file mode 100644 index 0000000..fcbf5cc --- /dev/null +++ b/protocol/src/version/v_1_14/login.rs @@ -0,0 +1,209 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_14/mod.rs b/protocol/src/version/v_1_14/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_14/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_14/status.rs b/protocol/src/version/v_1_14/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_14/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_14_1/game.rs b/protocol/src/version/v_1_14_1/game.rs new file mode 100644 index 0000000..ed76c79 --- /dev/null +++ b/protocol/src/version/v_1_14_1/game.rs @@ -0,0 +1,3535 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + SetDifficulty(SetDifficulty), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + LockDifficulty(LockDifficulty), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateJigsawBlock(UpdateJigsawBlock), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::SetDifficulty(_) => 0x02, + Self::EditBook(_) => 0x0C, + Self::QueryEntityNbt(_) => 0x0D, + Self::PickItem(_) => 0x17, + Self::NameItem(_) => 0x1E, + Self::SelectTrade(_) => 0x21, + Self::SetBeaconEffect(_) => 0x22, + Self::UpdateCommandBlock(_) => 0x24, + Self::UpdateCommandBlockMinecart(_) => 0x25, + Self::UpdateStructureBlock(_) => 0x28, + Self::ServerBoundTabComplete(_) => 0x06, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x07, + Self::EnchantItem(_) => 0x08, + Self::WindowClick(_) => 0x09, + Self::ServerBoundCloseWindow(_) => 0x0A, + Self::ServerBoundCustomPayload(_) => 0x0B, + Self::UseEntity(_) => 0x0E, + Self::ServerBoundKeepAlive(_) => 0x0F, + Self::LockDifficulty(_) => 0x10, + Self::ServerBoundPosition(_) => 0x11, + Self::PositionLook(_) => 0x12, + Self::Look(_) => 0x13, + Self::Flying(_) => 0x14, + Self::ServerBoundVehicleMove(_) => 0x15, + Self::SteerBoat(_) => 0x16, + Self::CraftRecipeRequest(_) => 0x18, + Self::ServerBoundAbilities(_) => 0x19, + Self::BlockDig(_) => 0x1A, + Self::EntityAction(_) => 0x1B, + Self::SteerVehicle(_) => 0x1C, + Self::CraftingBookData(_) => 0x1D, + Self::ResourcePackReceive(_) => 0x1F, + Self::ServerBoundHeldItemSlot(_) => 0x23, + Self::SetCreativeSlot(_) => 0x26, + Self::UpdateJigsawBlock(_) => 0x27, + Self::UpdateSign(_) => 0x29, + Self::ArmAnimation(_) => 0x2A, + Self::Spectate(_) => 0x2B, + Self::BlockPlace(_) => 0x2C, + Self::UseItem(_) => 0x2D, + Self::AdvancementTab(_) => 0x20, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x02 => { + let set_difficulty = SetDifficulty::decode(reader)?; + + Ok(Self::SetDifficulty(set_difficulty)) + } + 0x0C => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0D => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x17 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1E => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x21 => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x22 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x24 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x25 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x28 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x06 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x07 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x08 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x09 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x0A => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0B => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0E => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0F => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x10 => { + let lock_difficulty = LockDifficulty::decode(reader)?; + + Ok(Self::LockDifficulty(lock_difficulty)) + } + 0x11 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x12 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x13 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x14 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x15 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x16 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x18 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x19 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x1A => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x1B => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1C => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1D => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x1F => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x23 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x26 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x27 => { + let update_jigsaw_block = UpdateJigsawBlock::decode(reader)?; + + Ok(Self::UpdateJigsawBlock(update_jigsaw_block)) + } + 0x29 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x2A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x2B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x2C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x20 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn set_difficulty(new_difficulty: u8) -> Self { + let set_difficulty = SetDifficulty { new_difficulty }; + + Self::SetDifficulty(set_difficulty) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn lock_difficulty(locked: bool) -> Self { + let lock_difficulty = LockDifficulty { locked }; + + Self::LockDifficulty(lock_difficulty) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_jigsaw_block( + location: Position, + attachment_type: String, + target_pool: String, + final_state: String, + ) -> Self { + let update_jigsaw_block = UpdateJigsawBlock { + location, + attachment_type, + target_pool, + final_state, + }; + + Self::UpdateJigsawBlock(update_jigsaw_block) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + hand: i32, + location: Position, + direction: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + inside_block: bool, + ) -> Self { + let block_place = BlockPlace { + hand, + location, + direction, + cursor_x, + cursor_y, + cursor_z, + inside_block, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + OpenHorseWindow(OpenHorseWindow), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + UpdateLight(UpdateLight), + JoinGame(JoinGame), + Map(Map), + TradeList(TradeList), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenBook(OpenBook), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + UpdateViewPosition(UpdateViewPosition), + UpdateViewDistance(UpdateViewDistance), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + EntitySoundEffect(EntitySoundEffect), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x57, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete(_) => 0x10, + Self::DeclareCommands(_) => 0x11, + Self::FacePlayer(_) => 0x34, + Self::NbtQueryResponse(_) => 0x54, + Self::ClientBoundChat(_) => 0x0E, + Self::MultiBlockChange(_) => 0x0F, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x2E, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::OpenHorseWindow(_) => 0x1F, + Self::ClientBoundKeepAlive(_) => 0x20, + Self::MapChunk(_) => 0x21, + Self::WorldEvent(_) => 0x22, + Self::WorldParticles(_) => 0x23, + Self::UpdateLight(_) => 0x24, + Self::JoinGame(_) => 0x25, + Self::Map(_) => 0x26, + Self::TradeList(_) => 0x27, + Self::RelEntityMove(_) => 0x28, + Self::EntityMoveLook(_) => 0x29, + Self::EntityLook(_) => 0x2A, + Self::Entity(_) => 0x2B, + Self::ClientBoundVehicleMove(_) => 0x2C, + Self::OpenBook(_) => 0x2D, + Self::OpenSignEntity(_) => 0x2F, + Self::CraftRecipeResponse(_) => 0x30, + Self::ClientBoundAbilities(_) => 0x31, + Self::CombatEvent(_) => 0x32, + Self::PlayerInfo(_) => 0x33, + Self::ClientBoundPosition(_) => 0x35, + Self::UnlockRecipes(_) => 0x36, + Self::EntityDestroy => 0x37, + Self::RemoveEntityEffect(_) => 0x38, + Self::ResourcePackSend(_) => 0x39, + Self::Respawn(_) => 0x3A, + Self::EntityHeadRotation(_) => 0x3B, + Self::WorldBorder(_) => 0x3D, + Self::Camera(_) => 0x3E, + Self::ClientBoundHeldItemSlot(_) => 0x3F, + Self::UpdateViewPosition(_) => 0x40, + Self::UpdateViewDistance(_) => 0x41, + Self::ScoreboardDisplayObjective(_) => 0x42, + Self::EntityMetadata(_) => 0x43, + Self::AttachEntity(_) => 0x44, + Self::EntityVelocity(_) => 0x45, + Self::EntityEquipment(_) => 0x46, + Self::Experience(_) => 0x47, + Self::UpdateHealth(_) => 0x48, + Self::ScoreboardObjective(_) => 0x49, + Self::SetPassengers(_) => 0x4A, + Self::Teams(_) => 0x4B, + Self::ScoreboardScore(_) => 0x4C, + Self::SpawnPosition(_) => 0x4D, + Self::UpdateTime(_) => 0x4E, + Self::Title(_) => 0x4F, + Self::EntitySoundEffect(_) => 0x50, + Self::StopSound(_) => 0x52, + Self::SoundEffect(_) => 0x51, + Self::PlayerlistHeader(_) => 0x53, + Self::Collect(_) => 0x55, + Self::EntityTeleport(_) => 0x56, + Self::EntityUpdateAttributes(_) => 0x58, + Self::EntityEffect(_) => 0x59, + Self::SelectAdvancementTab(_) => 0x3C, + Self::DeclareRecipes => 0x5A, + Self::Tags(_) => 0x5B, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x57 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x10 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x11 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x34 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x54 => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0E => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x0F => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x2E => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let open_horse_window = OpenHorseWindow::decode(reader)?; + + Ok(Self::OpenHorseWindow(open_horse_window)) + } + 0x20 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x21 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x22 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x23 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x24 => { + let update_light = UpdateLight::decode(reader)?; + + Ok(Self::UpdateLight(update_light)) + } + 0x25 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x26 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x27 => { + let trade_list = TradeList::decode(reader)?; + + Ok(Self::TradeList(trade_list)) + } + 0x28 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x29 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2A => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x2B => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2C => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2D => { + let open_book = OpenBook::decode(reader)?; + + Ok(Self::OpenBook(open_book)) + } + 0x2F => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x30 => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x31 => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x32 => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x33 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x35 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x36 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x37 => Ok(Self::EntityDestroy), + 0x38 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x39 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x3A => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x3B => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3D => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3E => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3F => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x40 => { + let update_view_position = UpdateViewPosition::decode(reader)?; + + Ok(Self::UpdateViewPosition(update_view_position)) + } + 0x41 => { + let update_view_distance = UpdateViewDistance::decode(reader)?; + + Ok(Self::UpdateViewDistance(update_view_distance)) + } + 0x42 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x43 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x44 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x45 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x46 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x47 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x48 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x49 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x4A => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x4B => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x4C => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x4D => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4E => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x4F => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x50 => { + let entity_sound_effect = EntitySoundEffect::decode(reader)?; + + Ok(Self::EntitySoundEffect(entity_sound_effect)) + } + 0x52 => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x51 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x53 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x55 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x56 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x58 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x59 => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3C => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x5A => Ok(Self::DeclareRecipes), + 0x5B => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8, difficulty_locked: bool) -> Self { + let difficulty = Difficulty { + difficulty, + difficulty_locked, + }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window(window_id: i32, inventory_type: i32, window_title: String) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn open_horse_window(window_id: u8, nb_slots: i32, entity_id: i32) -> Self { + let open_horse_window = OpenHorseWindow { + window_id, + nb_slots, + entity_id, + }; + + Self::OpenHorseWindow(open_horse_window) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk( + x: i32, + z: i32, + ground_up: bool, + bit_map: i32, + heightmaps: CompoundTag, + chunk_data: Vec, + ) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + heightmaps, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn update_light( + chunk_x: i32, + chunk_z: i32, + sky_light_mask: i32, + block_light_mask: i32, + empty_sky_light_mask: i32, + empty_block_light_mask: i32, + data: Vec, + ) -> Self { + let update_light = UpdateLight { + chunk_x, + chunk_z, + sky_light_mask, + block_light_mask, + empty_sky_light_mask, + empty_block_light_mask, + data, + }; + + Self::UpdateLight(update_light) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + max_players: u8, + level_type: String, + view_distance: i32, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + max_players, + level_type, + view_distance, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map( + item_damage: i32, + scale: i8, + tracking_position: bool, + locked: bool, + columns: i8, + ) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + locked, + columns, + }; + + Self::Map(map) + } + + pub fn trade_list( + window_id: i32, + villager_level: i32, + experience: i32, + is_regular_villager: bool, + ) -> Self { + let trade_list = TradeList { + window_id, + villager_level, + experience, + is_regular_villager, + }; + + Self::TradeList(trade_list) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_book(hand: i32) -> Self { + let open_book = OpenBook { hand }; + + Self::OpenBook(open_book) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn update_view_position(chunk_x: i32, chunk_z: i32) -> Self { + let update_view_position = UpdateViewPosition { chunk_x, chunk_z }; + + Self::UpdateViewPosition(update_view_position) + } + + pub fn update_view_distance(view_distance: i32) -> Self { + let update_view_distance = UpdateViewDistance { view_distance }; + + Self::UpdateViewDistance(update_view_distance) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn entity_sound_effect( + sound_id: i32, + sound_category: i32, + entity_id: i32, + volume: f32, + pitch: f32, + ) -> Self { + let entity_sound_effect = EntitySoundEffect { + sound_id, + sound_category, + entity_id, + volume, + pitch, + }; + + Self::EntitySoundEffect(entity_sound_effect) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags( + block_tags: TagsMap, + item_tags: TagsMap, + fluid_tags: TagsMap, + entity_tags: TagsMap, + ) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + entity_tags, + }; + + Self::Tags(tags) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct SetDifficulty { + pub new_difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct LockDifficulty { + pub locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateJigsawBlock { + pub location: Position, + pub attachment_type: String, + pub target_pool: String, + pub final_state: String, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + #[packet(with = "var_int")] + pub hand: i32, + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, + pub inside_block: bool, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, + pub difficulty_locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub inventory_type: i32, + pub window_title: String, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenHorseWindow { + pub window_id: u8, + #[packet(with = "var_int")] + pub nb_slots: i32, + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub heightmaps: CompoundTag, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct UpdateLight { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, + #[packet(with = "var_int")] + pub sky_light_mask: i32, + #[packet(with = "var_int")] + pub block_light_mask: i32, + #[packet(with = "var_int")] + pub empty_sky_light_mask: i32, + #[packet(with = "var_int")] + pub empty_block_light_mask: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub max_players: u8, + pub level_type: String, + #[packet(with = "var_int")] + pub view_distance: i32, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub locked: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct TradeList { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub villager_level: i32, + #[packet(with = "var_int")] + pub experience: i32, + pub is_regular_villager: bool, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenBook { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewPosition { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewDistance { + #[packet(with = "var_int")] + pub view_distance: i32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct EntitySoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + #[packet(with = "var_int")] + pub entity_id: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, + pub entity_tags: TagsMap, +} diff --git a/protocol/src/version/v_1_14_1/handshake.rs b/protocol/src/version/v_1_14_1/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_14_1/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_14_1/login.rs b/protocol/src/version/v_1_14_1/login.rs new file mode 100644 index 0000000..fcbf5cc --- /dev/null +++ b/protocol/src/version/v_1_14_1/login.rs @@ -0,0 +1,209 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_14_1/mod.rs b/protocol/src/version/v_1_14_1/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_14_1/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_14_1/status.rs b/protocol/src/version/v_1_14_1/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_14_1/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_14_3/game.rs b/protocol/src/version/v_1_14_3/game.rs new file mode 100644 index 0000000..1901a5a --- /dev/null +++ b/protocol/src/version/v_1_14_3/game.rs @@ -0,0 +1,3538 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + SetDifficulty(SetDifficulty), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + LockDifficulty(LockDifficulty), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateJigsawBlock(UpdateJigsawBlock), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::SetDifficulty(_) => 0x02, + Self::EditBook(_) => 0x0C, + Self::QueryEntityNbt(_) => 0x0D, + Self::PickItem(_) => 0x17, + Self::NameItem(_) => 0x1E, + Self::SelectTrade(_) => 0x21, + Self::SetBeaconEffect(_) => 0x22, + Self::UpdateCommandBlock(_) => 0x24, + Self::UpdateCommandBlockMinecart(_) => 0x25, + Self::UpdateStructureBlock(_) => 0x28, + Self::ServerBoundTabComplete(_) => 0x06, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x07, + Self::EnchantItem(_) => 0x08, + Self::WindowClick(_) => 0x09, + Self::ServerBoundCloseWindow(_) => 0x0A, + Self::ServerBoundCustomPayload(_) => 0x0B, + Self::UseEntity(_) => 0x0E, + Self::ServerBoundKeepAlive(_) => 0x0F, + Self::LockDifficulty(_) => 0x10, + Self::ServerBoundPosition(_) => 0x11, + Self::PositionLook(_) => 0x12, + Self::Look(_) => 0x13, + Self::Flying(_) => 0x14, + Self::ServerBoundVehicleMove(_) => 0x15, + Self::SteerBoat(_) => 0x16, + Self::CraftRecipeRequest(_) => 0x18, + Self::ServerBoundAbilities(_) => 0x19, + Self::BlockDig(_) => 0x1A, + Self::EntityAction(_) => 0x1B, + Self::SteerVehicle(_) => 0x1C, + Self::CraftingBookData(_) => 0x1D, + Self::ResourcePackReceive(_) => 0x1F, + Self::ServerBoundHeldItemSlot(_) => 0x23, + Self::SetCreativeSlot(_) => 0x26, + Self::UpdateJigsawBlock(_) => 0x27, + Self::UpdateSign(_) => 0x29, + Self::ArmAnimation(_) => 0x2A, + Self::Spectate(_) => 0x2B, + Self::BlockPlace(_) => 0x2C, + Self::UseItem(_) => 0x2D, + Self::AdvancementTab(_) => 0x20, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x02 => { + let set_difficulty = SetDifficulty::decode(reader)?; + + Ok(Self::SetDifficulty(set_difficulty)) + } + 0x0C => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0D => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x17 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1E => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x21 => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x22 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x24 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x25 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x28 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x06 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x07 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x08 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x09 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x0A => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0B => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0E => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0F => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x10 => { + let lock_difficulty = LockDifficulty::decode(reader)?; + + Ok(Self::LockDifficulty(lock_difficulty)) + } + 0x11 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x12 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x13 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x14 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x15 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x16 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x18 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x19 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x1A => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x1B => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1C => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1D => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x1F => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x23 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x26 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x27 => { + let update_jigsaw_block = UpdateJigsawBlock::decode(reader)?; + + Ok(Self::UpdateJigsawBlock(update_jigsaw_block)) + } + 0x29 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x2A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x2B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x2C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x20 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn set_difficulty(new_difficulty: u8) -> Self { + let set_difficulty = SetDifficulty { new_difficulty }; + + Self::SetDifficulty(set_difficulty) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn lock_difficulty(locked: bool) -> Self { + let lock_difficulty = LockDifficulty { locked }; + + Self::LockDifficulty(lock_difficulty) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_jigsaw_block( + location: Position, + attachment_type: String, + target_pool: String, + final_state: String, + ) -> Self { + let update_jigsaw_block = UpdateJigsawBlock { + location, + attachment_type, + target_pool, + final_state, + }; + + Self::UpdateJigsawBlock(update_jigsaw_block) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + hand: i32, + location: Position, + direction: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + inside_block: bool, + ) -> Self { + let block_place = BlockPlace { + hand, + location, + direction, + cursor_x, + cursor_y, + cursor_z, + inside_block, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + OpenHorseWindow(OpenHorseWindow), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + UpdateLight(UpdateLight), + JoinGame(JoinGame), + Map(Map), + TradeList(TradeList), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenBook(OpenBook), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + UpdateViewPosition(UpdateViewPosition), + UpdateViewDistance(UpdateViewDistance), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + EntitySoundEffect(EntitySoundEffect), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x57, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete(_) => 0x10, + Self::DeclareCommands(_) => 0x11, + Self::FacePlayer(_) => 0x34, + Self::NbtQueryResponse(_) => 0x54, + Self::ClientBoundChat(_) => 0x0E, + Self::MultiBlockChange(_) => 0x0F, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x2E, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::OpenHorseWindow(_) => 0x1F, + Self::ClientBoundKeepAlive(_) => 0x20, + Self::MapChunk(_) => 0x21, + Self::WorldEvent(_) => 0x22, + Self::WorldParticles(_) => 0x23, + Self::UpdateLight(_) => 0x24, + Self::JoinGame(_) => 0x25, + Self::Map(_) => 0x26, + Self::TradeList(_) => 0x27, + Self::RelEntityMove(_) => 0x28, + Self::EntityMoveLook(_) => 0x29, + Self::EntityLook(_) => 0x2A, + Self::Entity(_) => 0x2B, + Self::ClientBoundVehicleMove(_) => 0x2C, + Self::OpenBook(_) => 0x2D, + Self::OpenSignEntity(_) => 0x2F, + Self::CraftRecipeResponse(_) => 0x30, + Self::ClientBoundAbilities(_) => 0x31, + Self::CombatEvent(_) => 0x32, + Self::PlayerInfo(_) => 0x33, + Self::ClientBoundPosition(_) => 0x35, + Self::UnlockRecipes(_) => 0x36, + Self::EntityDestroy => 0x37, + Self::RemoveEntityEffect(_) => 0x38, + Self::ResourcePackSend(_) => 0x39, + Self::Respawn(_) => 0x3A, + Self::EntityHeadRotation(_) => 0x3B, + Self::WorldBorder(_) => 0x3D, + Self::Camera(_) => 0x3E, + Self::ClientBoundHeldItemSlot(_) => 0x3F, + Self::UpdateViewPosition(_) => 0x40, + Self::UpdateViewDistance(_) => 0x41, + Self::ScoreboardDisplayObjective(_) => 0x42, + Self::EntityMetadata(_) => 0x43, + Self::AttachEntity(_) => 0x44, + Self::EntityVelocity(_) => 0x45, + Self::EntityEquipment(_) => 0x46, + Self::Experience(_) => 0x47, + Self::UpdateHealth(_) => 0x48, + Self::ScoreboardObjective(_) => 0x49, + Self::SetPassengers(_) => 0x4A, + Self::Teams(_) => 0x4B, + Self::ScoreboardScore(_) => 0x4C, + Self::SpawnPosition(_) => 0x4D, + Self::UpdateTime(_) => 0x4E, + Self::Title(_) => 0x4F, + Self::EntitySoundEffect(_) => 0x50, + Self::StopSound(_) => 0x52, + Self::SoundEffect(_) => 0x51, + Self::PlayerlistHeader(_) => 0x53, + Self::Collect(_) => 0x55, + Self::EntityTeleport(_) => 0x56, + Self::EntityUpdateAttributes(_) => 0x58, + Self::EntityEffect(_) => 0x59, + Self::SelectAdvancementTab(_) => 0x3C, + Self::DeclareRecipes => 0x5A, + Self::Tags(_) => 0x5B, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x57 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x10 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x11 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x34 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x54 => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0E => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x0F => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x2E => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let open_horse_window = OpenHorseWindow::decode(reader)?; + + Ok(Self::OpenHorseWindow(open_horse_window)) + } + 0x20 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x21 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x22 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x23 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x24 => { + let update_light = UpdateLight::decode(reader)?; + + Ok(Self::UpdateLight(update_light)) + } + 0x25 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x26 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x27 => { + let trade_list = TradeList::decode(reader)?; + + Ok(Self::TradeList(trade_list)) + } + 0x28 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x29 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2A => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x2B => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2C => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2D => { + let open_book = OpenBook::decode(reader)?; + + Ok(Self::OpenBook(open_book)) + } + 0x2F => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x30 => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x31 => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x32 => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x33 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x35 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x36 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x37 => Ok(Self::EntityDestroy), + 0x38 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x39 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x3A => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x3B => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3D => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3E => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3F => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x40 => { + let update_view_position = UpdateViewPosition::decode(reader)?; + + Ok(Self::UpdateViewPosition(update_view_position)) + } + 0x41 => { + let update_view_distance = UpdateViewDistance::decode(reader)?; + + Ok(Self::UpdateViewDistance(update_view_distance)) + } + 0x42 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x43 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x44 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x45 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x46 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x47 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x48 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x49 => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x4A => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x4B => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x4C => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x4D => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4E => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x4F => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x50 => { + let entity_sound_effect = EntitySoundEffect::decode(reader)?; + + Ok(Self::EntitySoundEffect(entity_sound_effect)) + } + 0x52 => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x51 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x53 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x55 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x56 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x58 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x59 => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3C => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x5A => Ok(Self::DeclareRecipes), + 0x5B => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8, difficulty_locked: bool) -> Self { + let difficulty = Difficulty { + difficulty, + difficulty_locked, + }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window(window_id: i32, inventory_type: i32, window_title: String) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn open_horse_window(window_id: u8, nb_slots: i32, entity_id: i32) -> Self { + let open_horse_window = OpenHorseWindow { + window_id, + nb_slots, + entity_id, + }; + + Self::OpenHorseWindow(open_horse_window) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk( + x: i32, + z: i32, + ground_up: bool, + bit_map: i32, + heightmaps: CompoundTag, + chunk_data: Vec, + ) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + heightmaps, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn update_light( + chunk_x: i32, + chunk_z: i32, + sky_light_mask: i32, + block_light_mask: i32, + empty_sky_light_mask: i32, + empty_block_light_mask: i32, + data: Vec, + ) -> Self { + let update_light = UpdateLight { + chunk_x, + chunk_z, + sky_light_mask, + block_light_mask, + empty_sky_light_mask, + empty_block_light_mask, + data, + }; + + Self::UpdateLight(update_light) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + max_players: u8, + level_type: String, + view_distance: i32, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + max_players, + level_type, + view_distance, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map( + item_damage: i32, + scale: i8, + tracking_position: bool, + locked: bool, + columns: i8, + ) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + locked, + columns, + }; + + Self::Map(map) + } + + pub fn trade_list( + window_id: i32, + villager_level: i32, + experience: i32, + is_regular_villager: bool, + can_restock: bool, + ) -> Self { + let trade_list = TradeList { + window_id, + villager_level, + experience, + is_regular_villager, + can_restock, + }; + + Self::TradeList(trade_list) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_book(hand: i32) -> Self { + let open_book = OpenBook { hand }; + + Self::OpenBook(open_book) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn update_view_position(chunk_x: i32, chunk_z: i32) -> Self { + let update_view_position = UpdateViewPosition { chunk_x, chunk_z }; + + Self::UpdateViewPosition(update_view_position) + } + + pub fn update_view_distance(view_distance: i32) -> Self { + let update_view_distance = UpdateViewDistance { view_distance }; + + Self::UpdateViewDistance(update_view_distance) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn entity_sound_effect( + sound_id: i32, + sound_category: i32, + entity_id: i32, + volume: f32, + pitch: f32, + ) -> Self { + let entity_sound_effect = EntitySoundEffect { + sound_id, + sound_category, + entity_id, + volume, + pitch, + }; + + Self::EntitySoundEffect(entity_sound_effect) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags( + block_tags: TagsMap, + item_tags: TagsMap, + fluid_tags: TagsMap, + entity_tags: TagsMap, + ) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + entity_tags, + }; + + Self::Tags(tags) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct SetDifficulty { + pub new_difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct LockDifficulty { + pub locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateJigsawBlock { + pub location: Position, + pub attachment_type: String, + pub target_pool: String, + pub final_state: String, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + #[packet(with = "var_int")] + pub hand: i32, + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, + pub inside_block: bool, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, + pub difficulty_locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub inventory_type: i32, + pub window_title: String, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenHorseWindow { + pub window_id: u8, + #[packet(with = "var_int")] + pub nb_slots: i32, + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub heightmaps: CompoundTag, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct UpdateLight { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, + #[packet(with = "var_int")] + pub sky_light_mask: i32, + #[packet(with = "var_int")] + pub block_light_mask: i32, + #[packet(with = "var_int")] + pub empty_sky_light_mask: i32, + #[packet(with = "var_int")] + pub empty_block_light_mask: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub max_players: u8, + pub level_type: String, + #[packet(with = "var_int")] + pub view_distance: i32, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub locked: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct TradeList { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub villager_level: i32, + #[packet(with = "var_int")] + pub experience: i32, + pub is_regular_villager: bool, + pub can_restock: bool, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenBook { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewPosition { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewDistance { + #[packet(with = "var_int")] + pub view_distance: i32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct EntitySoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + #[packet(with = "var_int")] + pub entity_id: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, + pub entity_tags: TagsMap, +} diff --git a/protocol/src/version/v_1_14_3/handshake.rs b/protocol/src/version/v_1_14_3/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_14_3/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_14_3/login.rs b/protocol/src/version/v_1_14_3/login.rs new file mode 100644 index 0000000..fcbf5cc --- /dev/null +++ b/protocol/src/version/v_1_14_3/login.rs @@ -0,0 +1,209 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_14_3/mod.rs b/protocol/src/version/v_1_14_3/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_14_3/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_14_3/status.rs b/protocol/src/version/v_1_14_3/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_14_3/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/packet/game.rs b/protocol/src/version/v_1_14_4/game.rs similarity index 99% rename from protocol/src/packet/game.rs rename to protocol/src/version/v_1_14_4/game.rs index cb6dc25..2d4d90e 100644 --- a/protocol/src/packet/game.rs +++ b/protocol/src/version/v_1_14_4/game.rs @@ -1,15 +1,15 @@ // This file is automatically generated. // It is not intended for manual editing. -use crate::data::chat::Message; -use crate::data::game::*; use crate::DecodeError; use crate::Decoder; use minecraft_protocol_derive::Packet; -use nbt::CompoundTag; use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; use uuid::Uuid; -pub enum GameServerBoundPacket { +pub enum ServerBoundGamePacket { TeleportConfirm(TeleportConfirm), QueryBlockNbt(QueryBlockNbt), SetDifficulty(SetDifficulty), @@ -58,7 +58,7 @@ pub enum GameServerBoundPacket { AdvancementTab(AdvancementTab), } -impl GameServerBoundPacket { +impl ServerBoundGamePacket { pub fn get_type_id(&self) -> u8 { match self { Self::TeleportConfirm(_) => 0x00, @@ -801,7 +801,7 @@ impl GameServerBoundPacket { } } -pub enum GameClientBoundPacket { +pub enum ClientBoundGamePacket { SpawnEntity(SpawnEntity), SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), SpawnEntityWeather(SpawnEntityWeather), @@ -897,7 +897,7 @@ pub enum GameClientBoundPacket { AcknowledgePlayerDigging(AcknowledgePlayerDigging), } -impl GameClientBoundPacket { +impl ClientBoundGamePacket { pub fn get_type_id(&self) -> u8 { match self { Self::SpawnEntity(_) => 0x00, @@ -1700,7 +1700,7 @@ impl GameClientBoundPacket { Self::NbtQueryResponse(nbt_query_response) } - pub fn client_bound_chat(message: Message, position: MessagePosition) -> Self { + pub fn client_bound_chat(message: String, position: i8) -> Self { let client_bound_chat = ClientBoundChat { message, position }; Self::ClientBoundChat(client_bound_chat) @@ -3004,8 +3004,8 @@ pub struct NbtQueryResponse { #[derive(Packet, Debug)] pub struct ClientBoundChat { - pub message: Message, - pub position: MessagePosition, + pub message: String, + pub position: i8, } #[derive(Packet, Debug)] diff --git a/protocol/src/version/v_1_14_4/handshake.rs b/protocol/src/version/v_1_14_4/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_14_4/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_14_4/login.rs b/protocol/src/version/v_1_14_4/login.rs new file mode 100644 index 0000000..fcbf5cc --- /dev/null +++ b/protocol/src/version/v_1_14_4/login.rs @@ -0,0 +1,209 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_14_4/mod.rs b/protocol/src/version/v_1_14_4/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_14_4/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_14_4/status.rs b/protocol/src/version/v_1_14_4/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_14_4/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_15/game.rs b/protocol/src/version/v_1_15/game.rs new file mode 100644 index 0000000..3b27cf6 --- /dev/null +++ b/protocol/src/version/v_1_15/game.rs @@ -0,0 +1,3573 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + SetDifficulty(SetDifficulty), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + LockDifficulty(LockDifficulty), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateJigsawBlock(UpdateJigsawBlock), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::SetDifficulty(_) => 0x02, + Self::EditBook(_) => 0x0C, + Self::QueryEntityNbt(_) => 0x0D, + Self::PickItem(_) => 0x17, + Self::NameItem(_) => 0x1E, + Self::SelectTrade(_) => 0x21, + Self::SetBeaconEffect(_) => 0x22, + Self::UpdateCommandBlock(_) => 0x24, + Self::UpdateCommandBlockMinecart(_) => 0x25, + Self::UpdateStructureBlock(_) => 0x28, + Self::ServerBoundTabComplete(_) => 0x06, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x07, + Self::EnchantItem(_) => 0x08, + Self::WindowClick(_) => 0x09, + Self::ServerBoundCloseWindow(_) => 0x0A, + Self::ServerBoundCustomPayload(_) => 0x0B, + Self::UseEntity(_) => 0x0E, + Self::ServerBoundKeepAlive(_) => 0x0F, + Self::LockDifficulty(_) => 0x10, + Self::ServerBoundPosition(_) => 0x11, + Self::PositionLook(_) => 0x12, + Self::Look(_) => 0x13, + Self::Flying(_) => 0x14, + Self::ServerBoundVehicleMove(_) => 0x15, + Self::SteerBoat(_) => 0x16, + Self::CraftRecipeRequest(_) => 0x18, + Self::ServerBoundAbilities(_) => 0x19, + Self::BlockDig(_) => 0x1A, + Self::EntityAction(_) => 0x1B, + Self::SteerVehicle(_) => 0x1C, + Self::CraftingBookData(_) => 0x1D, + Self::ResourcePackReceive(_) => 0x1F, + Self::ServerBoundHeldItemSlot(_) => 0x23, + Self::SetCreativeSlot(_) => 0x26, + Self::UpdateJigsawBlock(_) => 0x27, + Self::UpdateSign(_) => 0x29, + Self::ArmAnimation(_) => 0x2A, + Self::Spectate(_) => 0x2B, + Self::BlockPlace(_) => 0x2C, + Self::UseItem(_) => 0x2D, + Self::AdvancementTab(_) => 0x20, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x02 => { + let set_difficulty = SetDifficulty::decode(reader)?; + + Ok(Self::SetDifficulty(set_difficulty)) + } + 0x0C => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0D => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x17 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1E => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x21 => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x22 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x24 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x25 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x28 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x06 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x07 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x08 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x09 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x0A => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0B => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0E => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0F => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x10 => { + let lock_difficulty = LockDifficulty::decode(reader)?; + + Ok(Self::LockDifficulty(lock_difficulty)) + } + 0x11 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x12 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x13 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x14 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x15 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x16 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x18 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x19 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x1A => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x1B => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1C => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1D => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x1F => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x23 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x26 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x27 => { + let update_jigsaw_block = UpdateJigsawBlock::decode(reader)?; + + Ok(Self::UpdateJigsawBlock(update_jigsaw_block)) + } + 0x29 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x2A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x2B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x2C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x20 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn set_difficulty(new_difficulty: u8) -> Self { + let set_difficulty = SetDifficulty { new_difficulty }; + + Self::SetDifficulty(set_difficulty) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn lock_difficulty(locked: bool) -> Self { + let lock_difficulty = LockDifficulty { locked }; + + Self::LockDifficulty(lock_difficulty) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_jigsaw_block( + location: Position, + attachment_type: String, + target_pool: String, + final_state: String, + ) -> Self { + let update_jigsaw_block = UpdateJigsawBlock { + location, + attachment_type, + target_pool, + final_state, + }; + + Self::UpdateJigsawBlock(update_jigsaw_block) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + hand: i32, + location: Position, + direction: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + inside_block: bool, + ) -> Self { + let block_place = BlockPlace { + hand, + location, + direction, + cursor_x, + cursor_y, + cursor_z, + inside_block, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + OpenHorseWindow(OpenHorseWindow), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + UpdateLight(UpdateLight), + JoinGame(JoinGame), + Map(Map), + TradeList(TradeList), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenBook(OpenBook), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + UpdateViewPosition(UpdateViewPosition), + UpdateViewDistance(UpdateViewDistance), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + EntitySoundEffect(EntitySoundEffect), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), + AcknowledgePlayerDigging(AcknowledgePlayerDigging), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x58, + Self::BlockBreakAnimation(_) => 0x09, + Self::TileEntityData(_) => 0x0A, + Self::BlockAction(_) => 0x0B, + Self::BlockChange(_) => 0x0C, + Self::BossBar(_) => 0x0D, + Self::Difficulty(_) => 0x0E, + Self::ClientBoundTabComplete(_) => 0x11, + Self::DeclareCommands(_) => 0x12, + Self::FacePlayer(_) => 0x35, + Self::NbtQueryResponse(_) => 0x55, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x13, + Self::ClientBoundCloseWindow(_) => 0x14, + Self::OpenWindow(_) => 0x2F, + Self::WindowItems(_) => 0x15, + Self::CraftProgressBar(_) => 0x16, + Self::SetSlot(_) => 0x17, + Self::SetCooldown(_) => 0x18, + Self::ClientBoundCustomPayload(_) => 0x19, + Self::NamedSoundEffect(_) => 0x1A, + Self::KickDisconnect(_) => 0x1B, + Self::EntityStatus(_) => 0x1C, + Self::Explosion(_) => 0x1D, + Self::UnloadChunk(_) => 0x1E, + Self::GameStateChange(_) => 0x1F, + Self::OpenHorseWindow(_) => 0x20, + Self::ClientBoundKeepAlive(_) => 0x21, + Self::MapChunk(_) => 0x22, + Self::WorldEvent(_) => 0x23, + Self::WorldParticles(_) => 0x24, + Self::UpdateLight(_) => 0x25, + Self::JoinGame(_) => 0x26, + Self::Map(_) => 0x27, + Self::TradeList(_) => 0x28, + Self::RelEntityMove(_) => 0x29, + Self::EntityMoveLook(_) => 0x2A, + Self::EntityLook(_) => 0x2B, + Self::Entity(_) => 0x2C, + Self::ClientBoundVehicleMove(_) => 0x2D, + Self::OpenBook(_) => 0x2E, + Self::OpenSignEntity(_) => 0x30, + Self::CraftRecipeResponse(_) => 0x31, + Self::ClientBoundAbilities(_) => 0x32, + Self::CombatEvent(_) => 0x33, + Self::PlayerInfo(_) => 0x34, + Self::ClientBoundPosition(_) => 0x36, + Self::UnlockRecipes(_) => 0x37, + Self::EntityDestroy => 0x38, + Self::RemoveEntityEffect(_) => 0x39, + Self::ResourcePackSend(_) => 0x3A, + Self::Respawn(_) => 0x3B, + Self::EntityHeadRotation(_) => 0x3C, + Self::WorldBorder(_) => 0x3E, + Self::Camera(_) => 0x3F, + Self::ClientBoundHeldItemSlot(_) => 0x40, + Self::UpdateViewPosition(_) => 0x41, + Self::UpdateViewDistance(_) => 0x42, + Self::ScoreboardDisplayObjective(_) => 0x43, + Self::EntityMetadata(_) => 0x44, + Self::AttachEntity(_) => 0x45, + Self::EntityVelocity(_) => 0x46, + Self::EntityEquipment(_) => 0x47, + Self::Experience(_) => 0x48, + Self::UpdateHealth(_) => 0x49, + Self::ScoreboardObjective(_) => 0x4A, + Self::SetPassengers(_) => 0x4B, + Self::Teams(_) => 0x4C, + Self::ScoreboardScore(_) => 0x4D, + Self::SpawnPosition(_) => 0x4E, + Self::UpdateTime(_) => 0x4F, + Self::Title(_) => 0x50, + Self::EntitySoundEffect(_) => 0x51, + Self::StopSound(_) => 0x53, + Self::SoundEffect(_) => 0x52, + Self::PlayerlistHeader(_) => 0x54, + Self::Collect(_) => 0x56, + Self::EntityTeleport(_) => 0x57, + Self::EntityUpdateAttributes(_) => 0x59, + Self::EntityEffect(_) => 0x5A, + Self::SelectAdvancementTab(_) => 0x3D, + Self::DeclareRecipes => 0x5B, + Self::Tags(_) => 0x5C, + Self::AcknowledgePlayerDigging(_) => 0x08, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x58 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x09 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x0A => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0B => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0C => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0D => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0E => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x11 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x12 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x35 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x55 => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x13 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x14 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x2F => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x15 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x16 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x17 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x18 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x19 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x1A => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1B => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1C => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1D => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1E => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1F => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x20 => { + let open_horse_window = OpenHorseWindow::decode(reader)?; + + Ok(Self::OpenHorseWindow(open_horse_window)) + } + 0x21 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x22 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x23 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x24 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x25 => { + let update_light = UpdateLight::decode(reader)?; + + Ok(Self::UpdateLight(update_light)) + } + 0x26 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x27 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x28 => { + let trade_list = TradeList::decode(reader)?; + + Ok(Self::TradeList(trade_list)) + } + 0x29 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x2A => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2B => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x2C => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2D => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2E => { + let open_book = OpenBook::decode(reader)?; + + Ok(Self::OpenBook(open_book)) + } + 0x30 => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x31 => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x32 => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x33 => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x34 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x36 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x37 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x38 => Ok(Self::EntityDestroy), + 0x39 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x3A => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x3B => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x3C => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3E => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3F => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x40 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x41 => { + let update_view_position = UpdateViewPosition::decode(reader)?; + + Ok(Self::UpdateViewPosition(update_view_position)) + } + 0x42 => { + let update_view_distance = UpdateViewDistance::decode(reader)?; + + Ok(Self::UpdateViewDistance(update_view_distance)) + } + 0x43 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x44 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x45 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x46 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x47 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x48 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x49 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x4A => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x4B => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x4C => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x4D => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x4E => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4F => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x50 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x51 => { + let entity_sound_effect = EntitySoundEffect::decode(reader)?; + + Ok(Self::EntitySoundEffect(entity_sound_effect)) + } + 0x53 => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x52 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x54 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x56 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x57 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x59 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x5A => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3D => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x5B => Ok(Self::DeclareRecipes), + 0x5C => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + 0x08 => { + let acknowledge_player_digging = AcknowledgePlayerDigging::decode(reader)?; + + Ok(Self::AcknowledgePlayerDigging(acknowledge_player_digging)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8, difficulty_locked: bool) -> Self { + let difficulty = Difficulty { + difficulty, + difficulty_locked, + }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window(window_id: i32, inventory_type: i32, window_title: String) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn open_horse_window(window_id: u8, nb_slots: i32, entity_id: i32) -> Self { + let open_horse_window = OpenHorseWindow { + window_id, + nb_slots, + entity_id, + }; + + Self::OpenHorseWindow(open_horse_window) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk( + x: i32, + z: i32, + ground_up: bool, + bit_map: i32, + heightmaps: CompoundTag, + chunk_data: Vec, + ) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + heightmaps, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f64, + y: f64, + z: f64, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn update_light( + chunk_x: i32, + chunk_z: i32, + sky_light_mask: i32, + block_light_mask: i32, + empty_sky_light_mask: i32, + empty_block_light_mask: i32, + data: Vec, + ) -> Self { + let update_light = UpdateLight { + chunk_x, + chunk_z, + sky_light_mask, + block_light_mask, + empty_sky_light_mask, + empty_block_light_mask, + data, + }; + + Self::UpdateLight(update_light) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + hashed_seed: i64, + max_players: u8, + level_type: String, + view_distance: i32, + reduced_debug_info: bool, + enable_respawn_screen: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + hashed_seed, + max_players, + level_type, + view_distance, + reduced_debug_info, + enable_respawn_screen, + }; + + Self::JoinGame(join_game) + } + + pub fn map( + item_damage: i32, + scale: i8, + tracking_position: bool, + locked: bool, + columns: i8, + ) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + locked, + columns, + }; + + Self::Map(map) + } + + pub fn trade_list( + window_id: i32, + villager_level: i32, + experience: i32, + is_regular_villager: bool, + can_restock: bool, + ) -> Self { + let trade_list = TradeList { + window_id, + villager_level, + experience, + is_regular_villager, + can_restock, + }; + + Self::TradeList(trade_list) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_book(hand: i32) -> Self { + let open_book = OpenBook { hand }; + + Self::OpenBook(open_book) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, hashed_seed: i64, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + hashed_seed, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn update_view_position(chunk_x: i32, chunk_z: i32) -> Self { + let update_view_position = UpdateViewPosition { chunk_x, chunk_z }; + + Self::UpdateViewPosition(update_view_position) + } + + pub fn update_view_distance(view_distance: i32) -> Self { + let update_view_distance = UpdateViewDistance { view_distance }; + + Self::UpdateViewDistance(update_view_distance) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn entity_sound_effect( + sound_id: i32, + sound_category: i32, + entity_id: i32, + volume: f32, + pitch: f32, + ) -> Self { + let entity_sound_effect = EntitySoundEffect { + sound_id, + sound_category, + entity_id, + volume, + pitch, + }; + + Self::EntitySoundEffect(entity_sound_effect) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags( + block_tags: TagsMap, + item_tags: TagsMap, + fluid_tags: TagsMap, + entity_tags: TagsMap, + ) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + entity_tags, + }; + + Self::Tags(tags) + } + + pub fn acknowledge_player_digging( + location: Position, + block: i32, + status: i32, + successful: bool, + ) -> Self { + let acknowledge_player_digging = AcknowledgePlayerDigging { + location, + block, + status, + successful, + }; + + Self::AcknowledgePlayerDigging(acknowledge_player_digging) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct SetDifficulty { + pub new_difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct LockDifficulty { + pub locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateJigsawBlock { + pub location: Position, + pub attachment_type: String, + pub target_pool: String, + pub final_state: String, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + #[packet(with = "var_int")] + pub hand: i32, + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, + pub inside_block: bool, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, + pub difficulty_locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub inventory_type: i32, + pub window_title: String, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenHorseWindow { + pub window_id: u8, + #[packet(with = "var_int")] + pub nb_slots: i32, + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub heightmaps: CompoundTag, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f64, + pub y: f64, + pub z: f64, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct UpdateLight { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, + #[packet(with = "var_int")] + pub sky_light_mask: i32, + #[packet(with = "var_int")] + pub block_light_mask: i32, + #[packet(with = "var_int")] + pub empty_sky_light_mask: i32, + #[packet(with = "var_int")] + pub empty_block_light_mask: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub hashed_seed: i64, + pub max_players: u8, + pub level_type: String, + #[packet(with = "var_int")] + pub view_distance: i32, + pub reduced_debug_info: bool, + pub enable_respawn_screen: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub locked: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct TradeList { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub villager_level: i32, + #[packet(with = "var_int")] + pub experience: i32, + pub is_regular_villager: bool, + pub can_restock: bool, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenBook { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub hashed_seed: i64, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewPosition { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewDistance { + #[packet(with = "var_int")] + pub view_distance: i32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct EntitySoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + #[packet(with = "var_int")] + pub entity_id: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, + pub entity_tags: TagsMap, +} + +#[derive(Packet, Debug)] +pub struct AcknowledgePlayerDigging { + pub location: Position, + #[packet(with = "var_int")] + pub block: i32, + #[packet(with = "var_int")] + pub status: i32, + pub successful: bool, +} diff --git a/protocol/src/version/v_1_15/handshake.rs b/protocol/src/version/v_1_15/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_15/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_15/login.rs b/protocol/src/version/v_1_15/login.rs new file mode 100644 index 0000000..fcbf5cc --- /dev/null +++ b/protocol/src/version/v_1_15/login.rs @@ -0,0 +1,209 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_15/mod.rs b/protocol/src/version/v_1_15/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_15/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_15/status.rs b/protocol/src/version/v_1_15/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_15/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_15_1/game.rs b/protocol/src/version/v_1_15_1/game.rs new file mode 100644 index 0000000..3b27cf6 --- /dev/null +++ b/protocol/src/version/v_1_15_1/game.rs @@ -0,0 +1,3573 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + SetDifficulty(SetDifficulty), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + LockDifficulty(LockDifficulty), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateJigsawBlock(UpdateJigsawBlock), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::SetDifficulty(_) => 0x02, + Self::EditBook(_) => 0x0C, + Self::QueryEntityNbt(_) => 0x0D, + Self::PickItem(_) => 0x17, + Self::NameItem(_) => 0x1E, + Self::SelectTrade(_) => 0x21, + Self::SetBeaconEffect(_) => 0x22, + Self::UpdateCommandBlock(_) => 0x24, + Self::UpdateCommandBlockMinecart(_) => 0x25, + Self::UpdateStructureBlock(_) => 0x28, + Self::ServerBoundTabComplete(_) => 0x06, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x07, + Self::EnchantItem(_) => 0x08, + Self::WindowClick(_) => 0x09, + Self::ServerBoundCloseWindow(_) => 0x0A, + Self::ServerBoundCustomPayload(_) => 0x0B, + Self::UseEntity(_) => 0x0E, + Self::ServerBoundKeepAlive(_) => 0x0F, + Self::LockDifficulty(_) => 0x10, + Self::ServerBoundPosition(_) => 0x11, + Self::PositionLook(_) => 0x12, + Self::Look(_) => 0x13, + Self::Flying(_) => 0x14, + Self::ServerBoundVehicleMove(_) => 0x15, + Self::SteerBoat(_) => 0x16, + Self::CraftRecipeRequest(_) => 0x18, + Self::ServerBoundAbilities(_) => 0x19, + Self::BlockDig(_) => 0x1A, + Self::EntityAction(_) => 0x1B, + Self::SteerVehicle(_) => 0x1C, + Self::CraftingBookData(_) => 0x1D, + Self::ResourcePackReceive(_) => 0x1F, + Self::ServerBoundHeldItemSlot(_) => 0x23, + Self::SetCreativeSlot(_) => 0x26, + Self::UpdateJigsawBlock(_) => 0x27, + Self::UpdateSign(_) => 0x29, + Self::ArmAnimation(_) => 0x2A, + Self::Spectate(_) => 0x2B, + Self::BlockPlace(_) => 0x2C, + Self::UseItem(_) => 0x2D, + Self::AdvancementTab(_) => 0x20, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x02 => { + let set_difficulty = SetDifficulty::decode(reader)?; + + Ok(Self::SetDifficulty(set_difficulty)) + } + 0x0C => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0D => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x17 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1E => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x21 => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x22 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x24 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x25 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x28 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x06 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x07 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x08 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x09 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x0A => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0B => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0E => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0F => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x10 => { + let lock_difficulty = LockDifficulty::decode(reader)?; + + Ok(Self::LockDifficulty(lock_difficulty)) + } + 0x11 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x12 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x13 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x14 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x15 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x16 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x18 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x19 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x1A => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x1B => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1C => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1D => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x1F => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x23 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x26 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x27 => { + let update_jigsaw_block = UpdateJigsawBlock::decode(reader)?; + + Ok(Self::UpdateJigsawBlock(update_jigsaw_block)) + } + 0x29 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x2A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x2B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x2C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x20 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn set_difficulty(new_difficulty: u8) -> Self { + let set_difficulty = SetDifficulty { new_difficulty }; + + Self::SetDifficulty(set_difficulty) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn lock_difficulty(locked: bool) -> Self { + let lock_difficulty = LockDifficulty { locked }; + + Self::LockDifficulty(lock_difficulty) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_jigsaw_block( + location: Position, + attachment_type: String, + target_pool: String, + final_state: String, + ) -> Self { + let update_jigsaw_block = UpdateJigsawBlock { + location, + attachment_type, + target_pool, + final_state, + }; + + Self::UpdateJigsawBlock(update_jigsaw_block) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + hand: i32, + location: Position, + direction: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + inside_block: bool, + ) -> Self { + let block_place = BlockPlace { + hand, + location, + direction, + cursor_x, + cursor_y, + cursor_z, + inside_block, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + OpenHorseWindow(OpenHorseWindow), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + UpdateLight(UpdateLight), + JoinGame(JoinGame), + Map(Map), + TradeList(TradeList), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenBook(OpenBook), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + UpdateViewPosition(UpdateViewPosition), + UpdateViewDistance(UpdateViewDistance), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + EntitySoundEffect(EntitySoundEffect), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), + AcknowledgePlayerDigging(AcknowledgePlayerDigging), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x58, + Self::BlockBreakAnimation(_) => 0x09, + Self::TileEntityData(_) => 0x0A, + Self::BlockAction(_) => 0x0B, + Self::BlockChange(_) => 0x0C, + Self::BossBar(_) => 0x0D, + Self::Difficulty(_) => 0x0E, + Self::ClientBoundTabComplete(_) => 0x11, + Self::DeclareCommands(_) => 0x12, + Self::FacePlayer(_) => 0x35, + Self::NbtQueryResponse(_) => 0x55, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x13, + Self::ClientBoundCloseWindow(_) => 0x14, + Self::OpenWindow(_) => 0x2F, + Self::WindowItems(_) => 0x15, + Self::CraftProgressBar(_) => 0x16, + Self::SetSlot(_) => 0x17, + Self::SetCooldown(_) => 0x18, + Self::ClientBoundCustomPayload(_) => 0x19, + Self::NamedSoundEffect(_) => 0x1A, + Self::KickDisconnect(_) => 0x1B, + Self::EntityStatus(_) => 0x1C, + Self::Explosion(_) => 0x1D, + Self::UnloadChunk(_) => 0x1E, + Self::GameStateChange(_) => 0x1F, + Self::OpenHorseWindow(_) => 0x20, + Self::ClientBoundKeepAlive(_) => 0x21, + Self::MapChunk(_) => 0x22, + Self::WorldEvent(_) => 0x23, + Self::WorldParticles(_) => 0x24, + Self::UpdateLight(_) => 0x25, + Self::JoinGame(_) => 0x26, + Self::Map(_) => 0x27, + Self::TradeList(_) => 0x28, + Self::RelEntityMove(_) => 0x29, + Self::EntityMoveLook(_) => 0x2A, + Self::EntityLook(_) => 0x2B, + Self::Entity(_) => 0x2C, + Self::ClientBoundVehicleMove(_) => 0x2D, + Self::OpenBook(_) => 0x2E, + Self::OpenSignEntity(_) => 0x30, + Self::CraftRecipeResponse(_) => 0x31, + Self::ClientBoundAbilities(_) => 0x32, + Self::CombatEvent(_) => 0x33, + Self::PlayerInfo(_) => 0x34, + Self::ClientBoundPosition(_) => 0x36, + Self::UnlockRecipes(_) => 0x37, + Self::EntityDestroy => 0x38, + Self::RemoveEntityEffect(_) => 0x39, + Self::ResourcePackSend(_) => 0x3A, + Self::Respawn(_) => 0x3B, + Self::EntityHeadRotation(_) => 0x3C, + Self::WorldBorder(_) => 0x3E, + Self::Camera(_) => 0x3F, + Self::ClientBoundHeldItemSlot(_) => 0x40, + Self::UpdateViewPosition(_) => 0x41, + Self::UpdateViewDistance(_) => 0x42, + Self::ScoreboardDisplayObjective(_) => 0x43, + Self::EntityMetadata(_) => 0x44, + Self::AttachEntity(_) => 0x45, + Self::EntityVelocity(_) => 0x46, + Self::EntityEquipment(_) => 0x47, + Self::Experience(_) => 0x48, + Self::UpdateHealth(_) => 0x49, + Self::ScoreboardObjective(_) => 0x4A, + Self::SetPassengers(_) => 0x4B, + Self::Teams(_) => 0x4C, + Self::ScoreboardScore(_) => 0x4D, + Self::SpawnPosition(_) => 0x4E, + Self::UpdateTime(_) => 0x4F, + Self::Title(_) => 0x50, + Self::EntitySoundEffect(_) => 0x51, + Self::StopSound(_) => 0x53, + Self::SoundEffect(_) => 0x52, + Self::PlayerlistHeader(_) => 0x54, + Self::Collect(_) => 0x56, + Self::EntityTeleport(_) => 0x57, + Self::EntityUpdateAttributes(_) => 0x59, + Self::EntityEffect(_) => 0x5A, + Self::SelectAdvancementTab(_) => 0x3D, + Self::DeclareRecipes => 0x5B, + Self::Tags(_) => 0x5C, + Self::AcknowledgePlayerDigging(_) => 0x08, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x58 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x09 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x0A => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0B => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0C => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0D => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0E => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x11 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x12 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x35 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x55 => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x13 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x14 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x2F => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x15 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x16 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x17 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x18 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x19 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x1A => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1B => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1C => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1D => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1E => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1F => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x20 => { + let open_horse_window = OpenHorseWindow::decode(reader)?; + + Ok(Self::OpenHorseWindow(open_horse_window)) + } + 0x21 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x22 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x23 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x24 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x25 => { + let update_light = UpdateLight::decode(reader)?; + + Ok(Self::UpdateLight(update_light)) + } + 0x26 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x27 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x28 => { + let trade_list = TradeList::decode(reader)?; + + Ok(Self::TradeList(trade_list)) + } + 0x29 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x2A => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2B => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x2C => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2D => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2E => { + let open_book = OpenBook::decode(reader)?; + + Ok(Self::OpenBook(open_book)) + } + 0x30 => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x31 => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x32 => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x33 => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x34 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x36 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x37 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x38 => Ok(Self::EntityDestroy), + 0x39 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x3A => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x3B => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x3C => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3E => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3F => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x40 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x41 => { + let update_view_position = UpdateViewPosition::decode(reader)?; + + Ok(Self::UpdateViewPosition(update_view_position)) + } + 0x42 => { + let update_view_distance = UpdateViewDistance::decode(reader)?; + + Ok(Self::UpdateViewDistance(update_view_distance)) + } + 0x43 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x44 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x45 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x46 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x47 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x48 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x49 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x4A => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x4B => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x4C => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x4D => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x4E => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4F => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x50 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x51 => { + let entity_sound_effect = EntitySoundEffect::decode(reader)?; + + Ok(Self::EntitySoundEffect(entity_sound_effect)) + } + 0x53 => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x52 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x54 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x56 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x57 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x59 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x5A => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3D => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x5B => Ok(Self::DeclareRecipes), + 0x5C => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + 0x08 => { + let acknowledge_player_digging = AcknowledgePlayerDigging::decode(reader)?; + + Ok(Self::AcknowledgePlayerDigging(acknowledge_player_digging)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8, difficulty_locked: bool) -> Self { + let difficulty = Difficulty { + difficulty, + difficulty_locked, + }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window(window_id: i32, inventory_type: i32, window_title: String) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn open_horse_window(window_id: u8, nb_slots: i32, entity_id: i32) -> Self { + let open_horse_window = OpenHorseWindow { + window_id, + nb_slots, + entity_id, + }; + + Self::OpenHorseWindow(open_horse_window) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk( + x: i32, + z: i32, + ground_up: bool, + bit_map: i32, + heightmaps: CompoundTag, + chunk_data: Vec, + ) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + heightmaps, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f64, + y: f64, + z: f64, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn update_light( + chunk_x: i32, + chunk_z: i32, + sky_light_mask: i32, + block_light_mask: i32, + empty_sky_light_mask: i32, + empty_block_light_mask: i32, + data: Vec, + ) -> Self { + let update_light = UpdateLight { + chunk_x, + chunk_z, + sky_light_mask, + block_light_mask, + empty_sky_light_mask, + empty_block_light_mask, + data, + }; + + Self::UpdateLight(update_light) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + hashed_seed: i64, + max_players: u8, + level_type: String, + view_distance: i32, + reduced_debug_info: bool, + enable_respawn_screen: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + hashed_seed, + max_players, + level_type, + view_distance, + reduced_debug_info, + enable_respawn_screen, + }; + + Self::JoinGame(join_game) + } + + pub fn map( + item_damage: i32, + scale: i8, + tracking_position: bool, + locked: bool, + columns: i8, + ) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + locked, + columns, + }; + + Self::Map(map) + } + + pub fn trade_list( + window_id: i32, + villager_level: i32, + experience: i32, + is_regular_villager: bool, + can_restock: bool, + ) -> Self { + let trade_list = TradeList { + window_id, + villager_level, + experience, + is_regular_villager, + can_restock, + }; + + Self::TradeList(trade_list) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_book(hand: i32) -> Self { + let open_book = OpenBook { hand }; + + Self::OpenBook(open_book) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, hashed_seed: i64, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + hashed_seed, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn update_view_position(chunk_x: i32, chunk_z: i32) -> Self { + let update_view_position = UpdateViewPosition { chunk_x, chunk_z }; + + Self::UpdateViewPosition(update_view_position) + } + + pub fn update_view_distance(view_distance: i32) -> Self { + let update_view_distance = UpdateViewDistance { view_distance }; + + Self::UpdateViewDistance(update_view_distance) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn entity_sound_effect( + sound_id: i32, + sound_category: i32, + entity_id: i32, + volume: f32, + pitch: f32, + ) -> Self { + let entity_sound_effect = EntitySoundEffect { + sound_id, + sound_category, + entity_id, + volume, + pitch, + }; + + Self::EntitySoundEffect(entity_sound_effect) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags( + block_tags: TagsMap, + item_tags: TagsMap, + fluid_tags: TagsMap, + entity_tags: TagsMap, + ) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + entity_tags, + }; + + Self::Tags(tags) + } + + pub fn acknowledge_player_digging( + location: Position, + block: i32, + status: i32, + successful: bool, + ) -> Self { + let acknowledge_player_digging = AcknowledgePlayerDigging { + location, + block, + status, + successful, + }; + + Self::AcknowledgePlayerDigging(acknowledge_player_digging) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct SetDifficulty { + pub new_difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct LockDifficulty { + pub locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateJigsawBlock { + pub location: Position, + pub attachment_type: String, + pub target_pool: String, + pub final_state: String, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + #[packet(with = "var_int")] + pub hand: i32, + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, + pub inside_block: bool, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, + pub difficulty_locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub inventory_type: i32, + pub window_title: String, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenHorseWindow { + pub window_id: u8, + #[packet(with = "var_int")] + pub nb_slots: i32, + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub heightmaps: CompoundTag, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f64, + pub y: f64, + pub z: f64, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct UpdateLight { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, + #[packet(with = "var_int")] + pub sky_light_mask: i32, + #[packet(with = "var_int")] + pub block_light_mask: i32, + #[packet(with = "var_int")] + pub empty_sky_light_mask: i32, + #[packet(with = "var_int")] + pub empty_block_light_mask: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub hashed_seed: i64, + pub max_players: u8, + pub level_type: String, + #[packet(with = "var_int")] + pub view_distance: i32, + pub reduced_debug_info: bool, + pub enable_respawn_screen: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub locked: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct TradeList { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub villager_level: i32, + #[packet(with = "var_int")] + pub experience: i32, + pub is_regular_villager: bool, + pub can_restock: bool, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenBook { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub hashed_seed: i64, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewPosition { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewDistance { + #[packet(with = "var_int")] + pub view_distance: i32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct EntitySoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + #[packet(with = "var_int")] + pub entity_id: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, + pub entity_tags: TagsMap, +} + +#[derive(Packet, Debug)] +pub struct AcknowledgePlayerDigging { + pub location: Position, + #[packet(with = "var_int")] + pub block: i32, + #[packet(with = "var_int")] + pub status: i32, + pub successful: bool, +} diff --git a/protocol/src/version/v_1_15_1/handshake.rs b/protocol/src/version/v_1_15_1/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_15_1/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_15_1/login.rs b/protocol/src/version/v_1_15_1/login.rs new file mode 100644 index 0000000..fcbf5cc --- /dev/null +++ b/protocol/src/version/v_1_15_1/login.rs @@ -0,0 +1,209 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_15_1/mod.rs b/protocol/src/version/v_1_15_1/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_15_1/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_15_1/status.rs b/protocol/src/version/v_1_15_1/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_15_1/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_15_2/game.rs b/protocol/src/version/v_1_15_2/game.rs new file mode 100644 index 0000000..3b27cf6 --- /dev/null +++ b/protocol/src/version/v_1_15_2/game.rs @@ -0,0 +1,3573 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + SetDifficulty(SetDifficulty), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + LockDifficulty(LockDifficulty), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateJigsawBlock(UpdateJigsawBlock), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::SetDifficulty(_) => 0x02, + Self::EditBook(_) => 0x0C, + Self::QueryEntityNbt(_) => 0x0D, + Self::PickItem(_) => 0x17, + Self::NameItem(_) => 0x1E, + Self::SelectTrade(_) => 0x21, + Self::SetBeaconEffect(_) => 0x22, + Self::UpdateCommandBlock(_) => 0x24, + Self::UpdateCommandBlockMinecart(_) => 0x25, + Self::UpdateStructureBlock(_) => 0x28, + Self::ServerBoundTabComplete(_) => 0x06, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x07, + Self::EnchantItem(_) => 0x08, + Self::WindowClick(_) => 0x09, + Self::ServerBoundCloseWindow(_) => 0x0A, + Self::ServerBoundCustomPayload(_) => 0x0B, + Self::UseEntity(_) => 0x0E, + Self::ServerBoundKeepAlive(_) => 0x0F, + Self::LockDifficulty(_) => 0x10, + Self::ServerBoundPosition(_) => 0x11, + Self::PositionLook(_) => 0x12, + Self::Look(_) => 0x13, + Self::Flying(_) => 0x14, + Self::ServerBoundVehicleMove(_) => 0x15, + Self::SteerBoat(_) => 0x16, + Self::CraftRecipeRequest(_) => 0x18, + Self::ServerBoundAbilities(_) => 0x19, + Self::BlockDig(_) => 0x1A, + Self::EntityAction(_) => 0x1B, + Self::SteerVehicle(_) => 0x1C, + Self::CraftingBookData(_) => 0x1D, + Self::ResourcePackReceive(_) => 0x1F, + Self::ServerBoundHeldItemSlot(_) => 0x23, + Self::SetCreativeSlot(_) => 0x26, + Self::UpdateJigsawBlock(_) => 0x27, + Self::UpdateSign(_) => 0x29, + Self::ArmAnimation(_) => 0x2A, + Self::Spectate(_) => 0x2B, + Self::BlockPlace(_) => 0x2C, + Self::UseItem(_) => 0x2D, + Self::AdvancementTab(_) => 0x20, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x02 => { + let set_difficulty = SetDifficulty::decode(reader)?; + + Ok(Self::SetDifficulty(set_difficulty)) + } + 0x0C => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0D => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x17 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1E => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x21 => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x22 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x24 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x25 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x28 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x06 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x07 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x08 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x09 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x0A => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0B => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0E => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0F => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x10 => { + let lock_difficulty = LockDifficulty::decode(reader)?; + + Ok(Self::LockDifficulty(lock_difficulty)) + } + 0x11 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x12 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x13 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x14 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x15 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x16 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x18 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x19 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x1A => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x1B => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1C => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1D => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x1F => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x23 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x26 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x27 => { + let update_jigsaw_block = UpdateJigsawBlock::decode(reader)?; + + Ok(Self::UpdateJigsawBlock(update_jigsaw_block)) + } + 0x29 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x2A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x2B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x2C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x20 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn set_difficulty(new_difficulty: u8) -> Self { + let set_difficulty = SetDifficulty { new_difficulty }; + + Self::SetDifficulty(set_difficulty) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn lock_difficulty(locked: bool) -> Self { + let lock_difficulty = LockDifficulty { locked }; + + Self::LockDifficulty(lock_difficulty) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_jigsaw_block( + location: Position, + attachment_type: String, + target_pool: String, + final_state: String, + ) -> Self { + let update_jigsaw_block = UpdateJigsawBlock { + location, + attachment_type, + target_pool, + final_state, + }; + + Self::UpdateJigsawBlock(update_jigsaw_block) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + hand: i32, + location: Position, + direction: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + inside_block: bool, + ) -> Self { + let block_place = BlockPlace { + hand, + location, + direction, + cursor_x, + cursor_y, + cursor_z, + inside_block, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + OpenHorseWindow(OpenHorseWindow), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + UpdateLight(UpdateLight), + JoinGame(JoinGame), + Map(Map), + TradeList(TradeList), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenBook(OpenBook), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + UpdateViewPosition(UpdateViewPosition), + UpdateViewDistance(UpdateViewDistance), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + EntitySoundEffect(EntitySoundEffect), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), + AcknowledgePlayerDigging(AcknowledgePlayerDigging), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x58, + Self::BlockBreakAnimation(_) => 0x09, + Self::TileEntityData(_) => 0x0A, + Self::BlockAction(_) => 0x0B, + Self::BlockChange(_) => 0x0C, + Self::BossBar(_) => 0x0D, + Self::Difficulty(_) => 0x0E, + Self::ClientBoundTabComplete(_) => 0x11, + Self::DeclareCommands(_) => 0x12, + Self::FacePlayer(_) => 0x35, + Self::NbtQueryResponse(_) => 0x55, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x13, + Self::ClientBoundCloseWindow(_) => 0x14, + Self::OpenWindow(_) => 0x2F, + Self::WindowItems(_) => 0x15, + Self::CraftProgressBar(_) => 0x16, + Self::SetSlot(_) => 0x17, + Self::SetCooldown(_) => 0x18, + Self::ClientBoundCustomPayload(_) => 0x19, + Self::NamedSoundEffect(_) => 0x1A, + Self::KickDisconnect(_) => 0x1B, + Self::EntityStatus(_) => 0x1C, + Self::Explosion(_) => 0x1D, + Self::UnloadChunk(_) => 0x1E, + Self::GameStateChange(_) => 0x1F, + Self::OpenHorseWindow(_) => 0x20, + Self::ClientBoundKeepAlive(_) => 0x21, + Self::MapChunk(_) => 0x22, + Self::WorldEvent(_) => 0x23, + Self::WorldParticles(_) => 0x24, + Self::UpdateLight(_) => 0x25, + Self::JoinGame(_) => 0x26, + Self::Map(_) => 0x27, + Self::TradeList(_) => 0x28, + Self::RelEntityMove(_) => 0x29, + Self::EntityMoveLook(_) => 0x2A, + Self::EntityLook(_) => 0x2B, + Self::Entity(_) => 0x2C, + Self::ClientBoundVehicleMove(_) => 0x2D, + Self::OpenBook(_) => 0x2E, + Self::OpenSignEntity(_) => 0x30, + Self::CraftRecipeResponse(_) => 0x31, + Self::ClientBoundAbilities(_) => 0x32, + Self::CombatEvent(_) => 0x33, + Self::PlayerInfo(_) => 0x34, + Self::ClientBoundPosition(_) => 0x36, + Self::UnlockRecipes(_) => 0x37, + Self::EntityDestroy => 0x38, + Self::RemoveEntityEffect(_) => 0x39, + Self::ResourcePackSend(_) => 0x3A, + Self::Respawn(_) => 0x3B, + Self::EntityHeadRotation(_) => 0x3C, + Self::WorldBorder(_) => 0x3E, + Self::Camera(_) => 0x3F, + Self::ClientBoundHeldItemSlot(_) => 0x40, + Self::UpdateViewPosition(_) => 0x41, + Self::UpdateViewDistance(_) => 0x42, + Self::ScoreboardDisplayObjective(_) => 0x43, + Self::EntityMetadata(_) => 0x44, + Self::AttachEntity(_) => 0x45, + Self::EntityVelocity(_) => 0x46, + Self::EntityEquipment(_) => 0x47, + Self::Experience(_) => 0x48, + Self::UpdateHealth(_) => 0x49, + Self::ScoreboardObjective(_) => 0x4A, + Self::SetPassengers(_) => 0x4B, + Self::Teams(_) => 0x4C, + Self::ScoreboardScore(_) => 0x4D, + Self::SpawnPosition(_) => 0x4E, + Self::UpdateTime(_) => 0x4F, + Self::Title(_) => 0x50, + Self::EntitySoundEffect(_) => 0x51, + Self::StopSound(_) => 0x53, + Self::SoundEffect(_) => 0x52, + Self::PlayerlistHeader(_) => 0x54, + Self::Collect(_) => 0x56, + Self::EntityTeleport(_) => 0x57, + Self::EntityUpdateAttributes(_) => 0x59, + Self::EntityEffect(_) => 0x5A, + Self::SelectAdvancementTab(_) => 0x3D, + Self::DeclareRecipes => 0x5B, + Self::Tags(_) => 0x5C, + Self::AcknowledgePlayerDigging(_) => 0x08, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x58 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x09 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x0A => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0B => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0C => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0D => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0E => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x11 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x12 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x35 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x55 => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x13 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x14 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x2F => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x15 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x16 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x17 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x18 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x19 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x1A => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1B => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1C => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1D => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1E => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1F => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x20 => { + let open_horse_window = OpenHorseWindow::decode(reader)?; + + Ok(Self::OpenHorseWindow(open_horse_window)) + } + 0x21 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x22 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x23 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x24 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x25 => { + let update_light = UpdateLight::decode(reader)?; + + Ok(Self::UpdateLight(update_light)) + } + 0x26 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x27 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x28 => { + let trade_list = TradeList::decode(reader)?; + + Ok(Self::TradeList(trade_list)) + } + 0x29 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x2A => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2B => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x2C => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2D => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2E => { + let open_book = OpenBook::decode(reader)?; + + Ok(Self::OpenBook(open_book)) + } + 0x30 => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x31 => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x32 => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x33 => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x34 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x36 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x37 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x38 => Ok(Self::EntityDestroy), + 0x39 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x3A => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x3B => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x3C => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3E => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3F => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x40 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x41 => { + let update_view_position = UpdateViewPosition::decode(reader)?; + + Ok(Self::UpdateViewPosition(update_view_position)) + } + 0x42 => { + let update_view_distance = UpdateViewDistance::decode(reader)?; + + Ok(Self::UpdateViewDistance(update_view_distance)) + } + 0x43 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x44 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x45 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x46 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x47 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x48 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x49 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x4A => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x4B => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x4C => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x4D => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x4E => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4F => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x50 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x51 => { + let entity_sound_effect = EntitySoundEffect::decode(reader)?; + + Ok(Self::EntitySoundEffect(entity_sound_effect)) + } + 0x53 => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x52 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x54 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x56 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x57 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x59 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x5A => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3D => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x5B => Ok(Self::DeclareRecipes), + 0x5C => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + 0x08 => { + let acknowledge_player_digging = AcknowledgePlayerDigging::decode(reader)?; + + Ok(Self::AcknowledgePlayerDigging(acknowledge_player_digging)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8, difficulty_locked: bool) -> Self { + let difficulty = Difficulty { + difficulty, + difficulty_locked, + }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window(window_id: i32, inventory_type: i32, window_title: String) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn open_horse_window(window_id: u8, nb_slots: i32, entity_id: i32) -> Self { + let open_horse_window = OpenHorseWindow { + window_id, + nb_slots, + entity_id, + }; + + Self::OpenHorseWindow(open_horse_window) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk( + x: i32, + z: i32, + ground_up: bool, + bit_map: i32, + heightmaps: CompoundTag, + chunk_data: Vec, + ) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + heightmaps, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f64, + y: f64, + z: f64, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn update_light( + chunk_x: i32, + chunk_z: i32, + sky_light_mask: i32, + block_light_mask: i32, + empty_sky_light_mask: i32, + empty_block_light_mask: i32, + data: Vec, + ) -> Self { + let update_light = UpdateLight { + chunk_x, + chunk_z, + sky_light_mask, + block_light_mask, + empty_sky_light_mask, + empty_block_light_mask, + data, + }; + + Self::UpdateLight(update_light) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + hashed_seed: i64, + max_players: u8, + level_type: String, + view_distance: i32, + reduced_debug_info: bool, + enable_respawn_screen: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + hashed_seed, + max_players, + level_type, + view_distance, + reduced_debug_info, + enable_respawn_screen, + }; + + Self::JoinGame(join_game) + } + + pub fn map( + item_damage: i32, + scale: i8, + tracking_position: bool, + locked: bool, + columns: i8, + ) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + locked, + columns, + }; + + Self::Map(map) + } + + pub fn trade_list( + window_id: i32, + villager_level: i32, + experience: i32, + is_regular_villager: bool, + can_restock: bool, + ) -> Self { + let trade_list = TradeList { + window_id, + villager_level, + experience, + is_regular_villager, + can_restock, + }; + + Self::TradeList(trade_list) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_book(hand: i32) -> Self { + let open_book = OpenBook { hand }; + + Self::OpenBook(open_book) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, hashed_seed: i64, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + hashed_seed, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn update_view_position(chunk_x: i32, chunk_z: i32) -> Self { + let update_view_position = UpdateViewPosition { chunk_x, chunk_z }; + + Self::UpdateViewPosition(update_view_position) + } + + pub fn update_view_distance(view_distance: i32) -> Self { + let update_view_distance = UpdateViewDistance { view_distance }; + + Self::UpdateViewDistance(update_view_distance) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn entity_sound_effect( + sound_id: i32, + sound_category: i32, + entity_id: i32, + volume: f32, + pitch: f32, + ) -> Self { + let entity_sound_effect = EntitySoundEffect { + sound_id, + sound_category, + entity_id, + volume, + pitch, + }; + + Self::EntitySoundEffect(entity_sound_effect) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags( + block_tags: TagsMap, + item_tags: TagsMap, + fluid_tags: TagsMap, + entity_tags: TagsMap, + ) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + entity_tags, + }; + + Self::Tags(tags) + } + + pub fn acknowledge_player_digging( + location: Position, + block: i32, + status: i32, + successful: bool, + ) -> Self { + let acknowledge_player_digging = AcknowledgePlayerDigging { + location, + block, + status, + successful, + }; + + Self::AcknowledgePlayerDigging(acknowledge_player_digging) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct SetDifficulty { + pub new_difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct LockDifficulty { + pub locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateJigsawBlock { + pub location: Position, + pub attachment_type: String, + pub target_pool: String, + pub final_state: String, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + #[packet(with = "var_int")] + pub hand: i32, + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, + pub inside_block: bool, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, + pub difficulty_locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub inventory_type: i32, + pub window_title: String, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenHorseWindow { + pub window_id: u8, + #[packet(with = "var_int")] + pub nb_slots: i32, + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub heightmaps: CompoundTag, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f64, + pub y: f64, + pub z: f64, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct UpdateLight { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, + #[packet(with = "var_int")] + pub sky_light_mask: i32, + #[packet(with = "var_int")] + pub block_light_mask: i32, + #[packet(with = "var_int")] + pub empty_sky_light_mask: i32, + #[packet(with = "var_int")] + pub empty_block_light_mask: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub hashed_seed: i64, + pub max_players: u8, + pub level_type: String, + #[packet(with = "var_int")] + pub view_distance: i32, + pub reduced_debug_info: bool, + pub enable_respawn_screen: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub locked: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct TradeList { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub villager_level: i32, + #[packet(with = "var_int")] + pub experience: i32, + pub is_regular_villager: bool, + pub can_restock: bool, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenBook { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub hashed_seed: i64, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewPosition { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewDistance { + #[packet(with = "var_int")] + pub view_distance: i32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct EntitySoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + #[packet(with = "var_int")] + pub entity_id: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, + pub entity_tags: TagsMap, +} + +#[derive(Packet, Debug)] +pub struct AcknowledgePlayerDigging { + pub location: Position, + #[packet(with = "var_int")] + pub block: i32, + #[packet(with = "var_int")] + pub status: i32, + pub successful: bool, +} diff --git a/protocol/src/version/v_1_15_2/handshake.rs b/protocol/src/version/v_1_15_2/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_15_2/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_15_2/login.rs b/protocol/src/version/v_1_15_2/login.rs new file mode 100644 index 0000000..fcbf5cc --- /dev/null +++ b/protocol/src/version/v_1_15_2/login.rs @@ -0,0 +1,209 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_15_2/mod.rs b/protocol/src/version/v_1_15_2/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_15_2/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_15_2/status.rs b/protocol/src/version/v_1_15_2/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_15_2/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_16/game.rs b/protocol/src/version/v_1_16/game.rs new file mode 100644 index 0000000..70250d5 --- /dev/null +++ b/protocol/src/version/v_1_16/game.rs @@ -0,0 +1,3607 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + SetDifficulty(SetDifficulty), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + GenerateStructure(GenerateStructure), + ServerBoundKeepAlive(ServerBoundKeepAlive), + LockDifficulty(LockDifficulty), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateJigsawBlock(UpdateJigsawBlock), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::SetDifficulty(_) => 0x02, + Self::EditBook(_) => 0x0C, + Self::QueryEntityNbt(_) => 0x0D, + Self::PickItem(_) => 0x18, + Self::NameItem(_) => 0x1F, + Self::SelectTrade(_) => 0x22, + Self::SetBeaconEffect(_) => 0x23, + Self::UpdateCommandBlock(_) => 0x25, + Self::UpdateCommandBlockMinecart(_) => 0x26, + Self::UpdateStructureBlock(_) => 0x29, + Self::ServerBoundTabComplete(_) => 0x06, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x07, + Self::EnchantItem(_) => 0x08, + Self::WindowClick(_) => 0x09, + Self::ServerBoundCloseWindow(_) => 0x0A, + Self::ServerBoundCustomPayload(_) => 0x0B, + Self::UseEntity(_) => 0x0E, + Self::GenerateStructure(_) => 0x0F, + Self::ServerBoundKeepAlive(_) => 0x10, + Self::LockDifficulty(_) => 0x11, + Self::ServerBoundPosition(_) => 0x12, + Self::PositionLook(_) => 0x13, + Self::Look(_) => 0x14, + Self::Flying(_) => 0x15, + Self::ServerBoundVehicleMove(_) => 0x16, + Self::SteerBoat(_) => 0x17, + Self::CraftRecipeRequest(_) => 0x19, + Self::ServerBoundAbilities(_) => 0x1A, + Self::BlockDig(_) => 0x1B, + Self::EntityAction(_) => 0x1C, + Self::SteerVehicle(_) => 0x1D, + Self::CraftingBookData(_) => 0x1E, + Self::ResourcePackReceive(_) => 0x20, + Self::ServerBoundHeldItemSlot(_) => 0x24, + Self::SetCreativeSlot(_) => 0x27, + Self::UpdateJigsawBlock(_) => 0x28, + Self::UpdateSign(_) => 0x2A, + Self::ArmAnimation(_) => 0x2B, + Self::Spectate(_) => 0x2C, + Self::BlockPlace(_) => 0x2D, + Self::UseItem(_) => 0x2E, + Self::AdvancementTab(_) => 0x21, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x02 => { + let set_difficulty = SetDifficulty::decode(reader)?; + + Ok(Self::SetDifficulty(set_difficulty)) + } + 0x0C => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0D => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x18 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1F => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x22 => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x23 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x25 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x26 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x29 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x06 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x07 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x08 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x09 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x0A => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0B => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0E => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0F => { + let generate_structure = GenerateStructure::decode(reader)?; + + Ok(Self::GenerateStructure(generate_structure)) + } + 0x10 => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x11 => { + let lock_difficulty = LockDifficulty::decode(reader)?; + + Ok(Self::LockDifficulty(lock_difficulty)) + } + 0x12 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x13 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x14 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x15 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x16 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x17 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x19 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x1A => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x1B => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x1C => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1D => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1E => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x20 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x24 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x27 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x28 => { + let update_jigsaw_block = UpdateJigsawBlock::decode(reader)?; + + Ok(Self::UpdateJigsawBlock(update_jigsaw_block)) + } + 0x2A => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x2B => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x2C => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x2D => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2E => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x21 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn set_difficulty(new_difficulty: u8) -> Self { + let set_difficulty = SetDifficulty { new_difficulty }; + + Self::SetDifficulty(set_difficulty) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32, sneaking: bool) -> Self { + let use_entity = UseEntity { + target, + mouse, + sneaking, + }; + + Self::UseEntity(use_entity) + } + + pub fn generate_structure(location: Position, levels: i32, keep_jigsaws: bool) -> Self { + let generate_structure = GenerateStructure { + location, + levels, + keep_jigsaws, + }; + + Self::GenerateStructure(generate_structure) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn lock_difficulty(locked: bool) -> Self { + let lock_difficulty = LockDifficulty { locked }; + + Self::LockDifficulty(lock_difficulty) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8) -> Self { + let server_bound_abilities = ServerBoundAbilities { flags }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_jigsaw_block( + location: Position, + name: String, + target: String, + pool: String, + final_state: String, + joint_type: String, + ) -> Self { + let update_jigsaw_block = UpdateJigsawBlock { + location, + name, + target, + pool, + final_state, + joint_type, + }; + + Self::UpdateJigsawBlock(update_jigsaw_block) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + hand: i32, + location: Position, + direction: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + inside_block: bool, + ) -> Self { + let block_place = BlockPlace { + hand, + location, + direction, + cursor_x, + cursor_y, + cursor_z, + inside_block, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + OpenHorseWindow(OpenHorseWindow), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + UpdateLight(UpdateLight), + JoinGame(JoinGame), + Map(Map), + TradeList(TradeList), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenBook(OpenBook), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + UpdateViewPosition(UpdateViewPosition), + UpdateViewDistance(UpdateViewDistance), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + EntitySoundEffect(EntitySoundEffect), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), + AcknowledgePlayerDigging(AcknowledgePlayerDigging), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityLiving(_) => 0x02, + Self::SpawnEntityPainting(_) => 0x03, + Self::NamedEntitySpawn(_) => 0x04, + Self::Animation(_) => 0x05, + Self::Statistics => 0x06, + Self::Advancements(_) => 0x57, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete(_) => 0x10, + Self::DeclareCommands(_) => 0x11, + Self::FacePlayer(_) => 0x34, + Self::NbtQueryResponse(_) => 0x54, + Self::ClientBoundChat(_) => 0x0E, + Self::MultiBlockChange(_) => 0x0F, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x2E, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::OpenHorseWindow(_) => 0x1F, + Self::ClientBoundKeepAlive(_) => 0x20, + Self::MapChunk(_) => 0x21, + Self::WorldEvent(_) => 0x22, + Self::WorldParticles(_) => 0x23, + Self::UpdateLight(_) => 0x24, + Self::JoinGame(_) => 0x25, + Self::Map(_) => 0x26, + Self::TradeList(_) => 0x27, + Self::RelEntityMove(_) => 0x28, + Self::EntityMoveLook(_) => 0x29, + Self::EntityLook(_) => 0x2A, + Self::Entity(_) => 0x2B, + Self::ClientBoundVehicleMove(_) => 0x2C, + Self::OpenBook(_) => 0x2D, + Self::OpenSignEntity(_) => 0x2F, + Self::CraftRecipeResponse(_) => 0x30, + Self::ClientBoundAbilities(_) => 0x31, + Self::CombatEvent(_) => 0x32, + Self::PlayerInfo(_) => 0x33, + Self::ClientBoundPosition(_) => 0x35, + Self::UnlockRecipes(_) => 0x36, + Self::EntityDestroy => 0x37, + Self::RemoveEntityEffect(_) => 0x38, + Self::ResourcePackSend(_) => 0x39, + Self::Respawn(_) => 0x3A, + Self::EntityHeadRotation(_) => 0x3B, + Self::WorldBorder(_) => 0x3D, + Self::Camera(_) => 0x3E, + Self::ClientBoundHeldItemSlot(_) => 0x3F, + Self::UpdateViewPosition(_) => 0x40, + Self::UpdateViewDistance(_) => 0x41, + Self::ScoreboardDisplayObjective(_) => 0x43, + Self::EntityMetadata(_) => 0x44, + Self::AttachEntity(_) => 0x45, + Self::EntityVelocity(_) => 0x46, + Self::EntityEquipment(_) => 0x47, + Self::Experience(_) => 0x48, + Self::UpdateHealth(_) => 0x49, + Self::ScoreboardObjective(_) => 0x4A, + Self::SetPassengers(_) => 0x4B, + Self::Teams(_) => 0x4C, + Self::ScoreboardScore(_) => 0x4D, + Self::SpawnPosition(_) => 0x42, + Self::UpdateTime(_) => 0x4E, + Self::Title(_) => 0x4F, + Self::EntitySoundEffect(_) => 0x50, + Self::StopSound(_) => 0x52, + Self::SoundEffect(_) => 0x51, + Self::PlayerlistHeader(_) => 0x53, + Self::Collect(_) => 0x55, + Self::EntityTeleport(_) => 0x56, + Self::EntityUpdateAttributes(_) => 0x58, + Self::EntityEffect(_) => 0x59, + Self::SelectAdvancementTab(_) => 0x3C, + Self::DeclareRecipes => 0x5A, + Self::Tags(_) => 0x5B, + Self::AcknowledgePlayerDigging(_) => 0x07, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x03 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x04 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x05 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x06 => Ok(Self::Statistics), + 0x57 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x10 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x11 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x34 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x54 => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0E => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x0F => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x2E => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let open_horse_window = OpenHorseWindow::decode(reader)?; + + Ok(Self::OpenHorseWindow(open_horse_window)) + } + 0x20 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x21 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x22 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x23 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x24 => { + let update_light = UpdateLight::decode(reader)?; + + Ok(Self::UpdateLight(update_light)) + } + 0x25 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x26 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x27 => { + let trade_list = TradeList::decode(reader)?; + + Ok(Self::TradeList(trade_list)) + } + 0x28 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x29 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2A => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x2B => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2C => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2D => { + let open_book = OpenBook::decode(reader)?; + + Ok(Self::OpenBook(open_book)) + } + 0x2F => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x30 => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x31 => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x32 => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x33 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x35 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x36 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x37 => Ok(Self::EntityDestroy), + 0x38 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x39 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x3A => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x3B => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3D => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3E => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3F => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x40 => { + let update_view_position = UpdateViewPosition::decode(reader)?; + + Ok(Self::UpdateViewPosition(update_view_position)) + } + 0x41 => { + let update_view_distance = UpdateViewDistance::decode(reader)?; + + Ok(Self::UpdateViewDistance(update_view_distance)) + } + 0x43 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x44 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x45 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x46 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x47 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x48 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x49 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x4A => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x4B => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x4C => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x4D => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x42 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4E => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x4F => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x50 => { + let entity_sound_effect = EntitySoundEffect::decode(reader)?; + + Ok(Self::EntitySoundEffect(entity_sound_effect)) + } + 0x52 => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x51 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x53 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x55 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x56 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x58 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x59 => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3C => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x5A => Ok(Self::DeclareRecipes), + 0x5B => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + 0x07 => { + let acknowledge_player_digging = AcknowledgePlayerDigging::decode(reader)?; + + Ok(Self::AcknowledgePlayerDigging(acknowledge_player_digging)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8, difficulty_locked: bool) -> Self { + let difficulty = Difficulty { + difficulty, + difficulty_locked, + }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8, sender: Uuid) -> Self { + let client_bound_chat = ClientBoundChat { + message, + position, + sender, + }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window(window_id: i32, inventory_type: i32, window_title: String) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn open_horse_window(window_id: u8, nb_slots: i32, entity_id: i32) -> Self { + let open_horse_window = OpenHorseWindow { + window_id, + nb_slots, + entity_id, + }; + + Self::OpenHorseWindow(open_horse_window) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk( + x: i32, + z: i32, + ground_up: bool, + ignore_old_data: bool, + bit_map: i32, + heightmaps: CompoundTag, + chunk_data: Vec, + ) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + ignore_old_data, + bit_map, + heightmaps, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f64, + y: f64, + z: f64, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn update_light( + chunk_x: i32, + chunk_z: i32, + trust_edges: bool, + sky_light_mask: i32, + block_light_mask: i32, + empty_sky_light_mask: i32, + empty_block_light_mask: i32, + data: Vec, + ) -> Self { + let update_light = UpdateLight { + chunk_x, + chunk_z, + trust_edges, + sky_light_mask, + block_light_mask, + empty_sky_light_mask, + empty_block_light_mask, + data, + }; + + Self::UpdateLight(update_light) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + previous_game_mode: u8, + dimension_codec: CompoundTag, + dimension: String, + world_name: String, + hashed_seed: i64, + max_players: u8, + view_distance: i32, + reduced_debug_info: bool, + enable_respawn_screen: bool, + is_debug: bool, + is_flat: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + previous_game_mode, + dimension_codec, + dimension, + world_name, + hashed_seed, + max_players, + view_distance, + reduced_debug_info, + enable_respawn_screen, + is_debug, + is_flat, + }; + + Self::JoinGame(join_game) + } + + pub fn map( + item_damage: i32, + scale: i8, + tracking_position: bool, + locked: bool, + columns: i8, + ) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + locked, + columns, + }; + + Self::Map(map) + } + + pub fn trade_list( + window_id: i32, + villager_level: i32, + experience: i32, + is_regular_villager: bool, + can_restock: bool, + ) -> Self { + let trade_list = TradeList { + window_id, + villager_level, + experience, + is_regular_villager, + can_restock, + }; + + Self::TradeList(trade_list) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_book(hand: i32) -> Self { + let open_book = OpenBook { hand }; + + Self::OpenBook(open_book) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn( + dimension: String, + world_name: String, + hashed_seed: i64, + gamemode: u8, + previous_gamemode: u8, + is_debug: bool, + is_flat: bool, + copy_metadata: bool, + ) -> Self { + let respawn = Respawn { + dimension, + world_name, + hashed_seed, + gamemode, + previous_gamemode, + is_debug, + is_flat, + copy_metadata, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn update_view_position(chunk_x: i32, chunk_z: i32) -> Self { + let update_view_position = UpdateViewPosition { chunk_x, chunk_z }; + + Self::UpdateViewPosition(update_view_position) + } + + pub fn update_view_distance(view_distance: i32) -> Self { + let update_view_distance = UpdateViewDistance { view_distance }; + + Self::UpdateViewDistance(update_view_distance) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32) -> Self { + let entity_equipment = EntityEquipment { entity_id }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn entity_sound_effect( + sound_id: i32, + sound_category: i32, + entity_id: i32, + volume: f32, + pitch: f32, + ) -> Self { + let entity_sound_effect = EntitySoundEffect { + sound_id, + sound_category, + entity_id, + volume, + pitch, + }; + + Self::EntitySoundEffect(entity_sound_effect) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags( + block_tags: TagsMap, + item_tags: TagsMap, + fluid_tags: TagsMap, + entity_tags: TagsMap, + ) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + entity_tags, + }; + + Self::Tags(tags) + } + + pub fn acknowledge_player_digging( + location: Position, + block: i32, + status: i32, + successful: bool, + ) -> Self { + let acknowledge_player_digging = AcknowledgePlayerDigging { + location, + block, + status, + successful, + }; + + Self::AcknowledgePlayerDigging(acknowledge_player_digging) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct SetDifficulty { + pub new_difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, + pub sneaking: bool, +} + +#[derive(Packet, Debug)] +pub struct GenerateStructure { + pub location: Position, + #[packet(with = "var_int")] + pub levels: i32, + pub keep_jigsaws: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct LockDifficulty { + pub locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateJigsawBlock { + pub location: Position, + pub name: String, + pub target: String, + pub pool: String, + pub final_state: String, + pub joint_type: String, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + #[packet(with = "var_int")] + pub hand: i32, + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, + pub inside_block: bool, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, + pub difficulty_locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, + pub sender: Uuid, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub inventory_type: i32, + pub window_title: String, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenHorseWindow { + pub window_id: u8, + #[packet(with = "var_int")] + pub nb_slots: i32, + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + pub ignore_old_data: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub heightmaps: CompoundTag, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f64, + pub y: f64, + pub z: f64, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct UpdateLight { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, + pub trust_edges: bool, + #[packet(with = "var_int")] + pub sky_light_mask: i32, + #[packet(with = "var_int")] + pub block_light_mask: i32, + #[packet(with = "var_int")] + pub empty_sky_light_mask: i32, + #[packet(with = "var_int")] + pub empty_block_light_mask: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub previous_game_mode: u8, + pub dimension_codec: CompoundTag, + pub dimension: String, + pub world_name: String, + pub hashed_seed: i64, + pub max_players: u8, + #[packet(with = "var_int")] + pub view_distance: i32, + pub reduced_debug_info: bool, + pub enable_respawn_screen: bool, + pub is_debug: bool, + pub is_flat: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub locked: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct TradeList { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub villager_level: i32, + #[packet(with = "var_int")] + pub experience: i32, + pub is_regular_villager: bool, + pub can_restock: bool, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenBook { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: String, + pub world_name: String, + pub hashed_seed: i64, + pub gamemode: u8, + pub previous_gamemode: u8, + pub is_debug: bool, + pub is_flat: bool, + pub copy_metadata: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewPosition { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewDistance { + #[packet(with = "var_int")] + pub view_distance: i32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct EntitySoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + #[packet(with = "var_int")] + pub entity_id: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, + pub entity_tags: TagsMap, +} + +#[derive(Packet, Debug)] +pub struct AcknowledgePlayerDigging { + pub location: Position, + #[packet(with = "var_int")] + pub block: i32, + #[packet(with = "var_int")] + pub status: i32, + pub successful: bool, +} diff --git a/protocol/src/version/v_1_16/handshake.rs b/protocol/src/version/v_1_16/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_16/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/packet/login.rs b/protocol/src/version/v_1_16/login.rs similarity index 95% rename from protocol/src/packet/login.rs rename to protocol/src/version/v_1_16/login.rs index bb548cd..d29fe54 100644 --- a/protocol/src/packet/login.rs +++ b/protocol/src/version/v_1_16/login.rs @@ -1,19 +1,19 @@ // This file is automatically generated. // It is not intended for manual editing. -use crate::data::chat::Message; use crate::DecodeError; use crate::Decoder; use minecraft_protocol_derive::Packet; use std::io::Read; + use uuid::Uuid; -pub enum LoginServerBoundPacket { +pub enum ServerBoundLoginPacket { LoginStart(LoginStart), EncryptionResponse(EncryptionResponse), LoginPluginResponse(LoginPluginResponse), } -impl LoginServerBoundPacket { +impl ServerBoundLoginPacket { pub fn get_type_id(&self) -> u8 { match self { Self::LoginStart(_) => 0x00, @@ -65,7 +65,7 @@ impl LoginServerBoundPacket { } } -pub enum LoginClientBoundPacket { +pub enum ClientBoundLoginPacket { Disconnect(Disconnect), EncryptionRequest(EncryptionRequest), Success(Success), @@ -73,7 +73,7 @@ pub enum LoginClientBoundPacket { LoginPluginRequest(LoginPluginRequest), } -impl LoginClientBoundPacket { +impl ClientBoundLoginPacket { pub fn get_type_id(&self) -> u8 { match self { Self::Disconnect(_) => 0x00, @@ -115,7 +115,7 @@ impl LoginClientBoundPacket { } } - pub fn disconnect(reason: Message) -> Self { + pub fn disconnect(reason: String) -> Self { let disconnect = Disconnect { reason }; Self::Disconnect(disconnect) @@ -179,7 +179,7 @@ pub struct LoginPluginResponse { #[derive(Packet, Debug)] pub struct Disconnect { - pub reason: Message, + pub reason: String, } #[derive(Packet, Debug)] @@ -191,7 +191,6 @@ pub struct EncryptionRequest { #[derive(Packet, Debug)] pub struct Success { - #[packet(with = "uuid_hyp_str")] pub uuid: Uuid, pub username: String, } diff --git a/protocol/src/version/v_1_16/mod.rs b/protocol/src/version/v_1_16/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_16/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_16/status.rs b/protocol/src/version/v_1_16/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_16/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_16_1/game.rs b/protocol/src/version/v_1_16_1/game.rs new file mode 100644 index 0000000..70250d5 --- /dev/null +++ b/protocol/src/version/v_1_16_1/game.rs @@ -0,0 +1,3607 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + SetDifficulty(SetDifficulty), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + GenerateStructure(GenerateStructure), + ServerBoundKeepAlive(ServerBoundKeepAlive), + LockDifficulty(LockDifficulty), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateJigsawBlock(UpdateJigsawBlock), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::SetDifficulty(_) => 0x02, + Self::EditBook(_) => 0x0C, + Self::QueryEntityNbt(_) => 0x0D, + Self::PickItem(_) => 0x18, + Self::NameItem(_) => 0x1F, + Self::SelectTrade(_) => 0x22, + Self::SetBeaconEffect(_) => 0x23, + Self::UpdateCommandBlock(_) => 0x25, + Self::UpdateCommandBlockMinecart(_) => 0x26, + Self::UpdateStructureBlock(_) => 0x29, + Self::ServerBoundTabComplete(_) => 0x06, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x07, + Self::EnchantItem(_) => 0x08, + Self::WindowClick(_) => 0x09, + Self::ServerBoundCloseWindow(_) => 0x0A, + Self::ServerBoundCustomPayload(_) => 0x0B, + Self::UseEntity(_) => 0x0E, + Self::GenerateStructure(_) => 0x0F, + Self::ServerBoundKeepAlive(_) => 0x10, + Self::LockDifficulty(_) => 0x11, + Self::ServerBoundPosition(_) => 0x12, + Self::PositionLook(_) => 0x13, + Self::Look(_) => 0x14, + Self::Flying(_) => 0x15, + Self::ServerBoundVehicleMove(_) => 0x16, + Self::SteerBoat(_) => 0x17, + Self::CraftRecipeRequest(_) => 0x19, + Self::ServerBoundAbilities(_) => 0x1A, + Self::BlockDig(_) => 0x1B, + Self::EntityAction(_) => 0x1C, + Self::SteerVehicle(_) => 0x1D, + Self::CraftingBookData(_) => 0x1E, + Self::ResourcePackReceive(_) => 0x20, + Self::ServerBoundHeldItemSlot(_) => 0x24, + Self::SetCreativeSlot(_) => 0x27, + Self::UpdateJigsawBlock(_) => 0x28, + Self::UpdateSign(_) => 0x2A, + Self::ArmAnimation(_) => 0x2B, + Self::Spectate(_) => 0x2C, + Self::BlockPlace(_) => 0x2D, + Self::UseItem(_) => 0x2E, + Self::AdvancementTab(_) => 0x21, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x02 => { + let set_difficulty = SetDifficulty::decode(reader)?; + + Ok(Self::SetDifficulty(set_difficulty)) + } + 0x0C => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0D => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x18 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1F => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x22 => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x23 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x25 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x26 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x29 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x06 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x07 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x08 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x09 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x0A => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0B => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0E => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0F => { + let generate_structure = GenerateStructure::decode(reader)?; + + Ok(Self::GenerateStructure(generate_structure)) + } + 0x10 => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x11 => { + let lock_difficulty = LockDifficulty::decode(reader)?; + + Ok(Self::LockDifficulty(lock_difficulty)) + } + 0x12 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x13 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x14 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x15 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x16 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x17 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x19 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x1A => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x1B => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x1C => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1D => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1E => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x20 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x24 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x27 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x28 => { + let update_jigsaw_block = UpdateJigsawBlock::decode(reader)?; + + Ok(Self::UpdateJigsawBlock(update_jigsaw_block)) + } + 0x2A => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x2B => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x2C => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x2D => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2E => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x21 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn set_difficulty(new_difficulty: u8) -> Self { + let set_difficulty = SetDifficulty { new_difficulty }; + + Self::SetDifficulty(set_difficulty) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32, sneaking: bool) -> Self { + let use_entity = UseEntity { + target, + mouse, + sneaking, + }; + + Self::UseEntity(use_entity) + } + + pub fn generate_structure(location: Position, levels: i32, keep_jigsaws: bool) -> Self { + let generate_structure = GenerateStructure { + location, + levels, + keep_jigsaws, + }; + + Self::GenerateStructure(generate_structure) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn lock_difficulty(locked: bool) -> Self { + let lock_difficulty = LockDifficulty { locked }; + + Self::LockDifficulty(lock_difficulty) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8) -> Self { + let server_bound_abilities = ServerBoundAbilities { flags }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_jigsaw_block( + location: Position, + name: String, + target: String, + pool: String, + final_state: String, + joint_type: String, + ) -> Self { + let update_jigsaw_block = UpdateJigsawBlock { + location, + name, + target, + pool, + final_state, + joint_type, + }; + + Self::UpdateJigsawBlock(update_jigsaw_block) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + hand: i32, + location: Position, + direction: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + inside_block: bool, + ) -> Self { + let block_place = BlockPlace { + hand, + location, + direction, + cursor_x, + cursor_y, + cursor_z, + inside_block, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + OpenHorseWindow(OpenHorseWindow), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + UpdateLight(UpdateLight), + JoinGame(JoinGame), + Map(Map), + TradeList(TradeList), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenBook(OpenBook), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + UpdateViewPosition(UpdateViewPosition), + UpdateViewDistance(UpdateViewDistance), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + EntitySoundEffect(EntitySoundEffect), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), + AcknowledgePlayerDigging(AcknowledgePlayerDigging), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityLiving(_) => 0x02, + Self::SpawnEntityPainting(_) => 0x03, + Self::NamedEntitySpawn(_) => 0x04, + Self::Animation(_) => 0x05, + Self::Statistics => 0x06, + Self::Advancements(_) => 0x57, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete(_) => 0x10, + Self::DeclareCommands(_) => 0x11, + Self::FacePlayer(_) => 0x34, + Self::NbtQueryResponse(_) => 0x54, + Self::ClientBoundChat(_) => 0x0E, + Self::MultiBlockChange(_) => 0x0F, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x2E, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::OpenHorseWindow(_) => 0x1F, + Self::ClientBoundKeepAlive(_) => 0x20, + Self::MapChunk(_) => 0x21, + Self::WorldEvent(_) => 0x22, + Self::WorldParticles(_) => 0x23, + Self::UpdateLight(_) => 0x24, + Self::JoinGame(_) => 0x25, + Self::Map(_) => 0x26, + Self::TradeList(_) => 0x27, + Self::RelEntityMove(_) => 0x28, + Self::EntityMoveLook(_) => 0x29, + Self::EntityLook(_) => 0x2A, + Self::Entity(_) => 0x2B, + Self::ClientBoundVehicleMove(_) => 0x2C, + Self::OpenBook(_) => 0x2D, + Self::OpenSignEntity(_) => 0x2F, + Self::CraftRecipeResponse(_) => 0x30, + Self::ClientBoundAbilities(_) => 0x31, + Self::CombatEvent(_) => 0x32, + Self::PlayerInfo(_) => 0x33, + Self::ClientBoundPosition(_) => 0x35, + Self::UnlockRecipes(_) => 0x36, + Self::EntityDestroy => 0x37, + Self::RemoveEntityEffect(_) => 0x38, + Self::ResourcePackSend(_) => 0x39, + Self::Respawn(_) => 0x3A, + Self::EntityHeadRotation(_) => 0x3B, + Self::WorldBorder(_) => 0x3D, + Self::Camera(_) => 0x3E, + Self::ClientBoundHeldItemSlot(_) => 0x3F, + Self::UpdateViewPosition(_) => 0x40, + Self::UpdateViewDistance(_) => 0x41, + Self::ScoreboardDisplayObjective(_) => 0x43, + Self::EntityMetadata(_) => 0x44, + Self::AttachEntity(_) => 0x45, + Self::EntityVelocity(_) => 0x46, + Self::EntityEquipment(_) => 0x47, + Self::Experience(_) => 0x48, + Self::UpdateHealth(_) => 0x49, + Self::ScoreboardObjective(_) => 0x4A, + Self::SetPassengers(_) => 0x4B, + Self::Teams(_) => 0x4C, + Self::ScoreboardScore(_) => 0x4D, + Self::SpawnPosition(_) => 0x42, + Self::UpdateTime(_) => 0x4E, + Self::Title(_) => 0x4F, + Self::EntitySoundEffect(_) => 0x50, + Self::StopSound(_) => 0x52, + Self::SoundEffect(_) => 0x51, + Self::PlayerlistHeader(_) => 0x53, + Self::Collect(_) => 0x55, + Self::EntityTeleport(_) => 0x56, + Self::EntityUpdateAttributes(_) => 0x58, + Self::EntityEffect(_) => 0x59, + Self::SelectAdvancementTab(_) => 0x3C, + Self::DeclareRecipes => 0x5A, + Self::Tags(_) => 0x5B, + Self::AcknowledgePlayerDigging(_) => 0x07, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x03 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x04 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x05 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x06 => Ok(Self::Statistics), + 0x57 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x10 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x11 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x34 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x54 => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0E => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x0F => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x2E => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let open_horse_window = OpenHorseWindow::decode(reader)?; + + Ok(Self::OpenHorseWindow(open_horse_window)) + } + 0x20 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x21 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x22 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x23 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x24 => { + let update_light = UpdateLight::decode(reader)?; + + Ok(Self::UpdateLight(update_light)) + } + 0x25 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x26 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x27 => { + let trade_list = TradeList::decode(reader)?; + + Ok(Self::TradeList(trade_list)) + } + 0x28 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x29 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2A => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x2B => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2C => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2D => { + let open_book = OpenBook::decode(reader)?; + + Ok(Self::OpenBook(open_book)) + } + 0x2F => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x30 => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x31 => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x32 => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x33 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x35 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x36 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x37 => Ok(Self::EntityDestroy), + 0x38 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x39 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x3A => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x3B => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3D => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3E => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3F => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x40 => { + let update_view_position = UpdateViewPosition::decode(reader)?; + + Ok(Self::UpdateViewPosition(update_view_position)) + } + 0x41 => { + let update_view_distance = UpdateViewDistance::decode(reader)?; + + Ok(Self::UpdateViewDistance(update_view_distance)) + } + 0x43 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x44 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x45 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x46 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x47 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x48 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x49 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x4A => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x4B => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x4C => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x4D => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x42 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4E => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x4F => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x50 => { + let entity_sound_effect = EntitySoundEffect::decode(reader)?; + + Ok(Self::EntitySoundEffect(entity_sound_effect)) + } + 0x52 => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x51 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x53 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x55 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x56 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x58 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x59 => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3C => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x5A => Ok(Self::DeclareRecipes), + 0x5B => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + 0x07 => { + let acknowledge_player_digging = AcknowledgePlayerDigging::decode(reader)?; + + Ok(Self::AcknowledgePlayerDigging(acknowledge_player_digging)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8, difficulty_locked: bool) -> Self { + let difficulty = Difficulty { + difficulty, + difficulty_locked, + }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8, sender: Uuid) -> Self { + let client_bound_chat = ClientBoundChat { + message, + position, + sender, + }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window(window_id: i32, inventory_type: i32, window_title: String) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn open_horse_window(window_id: u8, nb_slots: i32, entity_id: i32) -> Self { + let open_horse_window = OpenHorseWindow { + window_id, + nb_slots, + entity_id, + }; + + Self::OpenHorseWindow(open_horse_window) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk( + x: i32, + z: i32, + ground_up: bool, + ignore_old_data: bool, + bit_map: i32, + heightmaps: CompoundTag, + chunk_data: Vec, + ) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + ignore_old_data, + bit_map, + heightmaps, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f64, + y: f64, + z: f64, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn update_light( + chunk_x: i32, + chunk_z: i32, + trust_edges: bool, + sky_light_mask: i32, + block_light_mask: i32, + empty_sky_light_mask: i32, + empty_block_light_mask: i32, + data: Vec, + ) -> Self { + let update_light = UpdateLight { + chunk_x, + chunk_z, + trust_edges, + sky_light_mask, + block_light_mask, + empty_sky_light_mask, + empty_block_light_mask, + data, + }; + + Self::UpdateLight(update_light) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + previous_game_mode: u8, + dimension_codec: CompoundTag, + dimension: String, + world_name: String, + hashed_seed: i64, + max_players: u8, + view_distance: i32, + reduced_debug_info: bool, + enable_respawn_screen: bool, + is_debug: bool, + is_flat: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + previous_game_mode, + dimension_codec, + dimension, + world_name, + hashed_seed, + max_players, + view_distance, + reduced_debug_info, + enable_respawn_screen, + is_debug, + is_flat, + }; + + Self::JoinGame(join_game) + } + + pub fn map( + item_damage: i32, + scale: i8, + tracking_position: bool, + locked: bool, + columns: i8, + ) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + locked, + columns, + }; + + Self::Map(map) + } + + pub fn trade_list( + window_id: i32, + villager_level: i32, + experience: i32, + is_regular_villager: bool, + can_restock: bool, + ) -> Self { + let trade_list = TradeList { + window_id, + villager_level, + experience, + is_regular_villager, + can_restock, + }; + + Self::TradeList(trade_list) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_book(hand: i32) -> Self { + let open_book = OpenBook { hand }; + + Self::OpenBook(open_book) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn( + dimension: String, + world_name: String, + hashed_seed: i64, + gamemode: u8, + previous_gamemode: u8, + is_debug: bool, + is_flat: bool, + copy_metadata: bool, + ) -> Self { + let respawn = Respawn { + dimension, + world_name, + hashed_seed, + gamemode, + previous_gamemode, + is_debug, + is_flat, + copy_metadata, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn update_view_position(chunk_x: i32, chunk_z: i32) -> Self { + let update_view_position = UpdateViewPosition { chunk_x, chunk_z }; + + Self::UpdateViewPosition(update_view_position) + } + + pub fn update_view_distance(view_distance: i32) -> Self { + let update_view_distance = UpdateViewDistance { view_distance }; + + Self::UpdateViewDistance(update_view_distance) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32) -> Self { + let entity_equipment = EntityEquipment { entity_id }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn entity_sound_effect( + sound_id: i32, + sound_category: i32, + entity_id: i32, + volume: f32, + pitch: f32, + ) -> Self { + let entity_sound_effect = EntitySoundEffect { + sound_id, + sound_category, + entity_id, + volume, + pitch, + }; + + Self::EntitySoundEffect(entity_sound_effect) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags( + block_tags: TagsMap, + item_tags: TagsMap, + fluid_tags: TagsMap, + entity_tags: TagsMap, + ) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + entity_tags, + }; + + Self::Tags(tags) + } + + pub fn acknowledge_player_digging( + location: Position, + block: i32, + status: i32, + successful: bool, + ) -> Self { + let acknowledge_player_digging = AcknowledgePlayerDigging { + location, + block, + status, + successful, + }; + + Self::AcknowledgePlayerDigging(acknowledge_player_digging) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct SetDifficulty { + pub new_difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, + pub sneaking: bool, +} + +#[derive(Packet, Debug)] +pub struct GenerateStructure { + pub location: Position, + #[packet(with = "var_int")] + pub levels: i32, + pub keep_jigsaws: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct LockDifficulty { + pub locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateJigsawBlock { + pub location: Position, + pub name: String, + pub target: String, + pub pool: String, + pub final_state: String, + pub joint_type: String, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + #[packet(with = "var_int")] + pub hand: i32, + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, + pub inside_block: bool, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, + pub difficulty_locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, + pub sender: Uuid, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub inventory_type: i32, + pub window_title: String, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenHorseWindow { + pub window_id: u8, + #[packet(with = "var_int")] + pub nb_slots: i32, + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + pub ignore_old_data: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub heightmaps: CompoundTag, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f64, + pub y: f64, + pub z: f64, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct UpdateLight { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, + pub trust_edges: bool, + #[packet(with = "var_int")] + pub sky_light_mask: i32, + #[packet(with = "var_int")] + pub block_light_mask: i32, + #[packet(with = "var_int")] + pub empty_sky_light_mask: i32, + #[packet(with = "var_int")] + pub empty_block_light_mask: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub previous_game_mode: u8, + pub dimension_codec: CompoundTag, + pub dimension: String, + pub world_name: String, + pub hashed_seed: i64, + pub max_players: u8, + #[packet(with = "var_int")] + pub view_distance: i32, + pub reduced_debug_info: bool, + pub enable_respawn_screen: bool, + pub is_debug: bool, + pub is_flat: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub locked: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct TradeList { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub villager_level: i32, + #[packet(with = "var_int")] + pub experience: i32, + pub is_regular_villager: bool, + pub can_restock: bool, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenBook { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: String, + pub world_name: String, + pub hashed_seed: i64, + pub gamemode: u8, + pub previous_gamemode: u8, + pub is_debug: bool, + pub is_flat: bool, + pub copy_metadata: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewPosition { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewDistance { + #[packet(with = "var_int")] + pub view_distance: i32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct EntitySoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + #[packet(with = "var_int")] + pub entity_id: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, + pub entity_tags: TagsMap, +} + +#[derive(Packet, Debug)] +pub struct AcknowledgePlayerDigging { + pub location: Position, + #[packet(with = "var_int")] + pub block: i32, + #[packet(with = "var_int")] + pub status: i32, + pub successful: bool, +} diff --git a/protocol/src/version/v_1_16_1/handshake.rs b/protocol/src/version/v_1_16_1/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_16_1/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_16_1/login.rs b/protocol/src/version/v_1_16_1/login.rs new file mode 100644 index 0000000..d29fe54 --- /dev/null +++ b/protocol/src/version/v_1_16_1/login.rs @@ -0,0 +1,211 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use uuid::Uuid; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: Uuid, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: Uuid, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_16_1/mod.rs b/protocol/src/version/v_1_16_1/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_16_1/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_16_1/status.rs b/protocol/src/version/v_1_16_1/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_16_1/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_16_2/game.rs b/protocol/src/version/v_1_16_2/game.rs new file mode 100644 index 0000000..575196a --- /dev/null +++ b/protocol/src/version/v_1_16_2/game.rs @@ -0,0 +1,3643 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + SetDifficulty(SetDifficulty), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + GenerateStructure(GenerateStructure), + ServerBoundKeepAlive(ServerBoundKeepAlive), + LockDifficulty(LockDifficulty), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + DisplayedRecipe(DisplayedRecipe), + RecipeBook(RecipeBook), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateJigsawBlock(UpdateJigsawBlock), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::SetDifficulty(_) => 0x02, + Self::EditBook(_) => 0x0C, + Self::QueryEntityNbt(_) => 0x0D, + Self::PickItem(_) => 0x18, + Self::NameItem(_) => 0x20, + Self::SelectTrade(_) => 0x23, + Self::SetBeaconEffect(_) => 0x24, + Self::UpdateCommandBlock(_) => 0x26, + Self::UpdateCommandBlockMinecart(_) => 0x27, + Self::UpdateStructureBlock(_) => 0x2A, + Self::ServerBoundTabComplete(_) => 0x06, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x07, + Self::EnchantItem(_) => 0x08, + Self::WindowClick(_) => 0x09, + Self::ServerBoundCloseWindow(_) => 0x0A, + Self::ServerBoundCustomPayload(_) => 0x0B, + Self::UseEntity(_) => 0x0E, + Self::GenerateStructure(_) => 0x0F, + Self::ServerBoundKeepAlive(_) => 0x10, + Self::LockDifficulty(_) => 0x11, + Self::ServerBoundPosition(_) => 0x12, + Self::PositionLook(_) => 0x13, + Self::Look(_) => 0x14, + Self::Flying(_) => 0x15, + Self::ServerBoundVehicleMove(_) => 0x16, + Self::SteerBoat(_) => 0x17, + Self::CraftRecipeRequest(_) => 0x19, + Self::ServerBoundAbilities(_) => 0x1A, + Self::BlockDig(_) => 0x1B, + Self::EntityAction(_) => 0x1C, + Self::SteerVehicle(_) => 0x1D, + Self::DisplayedRecipe(_) => 0x1E, + Self::RecipeBook(_) => 0x1F, + Self::ResourcePackReceive(_) => 0x21, + Self::ServerBoundHeldItemSlot(_) => 0x25, + Self::SetCreativeSlot(_) => 0x28, + Self::UpdateJigsawBlock(_) => 0x29, + Self::UpdateSign(_) => 0x2B, + Self::ArmAnimation(_) => 0x2C, + Self::Spectate(_) => 0x2D, + Self::BlockPlace(_) => 0x2E, + Self::UseItem(_) => 0x2F, + Self::AdvancementTab(_) => 0x22, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x02 => { + let set_difficulty = SetDifficulty::decode(reader)?; + + Ok(Self::SetDifficulty(set_difficulty)) + } + 0x0C => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0D => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x18 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x20 => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x23 => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x24 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x26 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x27 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x2A => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x06 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x07 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x08 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x09 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x0A => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0B => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0E => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0F => { + let generate_structure = GenerateStructure::decode(reader)?; + + Ok(Self::GenerateStructure(generate_structure)) + } + 0x10 => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x11 => { + let lock_difficulty = LockDifficulty::decode(reader)?; + + Ok(Self::LockDifficulty(lock_difficulty)) + } + 0x12 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x13 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x14 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x15 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x16 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x17 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x19 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x1A => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x1B => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x1C => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1D => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1E => { + let displayed_recipe = DisplayedRecipe::decode(reader)?; + + Ok(Self::DisplayedRecipe(displayed_recipe)) + } + 0x1F => { + let recipe_book = RecipeBook::decode(reader)?; + + Ok(Self::RecipeBook(recipe_book)) + } + 0x21 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x25 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x28 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x29 => { + let update_jigsaw_block = UpdateJigsawBlock::decode(reader)?; + + Ok(Self::UpdateJigsawBlock(update_jigsaw_block)) + } + 0x2B => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x2C => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x2D => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x2E => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2F => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x22 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn set_difficulty(new_difficulty: u8) -> Self { + let set_difficulty = SetDifficulty { new_difficulty }; + + Self::SetDifficulty(set_difficulty) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32, sneaking: bool) -> Self { + let use_entity = UseEntity { + target, + mouse, + sneaking, + }; + + Self::UseEntity(use_entity) + } + + pub fn generate_structure(location: Position, levels: i32, keep_jigsaws: bool) -> Self { + let generate_structure = GenerateStructure { + location, + levels, + keep_jigsaws, + }; + + Self::GenerateStructure(generate_structure) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn lock_difficulty(locked: bool) -> Self { + let lock_difficulty = LockDifficulty { locked }; + + Self::LockDifficulty(lock_difficulty) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8) -> Self { + let server_bound_abilities = ServerBoundAbilities { flags }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn displayed_recipe(recipe_id: String) -> Self { + let displayed_recipe = DisplayedRecipe { recipe_id }; + + Self::DisplayedRecipe(displayed_recipe) + } + + pub fn recipe_book(book_id: i32, book_open: bool, filter_active: bool) -> Self { + let recipe_book = RecipeBook { + book_id, + book_open, + filter_active, + }; + + Self::RecipeBook(recipe_book) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_jigsaw_block( + location: Position, + name: String, + target: String, + pool: String, + final_state: String, + joint_type: String, + ) -> Self { + let update_jigsaw_block = UpdateJigsawBlock { + location, + name, + target, + pool, + final_state, + joint_type, + }; + + Self::UpdateJigsawBlock(update_jigsaw_block) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + hand: i32, + location: Position, + direction: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + inside_block: bool, + ) -> Self { + let block_place = BlockPlace { + hand, + location, + direction, + cursor_x, + cursor_y, + cursor_z, + inside_block, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + OpenHorseWindow(OpenHorseWindow), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + UpdateLight(UpdateLight), + JoinGame(JoinGame), + Map(Map), + TradeList(TradeList), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenBook(OpenBook), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + UpdateViewPosition(UpdateViewPosition), + UpdateViewDistance(UpdateViewDistance), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + EntitySoundEffect(EntitySoundEffect), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), + AcknowledgePlayerDigging(AcknowledgePlayerDigging), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityLiving(_) => 0x02, + Self::SpawnEntityPainting(_) => 0x03, + Self::NamedEntitySpawn(_) => 0x04, + Self::Animation(_) => 0x05, + Self::Statistics => 0x06, + Self::Advancements(_) => 0x57, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete(_) => 0x0F, + Self::DeclareCommands(_) => 0x10, + Self::FacePlayer(_) => 0x33, + Self::NbtQueryResponse(_) => 0x54, + Self::ClientBoundChat(_) => 0x0E, + Self::MultiBlockChange(_) => 0x3B, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::OpenWindow(_) => 0x2D, + Self::WindowItems(_) => 0x13, + Self::CraftProgressBar(_) => 0x14, + Self::SetSlot(_) => 0x15, + Self::SetCooldown(_) => 0x16, + Self::ClientBoundCustomPayload(_) => 0x17, + Self::NamedSoundEffect(_) => 0x18, + Self::KickDisconnect(_) => 0x19, + Self::EntityStatus(_) => 0x1A, + Self::Explosion(_) => 0x1B, + Self::UnloadChunk(_) => 0x1C, + Self::GameStateChange(_) => 0x1D, + Self::OpenHorseWindow(_) => 0x1E, + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::MapChunk(_) => 0x20, + Self::WorldEvent(_) => 0x21, + Self::WorldParticles(_) => 0x22, + Self::UpdateLight(_) => 0x23, + Self::JoinGame(_) => 0x24, + Self::Map(_) => 0x25, + Self::TradeList(_) => 0x26, + Self::RelEntityMove(_) => 0x27, + Self::EntityMoveLook(_) => 0x28, + Self::EntityLook(_) => 0x29, + Self::Entity(_) => 0x2A, + Self::ClientBoundVehicleMove(_) => 0x2B, + Self::OpenBook(_) => 0x2C, + Self::OpenSignEntity(_) => 0x2E, + Self::CraftRecipeResponse(_) => 0x2F, + Self::ClientBoundAbilities(_) => 0x30, + Self::CombatEvent(_) => 0x31, + Self::PlayerInfo(_) => 0x32, + Self::ClientBoundPosition(_) => 0x34, + Self::UnlockRecipes(_) => 0x35, + Self::EntityDestroy => 0x36, + Self::RemoveEntityEffect(_) => 0x37, + Self::ResourcePackSend(_) => 0x38, + Self::Respawn(_) => 0x39, + Self::EntityHeadRotation(_) => 0x3A, + Self::WorldBorder(_) => 0x3D, + Self::Camera(_) => 0x3E, + Self::ClientBoundHeldItemSlot(_) => 0x3F, + Self::UpdateViewPosition(_) => 0x40, + Self::UpdateViewDistance(_) => 0x41, + Self::ScoreboardDisplayObjective(_) => 0x43, + Self::EntityMetadata(_) => 0x44, + Self::AttachEntity(_) => 0x45, + Self::EntityVelocity(_) => 0x46, + Self::EntityEquipment(_) => 0x47, + Self::Experience(_) => 0x48, + Self::UpdateHealth(_) => 0x49, + Self::ScoreboardObjective(_) => 0x4A, + Self::SetPassengers(_) => 0x4B, + Self::Teams(_) => 0x4C, + Self::ScoreboardScore(_) => 0x4D, + Self::SpawnPosition(_) => 0x42, + Self::UpdateTime(_) => 0x4E, + Self::Title(_) => 0x4F, + Self::EntitySoundEffect(_) => 0x50, + Self::StopSound(_) => 0x52, + Self::SoundEffect(_) => 0x51, + Self::PlayerlistHeader(_) => 0x53, + Self::Collect(_) => 0x55, + Self::EntityTeleport(_) => 0x56, + Self::EntityUpdateAttributes(_) => 0x58, + Self::EntityEffect(_) => 0x59, + Self::SelectAdvancementTab(_) => 0x3C, + Self::DeclareRecipes => 0x5A, + Self::Tags(_) => 0x5B, + Self::AcknowledgePlayerDigging(_) => 0x07, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x03 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x04 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x05 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x06 => Ok(Self::Statistics), + 0x57 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0F => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x10 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x33 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x54 => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0E => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x3B => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x2D => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x13 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x14 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x15 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x16 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x17 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x18 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x19 => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1A => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1B => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1C => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1D => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1E => { + let open_horse_window = OpenHorseWindow::decode(reader)?; + + Ok(Self::OpenHorseWindow(open_horse_window)) + } + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x23 => { + let update_light = UpdateLight::decode(reader)?; + + Ok(Self::UpdateLight(update_light)) + } + 0x24 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x25 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x26 => { + let trade_list = TradeList::decode(reader)?; + + Ok(Self::TradeList(trade_list)) + } + 0x27 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x28 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x29 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x2A => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2B => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2C => { + let open_book = OpenBook::decode(reader)?; + + Ok(Self::OpenBook(open_book)) + } + 0x2E => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2F => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x30 => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x31 => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x32 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x34 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x35 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x36 => Ok(Self::EntityDestroy), + 0x37 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x38 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x39 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x3A => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3D => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3E => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3F => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x40 => { + let update_view_position = UpdateViewPosition::decode(reader)?; + + Ok(Self::UpdateViewPosition(update_view_position)) + } + 0x41 => { + let update_view_distance = UpdateViewDistance::decode(reader)?; + + Ok(Self::UpdateViewDistance(update_view_distance)) + } + 0x43 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x44 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x45 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x46 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x47 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x48 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x49 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x4A => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x4B => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x4C => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x4D => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x42 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4E => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x4F => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x50 => { + let entity_sound_effect = EntitySoundEffect::decode(reader)?; + + Ok(Self::EntitySoundEffect(entity_sound_effect)) + } + 0x52 => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x51 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x53 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x55 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x56 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x58 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x59 => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3C => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x5A => Ok(Self::DeclareRecipes), + 0x5B => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + 0x07 => { + let acknowledge_player_digging = AcknowledgePlayerDigging::decode(reader)?; + + Ok(Self::AcknowledgePlayerDigging(acknowledge_player_digging)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8, difficulty_locked: bool) -> Self { + let difficulty = Difficulty { + difficulty, + difficulty_locked, + }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8, sender: Uuid) -> Self { + let client_bound_chat = ClientBoundChat { + message, + position, + sender, + }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(not_trust_edges: bool) -> Self { + let multi_block_change = MultiBlockChange { not_trust_edges }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window(window_id: i32, inventory_type: i32, window_title: String) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn open_horse_window(window_id: u8, nb_slots: i32, entity_id: i32) -> Self { + let open_horse_window = OpenHorseWindow { + window_id, + nb_slots, + entity_id, + }; + + Self::OpenHorseWindow(open_horse_window) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk( + x: i32, + z: i32, + ground_up: bool, + bit_map: i32, + heightmaps: CompoundTag, + chunk_data: Vec, + ) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + heightmaps, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f64, + y: f64, + z: f64, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn update_light( + chunk_x: i32, + chunk_z: i32, + trust_edges: bool, + sky_light_mask: i32, + block_light_mask: i32, + empty_sky_light_mask: i32, + empty_block_light_mask: i32, + data: Vec, + ) -> Self { + let update_light = UpdateLight { + chunk_x, + chunk_z, + trust_edges, + sky_light_mask, + block_light_mask, + empty_sky_light_mask, + empty_block_light_mask, + data, + }; + + Self::UpdateLight(update_light) + } + + pub fn join_game( + entity_id: i32, + is_hardcore: bool, + game_mode: u8, + previous_game_mode: u8, + dimension_codec: CompoundTag, + dimension: CompoundTag, + world_name: String, + hashed_seed: i64, + max_players: i32, + view_distance: i32, + reduced_debug_info: bool, + enable_respawn_screen: bool, + is_debug: bool, + is_flat: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + is_hardcore, + game_mode, + previous_game_mode, + dimension_codec, + dimension, + world_name, + hashed_seed, + max_players, + view_distance, + reduced_debug_info, + enable_respawn_screen, + is_debug, + is_flat, + }; + + Self::JoinGame(join_game) + } + + pub fn map( + item_damage: i32, + scale: i8, + tracking_position: bool, + locked: bool, + columns: i8, + ) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + locked, + columns, + }; + + Self::Map(map) + } + + pub fn trade_list( + window_id: i32, + villager_level: i32, + experience: i32, + is_regular_villager: bool, + can_restock: bool, + ) -> Self { + let trade_list = TradeList { + window_id, + villager_level, + experience, + is_regular_villager, + can_restock, + }; + + Self::TradeList(trade_list) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_book(hand: i32) -> Self { + let open_book = OpenBook { hand }; + + Self::OpenBook(open_book) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + blast_furnace_open: bool, + filtering_blast_furnace: bool, + smoker_book_open: bool, + filtering_smoker: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + blast_furnace_open, + filtering_blast_furnace, + smoker_book_open, + filtering_smoker, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn( + dimension: CompoundTag, + world_name: String, + hashed_seed: i64, + gamemode: u8, + previous_gamemode: u8, + is_debug: bool, + is_flat: bool, + copy_metadata: bool, + ) -> Self { + let respawn = Respawn { + dimension, + world_name, + hashed_seed, + gamemode, + previous_gamemode, + is_debug, + is_flat, + copy_metadata, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn update_view_position(chunk_x: i32, chunk_z: i32) -> Self { + let update_view_position = UpdateViewPosition { chunk_x, chunk_z }; + + Self::UpdateViewPosition(update_view_position) + } + + pub fn update_view_distance(view_distance: i32) -> Self { + let update_view_distance = UpdateViewDistance { view_distance }; + + Self::UpdateViewDistance(update_view_distance) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32) -> Self { + let entity_equipment = EntityEquipment { entity_id }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn entity_sound_effect( + sound_id: i32, + sound_category: i32, + entity_id: i32, + volume: f32, + pitch: f32, + ) -> Self { + let entity_sound_effect = EntitySoundEffect { + sound_id, + sound_category, + entity_id, + volume, + pitch, + }; + + Self::EntitySoundEffect(entity_sound_effect) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags( + block_tags: TagsMap, + item_tags: TagsMap, + fluid_tags: TagsMap, + entity_tags: TagsMap, + ) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + entity_tags, + }; + + Self::Tags(tags) + } + + pub fn acknowledge_player_digging( + location: Position, + block: i32, + status: i32, + successful: bool, + ) -> Self { + let acknowledge_player_digging = AcknowledgePlayerDigging { + location, + block, + status, + successful, + }; + + Self::AcknowledgePlayerDigging(acknowledge_player_digging) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct SetDifficulty { + pub new_difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, + pub sneaking: bool, +} + +#[derive(Packet, Debug)] +pub struct GenerateStructure { + pub location: Position, + #[packet(with = "var_int")] + pub levels: i32, + pub keep_jigsaws: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct LockDifficulty { + pub locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct DisplayedRecipe { + pub recipe_id: String, +} + +#[derive(Packet, Debug)] +pub struct RecipeBook { + #[packet(with = "var_int")] + pub book_id: i32, + pub book_open: bool, + pub filter_active: bool, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateJigsawBlock { + pub location: Position, + pub name: String, + pub target: String, + pub pool: String, + pub final_state: String, + pub joint_type: String, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + #[packet(with = "var_int")] + pub hand: i32, + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, + pub inside_block: bool, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, + pub difficulty_locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, + pub sender: Uuid, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub not_trust_edges: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub inventory_type: i32, + pub window_title: String, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenHorseWindow { + pub window_id: u8, + #[packet(with = "var_int")] + pub nb_slots: i32, + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub heightmaps: CompoundTag, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f64, + pub y: f64, + pub z: f64, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct UpdateLight { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, + pub trust_edges: bool, + #[packet(with = "var_int")] + pub sky_light_mask: i32, + #[packet(with = "var_int")] + pub block_light_mask: i32, + #[packet(with = "var_int")] + pub empty_sky_light_mask: i32, + #[packet(with = "var_int")] + pub empty_block_light_mask: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub is_hardcore: bool, + pub game_mode: u8, + pub previous_game_mode: u8, + pub dimension_codec: CompoundTag, + pub dimension: CompoundTag, + pub world_name: String, + pub hashed_seed: i64, + #[packet(with = "var_int")] + pub max_players: i32, + #[packet(with = "var_int")] + pub view_distance: i32, + pub reduced_debug_info: bool, + pub enable_respawn_screen: bool, + pub is_debug: bool, + pub is_flat: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub locked: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct TradeList { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub villager_level: i32, + #[packet(with = "var_int")] + pub experience: i32, + pub is_regular_villager: bool, + pub can_restock: bool, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenBook { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, + pub blast_furnace_open: bool, + pub filtering_blast_furnace: bool, + pub smoker_book_open: bool, + pub filtering_smoker: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: CompoundTag, + pub world_name: String, + pub hashed_seed: i64, + pub gamemode: u8, + pub previous_gamemode: u8, + pub is_debug: bool, + pub is_flat: bool, + pub copy_metadata: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewPosition { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewDistance { + #[packet(with = "var_int")] + pub view_distance: i32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct EntitySoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + #[packet(with = "var_int")] + pub entity_id: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, + pub entity_tags: TagsMap, +} + +#[derive(Packet, Debug)] +pub struct AcknowledgePlayerDigging { + pub location: Position, + #[packet(with = "var_int")] + pub block: i32, + #[packet(with = "var_int")] + pub status: i32, + pub successful: bool, +} diff --git a/protocol/src/version/v_1_16_2/handshake.rs b/protocol/src/version/v_1_16_2/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_16_2/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_16_2/login.rs b/protocol/src/version/v_1_16_2/login.rs new file mode 100644 index 0000000..d29fe54 --- /dev/null +++ b/protocol/src/version/v_1_16_2/login.rs @@ -0,0 +1,211 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use uuid::Uuid; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: Uuid, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: Uuid, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_16_2/mod.rs b/protocol/src/version/v_1_16_2/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_16_2/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_16_2/status.rs b/protocol/src/version/v_1_16_2/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_16_2/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_16_rc1/game.rs b/protocol/src/version/v_1_16_rc1/game.rs new file mode 100644 index 0000000..70250d5 --- /dev/null +++ b/protocol/src/version/v_1_16_rc1/game.rs @@ -0,0 +1,3607 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + SetDifficulty(SetDifficulty), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + GenerateStructure(GenerateStructure), + ServerBoundKeepAlive(ServerBoundKeepAlive), + LockDifficulty(LockDifficulty), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateJigsawBlock(UpdateJigsawBlock), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::SetDifficulty(_) => 0x02, + Self::EditBook(_) => 0x0C, + Self::QueryEntityNbt(_) => 0x0D, + Self::PickItem(_) => 0x18, + Self::NameItem(_) => 0x1F, + Self::SelectTrade(_) => 0x22, + Self::SetBeaconEffect(_) => 0x23, + Self::UpdateCommandBlock(_) => 0x25, + Self::UpdateCommandBlockMinecart(_) => 0x26, + Self::UpdateStructureBlock(_) => 0x29, + Self::ServerBoundTabComplete(_) => 0x06, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x07, + Self::EnchantItem(_) => 0x08, + Self::WindowClick(_) => 0x09, + Self::ServerBoundCloseWindow(_) => 0x0A, + Self::ServerBoundCustomPayload(_) => 0x0B, + Self::UseEntity(_) => 0x0E, + Self::GenerateStructure(_) => 0x0F, + Self::ServerBoundKeepAlive(_) => 0x10, + Self::LockDifficulty(_) => 0x11, + Self::ServerBoundPosition(_) => 0x12, + Self::PositionLook(_) => 0x13, + Self::Look(_) => 0x14, + Self::Flying(_) => 0x15, + Self::ServerBoundVehicleMove(_) => 0x16, + Self::SteerBoat(_) => 0x17, + Self::CraftRecipeRequest(_) => 0x19, + Self::ServerBoundAbilities(_) => 0x1A, + Self::BlockDig(_) => 0x1B, + Self::EntityAction(_) => 0x1C, + Self::SteerVehicle(_) => 0x1D, + Self::CraftingBookData(_) => 0x1E, + Self::ResourcePackReceive(_) => 0x20, + Self::ServerBoundHeldItemSlot(_) => 0x24, + Self::SetCreativeSlot(_) => 0x27, + Self::UpdateJigsawBlock(_) => 0x28, + Self::UpdateSign(_) => 0x2A, + Self::ArmAnimation(_) => 0x2B, + Self::Spectate(_) => 0x2C, + Self::BlockPlace(_) => 0x2D, + Self::UseItem(_) => 0x2E, + Self::AdvancementTab(_) => 0x21, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x02 => { + let set_difficulty = SetDifficulty::decode(reader)?; + + Ok(Self::SetDifficulty(set_difficulty)) + } + 0x0C => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0D => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x18 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1F => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x22 => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x23 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x25 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x26 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x29 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x06 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x07 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x08 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x09 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x0A => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0B => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0E => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0F => { + let generate_structure = GenerateStructure::decode(reader)?; + + Ok(Self::GenerateStructure(generate_structure)) + } + 0x10 => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x11 => { + let lock_difficulty = LockDifficulty::decode(reader)?; + + Ok(Self::LockDifficulty(lock_difficulty)) + } + 0x12 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x13 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x14 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x15 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x16 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x17 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x19 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x1A => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x1B => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x1C => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1D => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1E => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x20 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x24 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x27 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x28 => { + let update_jigsaw_block = UpdateJigsawBlock::decode(reader)?; + + Ok(Self::UpdateJigsawBlock(update_jigsaw_block)) + } + 0x2A => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x2B => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x2C => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x2D => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2E => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x21 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn set_difficulty(new_difficulty: u8) -> Self { + let set_difficulty = SetDifficulty { new_difficulty }; + + Self::SetDifficulty(set_difficulty) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32, sneaking: bool) -> Self { + let use_entity = UseEntity { + target, + mouse, + sneaking, + }; + + Self::UseEntity(use_entity) + } + + pub fn generate_structure(location: Position, levels: i32, keep_jigsaws: bool) -> Self { + let generate_structure = GenerateStructure { + location, + levels, + keep_jigsaws, + }; + + Self::GenerateStructure(generate_structure) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn lock_difficulty(locked: bool) -> Self { + let lock_difficulty = LockDifficulty { locked }; + + Self::LockDifficulty(lock_difficulty) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8) -> Self { + let server_bound_abilities = ServerBoundAbilities { flags }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_jigsaw_block( + location: Position, + name: String, + target: String, + pool: String, + final_state: String, + joint_type: String, + ) -> Self { + let update_jigsaw_block = UpdateJigsawBlock { + location, + name, + target, + pool, + final_state, + joint_type, + }; + + Self::UpdateJigsawBlock(update_jigsaw_block) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + hand: i32, + location: Position, + direction: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + inside_block: bool, + ) -> Self { + let block_place = BlockPlace { + hand, + location, + direction, + cursor_x, + cursor_y, + cursor_z, + inside_block, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + OpenHorseWindow(OpenHorseWindow), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + UpdateLight(UpdateLight), + JoinGame(JoinGame), + Map(Map), + TradeList(TradeList), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenBook(OpenBook), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + UpdateViewPosition(UpdateViewPosition), + UpdateViewDistance(UpdateViewDistance), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + EntitySoundEffect(EntitySoundEffect), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), + AcknowledgePlayerDigging(AcknowledgePlayerDigging), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityLiving(_) => 0x02, + Self::SpawnEntityPainting(_) => 0x03, + Self::NamedEntitySpawn(_) => 0x04, + Self::Animation(_) => 0x05, + Self::Statistics => 0x06, + Self::Advancements(_) => 0x57, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete(_) => 0x10, + Self::DeclareCommands(_) => 0x11, + Self::FacePlayer(_) => 0x34, + Self::NbtQueryResponse(_) => 0x54, + Self::ClientBoundChat(_) => 0x0E, + Self::MultiBlockChange(_) => 0x0F, + Self::ClientBoundTransaction(_) => 0x12, + Self::ClientBoundCloseWindow(_) => 0x13, + Self::OpenWindow(_) => 0x2E, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::OpenHorseWindow(_) => 0x1F, + Self::ClientBoundKeepAlive(_) => 0x20, + Self::MapChunk(_) => 0x21, + Self::WorldEvent(_) => 0x22, + Self::WorldParticles(_) => 0x23, + Self::UpdateLight(_) => 0x24, + Self::JoinGame(_) => 0x25, + Self::Map(_) => 0x26, + Self::TradeList(_) => 0x27, + Self::RelEntityMove(_) => 0x28, + Self::EntityMoveLook(_) => 0x29, + Self::EntityLook(_) => 0x2A, + Self::Entity(_) => 0x2B, + Self::ClientBoundVehicleMove(_) => 0x2C, + Self::OpenBook(_) => 0x2D, + Self::OpenSignEntity(_) => 0x2F, + Self::CraftRecipeResponse(_) => 0x30, + Self::ClientBoundAbilities(_) => 0x31, + Self::CombatEvent(_) => 0x32, + Self::PlayerInfo(_) => 0x33, + Self::ClientBoundPosition(_) => 0x35, + Self::UnlockRecipes(_) => 0x36, + Self::EntityDestroy => 0x37, + Self::RemoveEntityEffect(_) => 0x38, + Self::ResourcePackSend(_) => 0x39, + Self::Respawn(_) => 0x3A, + Self::EntityHeadRotation(_) => 0x3B, + Self::WorldBorder(_) => 0x3D, + Self::Camera(_) => 0x3E, + Self::ClientBoundHeldItemSlot(_) => 0x3F, + Self::UpdateViewPosition(_) => 0x40, + Self::UpdateViewDistance(_) => 0x41, + Self::ScoreboardDisplayObjective(_) => 0x43, + Self::EntityMetadata(_) => 0x44, + Self::AttachEntity(_) => 0x45, + Self::EntityVelocity(_) => 0x46, + Self::EntityEquipment(_) => 0x47, + Self::Experience(_) => 0x48, + Self::UpdateHealth(_) => 0x49, + Self::ScoreboardObjective(_) => 0x4A, + Self::SetPassengers(_) => 0x4B, + Self::Teams(_) => 0x4C, + Self::ScoreboardScore(_) => 0x4D, + Self::SpawnPosition(_) => 0x42, + Self::UpdateTime(_) => 0x4E, + Self::Title(_) => 0x4F, + Self::EntitySoundEffect(_) => 0x50, + Self::StopSound(_) => 0x52, + Self::SoundEffect(_) => 0x51, + Self::PlayerlistHeader(_) => 0x53, + Self::Collect(_) => 0x55, + Self::EntityTeleport(_) => 0x56, + Self::EntityUpdateAttributes(_) => 0x58, + Self::EntityEffect(_) => 0x59, + Self::SelectAdvancementTab(_) => 0x3C, + Self::DeclareRecipes => 0x5A, + Self::Tags(_) => 0x5B, + Self::AcknowledgePlayerDigging(_) => 0x07, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x03 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x04 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x05 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x06 => Ok(Self::Statistics), + 0x57 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x10 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x11 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x34 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x54 => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0E => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x0F => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x12 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x13 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x2E => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let open_horse_window = OpenHorseWindow::decode(reader)?; + + Ok(Self::OpenHorseWindow(open_horse_window)) + } + 0x20 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x21 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x22 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x23 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x24 => { + let update_light = UpdateLight::decode(reader)?; + + Ok(Self::UpdateLight(update_light)) + } + 0x25 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x26 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x27 => { + let trade_list = TradeList::decode(reader)?; + + Ok(Self::TradeList(trade_list)) + } + 0x28 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x29 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2A => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x2B => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2C => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2D => { + let open_book = OpenBook::decode(reader)?; + + Ok(Self::OpenBook(open_book)) + } + 0x2F => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x30 => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x31 => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x32 => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x33 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x35 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x36 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x37 => Ok(Self::EntityDestroy), + 0x38 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x39 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x3A => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x3B => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3D => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3E => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x3F => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x40 => { + let update_view_position = UpdateViewPosition::decode(reader)?; + + Ok(Self::UpdateViewPosition(update_view_position)) + } + 0x41 => { + let update_view_distance = UpdateViewDistance::decode(reader)?; + + Ok(Self::UpdateViewDistance(update_view_distance)) + } + 0x43 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x44 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x45 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x46 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x47 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x48 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x49 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x4A => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x4B => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x4C => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x4D => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x42 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4E => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x4F => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x50 => { + let entity_sound_effect = EntitySoundEffect::decode(reader)?; + + Ok(Self::EntitySoundEffect(entity_sound_effect)) + } + 0x52 => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x51 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x53 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x55 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x56 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x58 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x59 => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3C => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x5A => Ok(Self::DeclareRecipes), + 0x5B => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + 0x07 => { + let acknowledge_player_digging = AcknowledgePlayerDigging::decode(reader)?; + + Ok(Self::AcknowledgePlayerDigging(acknowledge_player_digging)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8, difficulty_locked: bool) -> Self { + let difficulty = Difficulty { + difficulty, + difficulty_locked, + }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8, sender: Uuid) -> Self { + let client_bound_chat = ClientBoundChat { + message, + position, + sender, + }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window(window_id: i32, inventory_type: i32, window_title: String) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn open_horse_window(window_id: u8, nb_slots: i32, entity_id: i32) -> Self { + let open_horse_window = OpenHorseWindow { + window_id, + nb_slots, + entity_id, + }; + + Self::OpenHorseWindow(open_horse_window) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk( + x: i32, + z: i32, + ground_up: bool, + ignore_old_data: bool, + bit_map: i32, + heightmaps: CompoundTag, + chunk_data: Vec, + ) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + ignore_old_data, + bit_map, + heightmaps, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f64, + y: f64, + z: f64, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn update_light( + chunk_x: i32, + chunk_z: i32, + trust_edges: bool, + sky_light_mask: i32, + block_light_mask: i32, + empty_sky_light_mask: i32, + empty_block_light_mask: i32, + data: Vec, + ) -> Self { + let update_light = UpdateLight { + chunk_x, + chunk_z, + trust_edges, + sky_light_mask, + block_light_mask, + empty_sky_light_mask, + empty_block_light_mask, + data, + }; + + Self::UpdateLight(update_light) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + previous_game_mode: u8, + dimension_codec: CompoundTag, + dimension: String, + world_name: String, + hashed_seed: i64, + max_players: u8, + view_distance: i32, + reduced_debug_info: bool, + enable_respawn_screen: bool, + is_debug: bool, + is_flat: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + previous_game_mode, + dimension_codec, + dimension, + world_name, + hashed_seed, + max_players, + view_distance, + reduced_debug_info, + enable_respawn_screen, + is_debug, + is_flat, + }; + + Self::JoinGame(join_game) + } + + pub fn map( + item_damage: i32, + scale: i8, + tracking_position: bool, + locked: bool, + columns: i8, + ) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + locked, + columns, + }; + + Self::Map(map) + } + + pub fn trade_list( + window_id: i32, + villager_level: i32, + experience: i32, + is_regular_villager: bool, + can_restock: bool, + ) -> Self { + let trade_list = TradeList { + window_id, + villager_level, + experience, + is_regular_villager, + can_restock, + }; + + Self::TradeList(trade_list) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_book(hand: i32) -> Self { + let open_book = OpenBook { hand }; + + Self::OpenBook(open_book) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn( + dimension: String, + world_name: String, + hashed_seed: i64, + gamemode: u8, + previous_gamemode: u8, + is_debug: bool, + is_flat: bool, + copy_metadata: bool, + ) -> Self { + let respawn = Respawn { + dimension, + world_name, + hashed_seed, + gamemode, + previous_gamemode, + is_debug, + is_flat, + copy_metadata, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn update_view_position(chunk_x: i32, chunk_z: i32) -> Self { + let update_view_position = UpdateViewPosition { chunk_x, chunk_z }; + + Self::UpdateViewPosition(update_view_position) + } + + pub fn update_view_distance(view_distance: i32) -> Self { + let update_view_distance = UpdateViewDistance { view_distance }; + + Self::UpdateViewDistance(update_view_distance) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32) -> Self { + let entity_equipment = EntityEquipment { entity_id }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn entity_sound_effect( + sound_id: i32, + sound_category: i32, + entity_id: i32, + volume: f32, + pitch: f32, + ) -> Self { + let entity_sound_effect = EntitySoundEffect { + sound_id, + sound_category, + entity_id, + volume, + pitch, + }; + + Self::EntitySoundEffect(entity_sound_effect) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags( + block_tags: TagsMap, + item_tags: TagsMap, + fluid_tags: TagsMap, + entity_tags: TagsMap, + ) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + entity_tags, + }; + + Self::Tags(tags) + } + + pub fn acknowledge_player_digging( + location: Position, + block: i32, + status: i32, + successful: bool, + ) -> Self { + let acknowledge_player_digging = AcknowledgePlayerDigging { + location, + block, + status, + successful, + }; + + Self::AcknowledgePlayerDigging(acknowledge_player_digging) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct SetDifficulty { + pub new_difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, + pub sneaking: bool, +} + +#[derive(Packet, Debug)] +pub struct GenerateStructure { + pub location: Position, + #[packet(with = "var_int")] + pub levels: i32, + pub keep_jigsaws: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct LockDifficulty { + pub locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateJigsawBlock { + pub location: Position, + pub name: String, + pub target: String, + pub pool: String, + pub final_state: String, + pub joint_type: String, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + #[packet(with = "var_int")] + pub hand: i32, + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, + pub inside_block: bool, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, + pub difficulty_locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, + pub sender: Uuid, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub inventory_type: i32, + pub window_title: String, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenHorseWindow { + pub window_id: u8, + #[packet(with = "var_int")] + pub nb_slots: i32, + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + pub ignore_old_data: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub heightmaps: CompoundTag, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f64, + pub y: f64, + pub z: f64, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct UpdateLight { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, + pub trust_edges: bool, + #[packet(with = "var_int")] + pub sky_light_mask: i32, + #[packet(with = "var_int")] + pub block_light_mask: i32, + #[packet(with = "var_int")] + pub empty_sky_light_mask: i32, + #[packet(with = "var_int")] + pub empty_block_light_mask: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub previous_game_mode: u8, + pub dimension_codec: CompoundTag, + pub dimension: String, + pub world_name: String, + pub hashed_seed: i64, + pub max_players: u8, + #[packet(with = "var_int")] + pub view_distance: i32, + pub reduced_debug_info: bool, + pub enable_respawn_screen: bool, + pub is_debug: bool, + pub is_flat: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub locked: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct TradeList { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub villager_level: i32, + #[packet(with = "var_int")] + pub experience: i32, + pub is_regular_villager: bool, + pub can_restock: bool, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenBook { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: String, + pub world_name: String, + pub hashed_seed: i64, + pub gamemode: u8, + pub previous_gamemode: u8, + pub is_debug: bool, + pub is_flat: bool, + pub copy_metadata: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewPosition { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewDistance { + #[packet(with = "var_int")] + pub view_distance: i32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct EntitySoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + #[packet(with = "var_int")] + pub entity_id: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, + pub entity_tags: TagsMap, +} + +#[derive(Packet, Debug)] +pub struct AcknowledgePlayerDigging { + pub location: Position, + #[packet(with = "var_int")] + pub block: i32, + #[packet(with = "var_int")] + pub status: i32, + pub successful: bool, +} diff --git a/protocol/src/version/v_1_16_rc1/handshake.rs b/protocol/src/version/v_1_16_rc1/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_16_rc1/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_16_rc1/login.rs b/protocol/src/version/v_1_16_rc1/login.rs new file mode 100644 index 0000000..d29fe54 --- /dev/null +++ b/protocol/src/version/v_1_16_rc1/login.rs @@ -0,0 +1,211 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use uuid::Uuid; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: Uuid, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: Uuid, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_1_16_rc1/mod.rs b/protocol/src/version/v_1_16_rc1/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_16_rc1/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_16_rc1/status.rs b/protocol/src/version/v_1_16_rc1/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_16_rc1/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_8/game.rs b/protocol/src/version/v_1_8/game.rs new file mode 100644 index 0000000..149f640 --- /dev/null +++ b/protocol/src/version/v_1_8/game.rs @@ -0,0 +1,2475 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundChat(ServerBoundChat), + UseEntity(UseEntity), + Flying(Flying), + ServerBoundPosition(ServerBoundPosition), + Look(Look), + PositionLook(PositionLook), + BlockDig(BlockDig), + BlockPlace(BlockPlace), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + ArmAnimation, + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + ServerBoundCloseWindow(ServerBoundCloseWindow), + WindowClick(WindowClick), + ServerBoundTransaction(ServerBoundTransaction), + SetCreativeSlot(SetCreativeSlot), + EnchantItem(EnchantItem), + ServerBoundUpdateSign(ServerBoundUpdateSign), + ServerBoundAbilities(ServerBoundAbilities), + ServerBoundTabComplete(ServerBoundTabComplete), + Settings(Settings), + ClientCommand(ClientCommand), + ServerBoundCustomPayload(ServerBoundCustomPayload), + Spectate(Spectate), + ResourcePackReceive(ResourcePackReceive), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::ServerBoundKeepAlive(_) => 0x00, + Self::ServerBoundChat(_) => 0x01, + Self::UseEntity(_) => 0x02, + Self::Flying(_) => 0x03, + Self::ServerBoundPosition(_) => 0x04, + Self::Look(_) => 0x05, + Self::PositionLook(_) => 0x06, + Self::BlockDig(_) => 0x07, + Self::BlockPlace(_) => 0x08, + Self::ServerBoundHeldItemSlot(_) => 0x09, + Self::ArmAnimation => 0x0A, + Self::EntityAction(_) => 0x0B, + Self::SteerVehicle(_) => 0x0C, + Self::ServerBoundCloseWindow(_) => 0x0D, + Self::WindowClick(_) => 0x0E, + Self::ServerBoundTransaction(_) => 0x0F, + Self::SetCreativeSlot(_) => 0x10, + Self::EnchantItem(_) => 0x11, + Self::ServerBoundUpdateSign(_) => 0x12, + Self::ServerBoundAbilities(_) => 0x13, + Self::ServerBoundTabComplete(_) => 0x14, + Self::Settings(_) => 0x15, + Self::ClientCommand(_) => 0x16, + Self::ServerBoundCustomPayload(_) => 0x17, + Self::Spectate(_) => 0x18, + Self::ResourcePackReceive(_) => 0x19, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x01 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x02 => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x03 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x04 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x05 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x06 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x07 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x08 => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x09 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x0A => Ok(Self::ArmAnimation), + 0x0B => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x0C => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x0D => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0E => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x0F => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x10 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x11 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x12 => { + let server_bound_update_sign = ServerBoundUpdateSign::decode(reader)?; + + Ok(Self::ServerBoundUpdateSign(server_bound_update_sign)) + } + 0x13 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x14 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x15 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x16 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x17 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x18 => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x19 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn block_place( + location: Position, + direction: i8, + held_item: Option, + cursor_x: i8, + cursor_y: i8, + cursor_z: i8, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + held_item, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn arm_animation() -> Self { + Self::ArmAnimation + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn server_bound_update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let server_bound_update_sign = ServerBoundUpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::ServerBoundUpdateSign(server_bound_update_sign) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn server_bound_tab_complete(text: String, block: Position) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { text, block }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i8, + chat_colors: bool, + skin_parts: u8, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + }; + + Self::Settings(settings) + } + + pub fn client_command(payload: i32) -> Self { + let client_command = ClientCommand { payload }; + + Self::ClientCommand(client_command) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn resource_pack_receive(hash: String, result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { hash, result }; + + Self::ResourcePackReceive(resource_pack_receive) + } +} + +pub enum ClientBoundGamePacket { + ClientBoundKeepAlive(ClientBoundKeepAlive), + JoinGame(JoinGame), + ClientBoundChat(ClientBoundChat), + UpdateTime(UpdateTime), + EntityEquipment(EntityEquipment), + SpawnPosition(SpawnPosition), + UpdateHealth(UpdateHealth), + Respawn(Respawn), + ClientBoundPosition(ClientBoundPosition), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + Bed(Bed), + Animation(Animation), + NamedEntitySpawn(NamedEntitySpawn), + Collect(Collect), + SpawnEntity(SpawnEntity), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + EntityVelocity(EntityVelocity), + EntityDestroy, + Entity(Entity), + RelEntityMove(RelEntityMove), + EntityLook(EntityLook), + EntityMoveLook(EntityMoveLook), + EntityTeleport(EntityTeleport), + EntityHeadRotation(EntityHeadRotation), + EntityStatus(EntityStatus), + AttachEntity(AttachEntity), + EntityMetadata(EntityMetadata), + EntityEffect(EntityEffect), + RemoveEntityEffect(RemoveEntityEffect), + Experience(Experience), + UpdateAttributes(UpdateAttributes), + MapChunk(MapChunk), + MultiBlockChange(MultiBlockChange), + BlockChange(BlockChange), + BlockAction(BlockAction), + BlockBreakAnimation(BlockBreakAnimation), + MapChunkBulk(MapChunkBulk), + Explosion(Explosion), + WorldEvent(WorldEvent), + NamedSoundEffect(NamedSoundEffect), + WorldParticles(WorldParticles), + GameStateChange(GameStateChange), + SpawnEntityWeather(SpawnEntityWeather), + OpenWindow(OpenWindow), + ClientBoundCloseWindow(ClientBoundCloseWindow), + SetSlot(SetSlot), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundUpdateSign(ClientBoundUpdateSign), + Map(Map), + TileEntityData(TileEntityData), + OpenSignEntity(OpenSignEntity), + Statistics, + PlayerInfo(PlayerInfo), + ClientBoundAbilities(ClientBoundAbilities), + ClientBoundTabComplete, + ScoreboardObjective(ScoreboardObjective), + ScoreboardScore(ScoreboardScore), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + ScoreboardTeam(ScoreboardTeam), + ClientBoundCustomPayload(ClientBoundCustomPayload), + KickDisconnect(KickDisconnect), + Difficulty(Difficulty), + CombatEvent(CombatEvent), + Camera(Camera), + WorldBorder(WorldBorder), + Title(Title), + SetCompression(SetCompression), + PlayerlistHeader(PlayerlistHeader), + ResourcePackSend(ResourcePackSend), + UpdateEntityNbt(UpdateEntityNbt), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::ClientBoundKeepAlive(_) => 0x00, + Self::JoinGame(_) => 0x01, + Self::ClientBoundChat(_) => 0x02, + Self::UpdateTime(_) => 0x03, + Self::EntityEquipment(_) => 0x04, + Self::SpawnPosition(_) => 0x05, + Self::UpdateHealth(_) => 0x06, + Self::Respawn(_) => 0x07, + Self::ClientBoundPosition(_) => 0x08, + Self::ClientBoundHeldItemSlot(_) => 0x09, + Self::Bed(_) => 0x0A, + Self::Animation(_) => 0x0B, + Self::NamedEntitySpawn(_) => 0x0C, + Self::Collect(_) => 0x0D, + Self::SpawnEntity(_) => 0x0E, + Self::SpawnEntityLiving(_) => 0x0F, + Self::SpawnEntityPainting(_) => 0x10, + Self::SpawnEntityExperienceOrb(_) => 0x11, + Self::EntityVelocity(_) => 0x12, + Self::EntityDestroy => 0x13, + Self::Entity(_) => 0x14, + Self::RelEntityMove(_) => 0x15, + Self::EntityLook(_) => 0x16, + Self::EntityMoveLook(_) => 0x17, + Self::EntityTeleport(_) => 0x18, + Self::EntityHeadRotation(_) => 0x19, + Self::EntityStatus(_) => 0x1A, + Self::AttachEntity(_) => 0x1B, + Self::EntityMetadata(_) => 0x1C, + Self::EntityEffect(_) => 0x1D, + Self::RemoveEntityEffect(_) => 0x1E, + Self::Experience(_) => 0x1F, + Self::UpdateAttributes(_) => 0x20, + Self::MapChunk(_) => 0x21, + Self::MultiBlockChange(_) => 0x22, + Self::BlockChange(_) => 0x23, + Self::BlockAction(_) => 0x24, + Self::BlockBreakAnimation(_) => 0x25, + Self::MapChunkBulk(_) => 0x26, + Self::Explosion(_) => 0x27, + Self::WorldEvent(_) => 0x28, + Self::NamedSoundEffect(_) => 0x29, + Self::WorldParticles(_) => 0x2A, + Self::GameStateChange(_) => 0x2B, + Self::SpawnEntityWeather(_) => 0x2C, + Self::OpenWindow(_) => 0x2D, + Self::ClientBoundCloseWindow(_) => 0x2E, + Self::SetSlot(_) => 0x2F, + Self::WindowItems(_) => 0x30, + Self::CraftProgressBar(_) => 0x31, + Self::ClientBoundTransaction(_) => 0x32, + Self::ClientBoundUpdateSign(_) => 0x33, + Self::Map(_) => 0x34, + Self::TileEntityData(_) => 0x35, + Self::OpenSignEntity(_) => 0x36, + Self::Statistics => 0x37, + Self::PlayerInfo(_) => 0x38, + Self::ClientBoundAbilities(_) => 0x39, + Self::ClientBoundTabComplete => 0x3A, + Self::ScoreboardObjective(_) => 0x3B, + Self::ScoreboardScore(_) => 0x3C, + Self::ScoreboardDisplayObjective(_) => 0x3D, + Self::ScoreboardTeam(_) => 0x3E, + Self::ClientBoundCustomPayload(_) => 0x3F, + Self::KickDisconnect(_) => 0x40, + Self::Difficulty(_) => 0x41, + Self::CombatEvent(_) => 0x42, + Self::Camera(_) => 0x43, + Self::WorldBorder(_) => 0x44, + Self::Title(_) => 0x45, + Self::SetCompression(_) => 0x46, + Self::PlayerlistHeader(_) => 0x47, + Self::ResourcePackSend(_) => 0x48, + Self::UpdateEntityNbt(_) => 0x49, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x01 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x02 => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x03 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x04 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x05 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x06 => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x07 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x08 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x09 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x0A => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x0B => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x0C => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x0D => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x0E => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x0F => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x10 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x11 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x12 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x13 => Ok(Self::EntityDestroy), + 0x14 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x15 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x16 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x17 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x18 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x19 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x1A => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1B => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x1C => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x1D => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x1E => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x1F => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x20 => { + let update_attributes = UpdateAttributes::decode(reader)?; + + Ok(Self::UpdateAttributes(update_attributes)) + } + 0x21 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x22 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x23 => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x24 => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x25 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x26 => { + let map_chunk_bulk = MapChunkBulk::decode(reader)?; + + Ok(Self::MapChunkBulk(map_chunk_bulk)) + } + 0x27 => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x28 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x29 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x2A => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x2B => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x2C => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x2D => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x2E => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x2F => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x30 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x31 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x32 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x33 => { + let client_bound_update_sign = ClientBoundUpdateSign::decode(reader)?; + + Ok(Self::ClientBoundUpdateSign(client_bound_update_sign)) + } + 0x34 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x35 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x36 => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x37 => Ok(Self::Statistics), + 0x38 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x39 => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x3A => Ok(Self::ClientBoundTabComplete), + 0x3B => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x3C => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x3D => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x3E => { + let scoreboard_team = ScoreboardTeam::decode(reader)?; + + Ok(Self::ScoreboardTeam(scoreboard_team)) + } + 0x3F => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x40 => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x41 => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x42 => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x43 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x44 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x45 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x46 => { + let set_compression = SetCompression::decode(reader)?; + + Ok(Self::SetCompression(set_compression)) + } + 0x47 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x48 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x49 => { + let update_entity_nbt = UpdateEntityNbt::decode(reader)?; + + Ok(Self::UpdateEntityNbt(update_entity_nbt)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i8, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn entity_equipment(entity_id: i32, slot: i16, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn client_bound_position(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, flags: i8) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: i32, + y: i32, + z: i32, + yaw: i8, + pitch: i8, + current_item: i16, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + current_item, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn collect(collected_entity_id: i32, collector_entity_id: i32) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + }; + + Self::Collect(collect) + } + + pub fn spawn_entity( + entity_id: i32, + type_: i8, + x: i32, + y: i32, + z: i32, + pitch: i8, + yaw: i8, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + type_, + x, + y, + z, + pitch, + yaw, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_living( + entity_id: i32, + type_: u8, + x: i32, + y: i32, + z: i32, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: i32, y: i32, z: i32, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i8, d_y: i8, d_z: i8, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i8, + d_y: i8, + d_z: i8, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_teleport( + entity_id: i32, + x: i32, + y: i32, + z: i32, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32, leash: bool) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + leash, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: bool, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_attributes(entity_id: i32) -> Self { + let update_attributes = UpdateAttributes { entity_id }; + + Self::UpdateAttributes(update_attributes) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: u16, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn map_chunk_bulk(sky_light_sent: bool, data: Vec) -> Self { + let map_chunk_bulk = MapChunkBulk { + sky_light_sent, + data, + }; + + Self::MapChunkBulk(map_chunk_bulk) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn named_sound_effect( + sound_name: String, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: u8, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: i32, y: i32, z: i32) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let client_bound_update_sign = ClientBoundUpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::ClientBoundUpdateSign(client_bound_update_sign) + } + + pub fn map(item_damage: i32, scale: i8, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + columns, + }; + + Self::Map(map) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn scoreboard_team(team: String, mode: i8) -> Self { + let scoreboard_team = ScoreboardTeam { team, mode }; + + Self::ScoreboardTeam(scoreboard_team) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn set_compression(threshold: i32) -> Self { + let set_compression = SetCompression { threshold }; + + Self::SetCompression(set_compression) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn update_entity_nbt(entity_id: i32, tag: CompoundTag) -> Self { + let update_entity_nbt = UpdateEntityNbt { entity_id, tag }; + + Self::UpdateEntityNbt(update_entity_nbt) + } +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + pub direction: i8, + pub held_item: Option, + pub cursor_x: i8, + pub cursor_y: i8, + pub cursor_z: i8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundUpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub block: Position, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + pub chat_flags: i8, + pub chat_colors: bool, + pub skin_parts: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub payload: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + pub hash: String, + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i8, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: i32, + pub y: i32, + pub z: i32, + pub yaw: i8, + pub pitch: i8, + pub current_item: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: i32, + pub y: i32, + pub z: i32, + pub pitch: i8, + pub yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: u8, + pub x: i32, + pub y: i32, + pub z: i32, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i8, + pub d_y: i8, + pub d_z: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i8, + pub d_y: i8, + pub d_z: i8, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, + pub leash: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + pub bit_map: u16, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct MapChunkBulk { + pub sky_light_sent: bool, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: u8, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: i32, + pub y: i32, + pub z: i32, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundUpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardTeam { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SetCompression { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct UpdateEntityNbt { + #[packet(with = "var_int")] + pub entity_id: i32, + pub tag: CompoundTag, +} diff --git a/protocol/src/version/v_1_8/handshake.rs b/protocol/src/version/v_1_8/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_8/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_8/login.rs b/protocol/src/version/v_1_8/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_1_8/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_1_8/mod.rs b/protocol/src/version/v_1_8/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_8/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_8/status.rs b/protocol/src/version/v_1_8/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_8/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_9/game.rs b/protocol/src/version/v_1_9/game.rs new file mode 100644 index 0000000..9a2ce42 --- /dev/null +++ b/protocol/src/version/v_1_9/game.rs @@ -0,0 +1,2719 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + ServerBoundUpdateSign(ServerBoundUpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::ServerBoundTabComplete(_) => 0x01, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x05, + Self::EnchantItem(_) => 0x06, + Self::WindowClick(_) => 0x07, + Self::ServerBoundCloseWindow(_) => 0x08, + Self::ServerBoundCustomPayload(_) => 0x09, + Self::UseEntity(_) => 0x0A, + Self::ServerBoundKeepAlive(_) => 0x0B, + Self::ServerBoundPosition(_) => 0x0C, + Self::PositionLook(_) => 0x0D, + Self::Look(_) => 0x0E, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x10, + Self::SteerBoat(_) => 0x11, + Self::ServerBoundAbilities(_) => 0x12, + Self::BlockDig(_) => 0x13, + Self::EntityAction(_) => 0x14, + Self::SteerVehicle(_) => 0x15, + Self::ResourcePackReceive(_) => 0x16, + Self::ServerBoundHeldItemSlot(_) => 0x17, + Self::SetCreativeSlot(_) => 0x18, + Self::ServerBoundUpdateSign(_) => 0x19, + Self::ArmAnimation(_) => 0x1A, + Self::Spectate(_) => 0x1B, + Self::BlockPlace(_) => 0x1C, + Self::UseItem(_) => 0x1D, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x05 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x06 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x07 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x08 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x09 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0A => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0B => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0C => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0D => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0E => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x10 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x11 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x12 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x13 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x14 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x15 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x16 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x17 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x18 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x19 => { + let server_bound_update_sign = ServerBoundUpdateSign::decode(reader)?; + + Ok(Self::ServerBoundUpdateSign(server_bound_update_sign)) + } + 0x1A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x1D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn resource_pack_receive(hash: String, result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { hash, result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn server_bound_update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let server_bound_update_sign = ServerBoundUpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::ServerBoundUpdateSign(server_bound_update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: i8, + cursor_y: i8, + cursor_z: i8, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + ClientBoundUpdateSign(ClientBoundUpdateSign), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete => 0x0E, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::OpenWindow(_) => 0x13, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::MapChunk(_) => 0x20, + Self::WorldEvent(_) => 0x21, + Self::WorldParticles(_) => 0x22, + Self::JoinGame(_) => 0x23, + Self::Map(_) => 0x24, + Self::RelEntityMove(_) => 0x25, + Self::EntityMoveLook(_) => 0x26, + Self::EntityLook(_) => 0x27, + Self::Entity(_) => 0x28, + Self::ClientBoundVehicleMove(_) => 0x29, + Self::OpenSignEntity(_) => 0x2A, + Self::ClientBoundAbilities(_) => 0x2B, + Self::CombatEvent(_) => 0x2C, + Self::PlayerInfo(_) => 0x2D, + Self::ClientBoundPosition(_) => 0x2E, + Self::Bed(_) => 0x2F, + Self::EntityDestroy => 0x30, + Self::RemoveEntityEffect(_) => 0x31, + Self::ResourcePackSend(_) => 0x32, + Self::Respawn(_) => 0x33, + Self::EntityHeadRotation(_) => 0x34, + Self::WorldBorder(_) => 0x35, + Self::Camera(_) => 0x36, + Self::ClientBoundHeldItemSlot(_) => 0x37, + Self::ScoreboardDisplayObjective(_) => 0x38, + Self::EntityMetadata(_) => 0x39, + Self::AttachEntity(_) => 0x3A, + Self::EntityVelocity(_) => 0x3B, + Self::EntityEquipment(_) => 0x3C, + Self::Experience(_) => 0x3D, + Self::UpdateHealth(_) => 0x3E, + Self::ScoreboardObjective(_) => 0x3F, + Self::SetPassengers(_) => 0x40, + Self::Teams(_) => 0x41, + Self::ScoreboardScore(_) => 0x42, + Self::SpawnPosition(_) => 0x43, + Self::UpdateTime(_) => 0x44, + Self::Title(_) => 0x45, + Self::ClientBoundUpdateSign(_) => 0x46, + Self::SoundEffect(_) => 0x47, + Self::PlayerlistHeader(_) => 0x48, + Self::Collect(_) => 0x49, + Self::EntityTeleport(_) => 0x4A, + Self::EntityUpdateAttributes(_) => 0x4B, + Self::EntityEffect(_) => 0x4C, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0E => Ok(Self::ClientBoundTabComplete), + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x13 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x23 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x24 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x25 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x26 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x27 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x28 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x29 => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2A => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2B => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2C => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2D => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2E => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x2F => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x30 => Ok(Self::EntityDestroy), + 0x31 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x32 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x33 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x34 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x35 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x36 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x37 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x38 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x39 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3A => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3B => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3C => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x3D => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x3E => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x3F => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x40 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x41 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x42 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x43 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x44 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x45 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x46 => { + let client_bound_update_sign = ClientBoundUpdateSign::decode(reader)?; + + Ok(Self::ClientBoundUpdateSign(client_bound_update_sign)) + } + 0x47 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x48 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x49 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x4A => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4B => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4C => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: u8, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: u8, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i8, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn client_bound_update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let client_bound_update_sign = ClientBoundUpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::ClientBoundUpdateSign(client_bound_update_sign) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: u8, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect(collected_entity_id: i32, collector_entity_id: i32) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + pub hash: String, + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundUpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: i8, + pub cursor_y: i8, + pub cursor_z: i8, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub type_: u8, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: u8, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i8, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundUpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: u8, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} diff --git a/protocol/src/version/v_1_9/handshake.rs b/protocol/src/version/v_1_9/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_9/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_9/login.rs b/protocol/src/version/v_1_9/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_1_9/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_1_9/mod.rs b/protocol/src/version/v_1_9/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_9/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_9/status.rs b/protocol/src/version/v_1_9/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_9/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_9_1_pre2/game.rs b/protocol/src/version/v_1_9_1_pre2/game.rs new file mode 100644 index 0000000..ae06599 --- /dev/null +++ b/protocol/src/version/v_1_9_1_pre2/game.rs @@ -0,0 +1,2719 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + ServerBoundUpdateSign(ServerBoundUpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::ServerBoundTabComplete(_) => 0x01, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x05, + Self::EnchantItem(_) => 0x06, + Self::WindowClick(_) => 0x07, + Self::ServerBoundCloseWindow(_) => 0x08, + Self::ServerBoundCustomPayload(_) => 0x09, + Self::UseEntity(_) => 0x0A, + Self::ServerBoundKeepAlive(_) => 0x0B, + Self::ServerBoundPosition(_) => 0x0C, + Self::PositionLook(_) => 0x0D, + Self::Look(_) => 0x0E, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x10, + Self::SteerBoat(_) => 0x11, + Self::ServerBoundAbilities(_) => 0x12, + Self::BlockDig(_) => 0x13, + Self::EntityAction(_) => 0x14, + Self::SteerVehicle(_) => 0x15, + Self::ResourcePackReceive(_) => 0x16, + Self::ServerBoundHeldItemSlot(_) => 0x17, + Self::SetCreativeSlot(_) => 0x18, + Self::ServerBoundUpdateSign(_) => 0x19, + Self::ArmAnimation(_) => 0x1A, + Self::Spectate(_) => 0x1B, + Self::BlockPlace(_) => 0x1C, + Self::UseItem(_) => 0x1D, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x05 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x06 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x07 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x08 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x09 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0A => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0B => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0C => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0D => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0E => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x10 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x11 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x12 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x13 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x14 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x15 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x16 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x17 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x18 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x19 => { + let server_bound_update_sign = ServerBoundUpdateSign::decode(reader)?; + + Ok(Self::ServerBoundUpdateSign(server_bound_update_sign)) + } + 0x1A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x1D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn resource_pack_receive(hash: String, result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { hash, result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn server_bound_update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let server_bound_update_sign = ServerBoundUpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::ServerBoundUpdateSign(server_bound_update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: i8, + cursor_y: i8, + cursor_z: i8, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + ClientBoundUpdateSign(ClientBoundUpdateSign), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete => 0x0E, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::OpenWindow(_) => 0x13, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::MapChunk(_) => 0x20, + Self::WorldEvent(_) => 0x21, + Self::WorldParticles(_) => 0x22, + Self::JoinGame(_) => 0x23, + Self::Map(_) => 0x24, + Self::RelEntityMove(_) => 0x25, + Self::EntityMoveLook(_) => 0x26, + Self::EntityLook(_) => 0x27, + Self::Entity(_) => 0x28, + Self::ClientBoundVehicleMove(_) => 0x29, + Self::OpenSignEntity(_) => 0x2A, + Self::ClientBoundAbilities(_) => 0x2B, + Self::CombatEvent(_) => 0x2C, + Self::PlayerInfo(_) => 0x2D, + Self::ClientBoundPosition(_) => 0x2E, + Self::Bed(_) => 0x2F, + Self::EntityDestroy => 0x30, + Self::RemoveEntityEffect(_) => 0x31, + Self::ResourcePackSend(_) => 0x32, + Self::Respawn(_) => 0x33, + Self::EntityHeadRotation(_) => 0x34, + Self::WorldBorder(_) => 0x35, + Self::Camera(_) => 0x36, + Self::ClientBoundHeldItemSlot(_) => 0x37, + Self::ScoreboardDisplayObjective(_) => 0x38, + Self::EntityMetadata(_) => 0x39, + Self::AttachEntity(_) => 0x3A, + Self::EntityVelocity(_) => 0x3B, + Self::EntityEquipment(_) => 0x3C, + Self::Experience(_) => 0x3D, + Self::UpdateHealth(_) => 0x3E, + Self::ScoreboardObjective(_) => 0x3F, + Self::SetPassengers(_) => 0x40, + Self::Teams(_) => 0x41, + Self::ScoreboardScore(_) => 0x42, + Self::SpawnPosition(_) => 0x43, + Self::UpdateTime(_) => 0x44, + Self::Title(_) => 0x45, + Self::ClientBoundUpdateSign(_) => 0x46, + Self::SoundEffect(_) => 0x47, + Self::PlayerlistHeader(_) => 0x48, + Self::Collect(_) => 0x49, + Self::EntityTeleport(_) => 0x4A, + Self::EntityUpdateAttributes(_) => 0x4B, + Self::EntityEffect(_) => 0x4C, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0E => Ok(Self::ClientBoundTabComplete), + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x13 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x23 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x24 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x25 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x26 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x27 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x28 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x29 => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2A => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2B => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2C => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2D => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2E => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x2F => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x30 => Ok(Self::EntityDestroy), + 0x31 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x32 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x33 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x34 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x35 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x36 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x37 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x38 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x39 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3A => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3B => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3C => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x3D => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x3E => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x3F => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x40 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x41 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x42 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x43 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x44 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x45 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x46 => { + let client_bound_update_sign = ClientBoundUpdateSign::decode(reader)?; + + Ok(Self::ClientBoundUpdateSign(client_bound_update_sign)) + } + 0x47 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x48 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x49 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x4A => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4B => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4C => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: u8, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: u8, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn client_bound_update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let client_bound_update_sign = ClientBoundUpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::ClientBoundUpdateSign(client_bound_update_sign) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: u8, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect(collected_entity_id: i32, collector_entity_id: i32) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + pub hash: String, + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundUpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: i8, + pub cursor_y: i8, + pub cursor_z: i8, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub type_: u8, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: u8, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundUpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: u8, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} diff --git a/protocol/src/version/v_1_9_1_pre2/handshake.rs b/protocol/src/version/v_1_9_1_pre2/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_9_1_pre2/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_9_1_pre2/login.rs b/protocol/src/version/v_1_9_1_pre2/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_1_9_1_pre2/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_1_9_1_pre2/mod.rs b/protocol/src/version/v_1_9_1_pre2/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_9_1_pre2/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_9_1_pre2/status.rs b/protocol/src/version/v_1_9_1_pre2/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_9_1_pre2/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_9_2/game.rs b/protocol/src/version/v_1_9_2/game.rs new file mode 100644 index 0000000..ae06599 --- /dev/null +++ b/protocol/src/version/v_1_9_2/game.rs @@ -0,0 +1,2719 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + ServerBoundUpdateSign(ServerBoundUpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::ServerBoundTabComplete(_) => 0x01, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x05, + Self::EnchantItem(_) => 0x06, + Self::WindowClick(_) => 0x07, + Self::ServerBoundCloseWindow(_) => 0x08, + Self::ServerBoundCustomPayload(_) => 0x09, + Self::UseEntity(_) => 0x0A, + Self::ServerBoundKeepAlive(_) => 0x0B, + Self::ServerBoundPosition(_) => 0x0C, + Self::PositionLook(_) => 0x0D, + Self::Look(_) => 0x0E, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x10, + Self::SteerBoat(_) => 0x11, + Self::ServerBoundAbilities(_) => 0x12, + Self::BlockDig(_) => 0x13, + Self::EntityAction(_) => 0x14, + Self::SteerVehicle(_) => 0x15, + Self::ResourcePackReceive(_) => 0x16, + Self::ServerBoundHeldItemSlot(_) => 0x17, + Self::SetCreativeSlot(_) => 0x18, + Self::ServerBoundUpdateSign(_) => 0x19, + Self::ArmAnimation(_) => 0x1A, + Self::Spectate(_) => 0x1B, + Self::BlockPlace(_) => 0x1C, + Self::UseItem(_) => 0x1D, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x05 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x06 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x07 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x08 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x09 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0A => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0B => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0C => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0D => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0E => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x10 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x11 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x12 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x13 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x14 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x15 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x16 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x17 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x18 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x19 => { + let server_bound_update_sign = ServerBoundUpdateSign::decode(reader)?; + + Ok(Self::ServerBoundUpdateSign(server_bound_update_sign)) + } + 0x1A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x1D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn resource_pack_receive(hash: String, result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { hash, result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn server_bound_update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let server_bound_update_sign = ServerBoundUpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::ServerBoundUpdateSign(server_bound_update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: i8, + cursor_y: i8, + cursor_z: i8, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + ClientBoundUpdateSign(ClientBoundUpdateSign), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete => 0x0E, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::OpenWindow(_) => 0x13, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::MapChunk(_) => 0x20, + Self::WorldEvent(_) => 0x21, + Self::WorldParticles(_) => 0x22, + Self::JoinGame(_) => 0x23, + Self::Map(_) => 0x24, + Self::RelEntityMove(_) => 0x25, + Self::EntityMoveLook(_) => 0x26, + Self::EntityLook(_) => 0x27, + Self::Entity(_) => 0x28, + Self::ClientBoundVehicleMove(_) => 0x29, + Self::OpenSignEntity(_) => 0x2A, + Self::ClientBoundAbilities(_) => 0x2B, + Self::CombatEvent(_) => 0x2C, + Self::PlayerInfo(_) => 0x2D, + Self::ClientBoundPosition(_) => 0x2E, + Self::Bed(_) => 0x2F, + Self::EntityDestroy => 0x30, + Self::RemoveEntityEffect(_) => 0x31, + Self::ResourcePackSend(_) => 0x32, + Self::Respawn(_) => 0x33, + Self::EntityHeadRotation(_) => 0x34, + Self::WorldBorder(_) => 0x35, + Self::Camera(_) => 0x36, + Self::ClientBoundHeldItemSlot(_) => 0x37, + Self::ScoreboardDisplayObjective(_) => 0x38, + Self::EntityMetadata(_) => 0x39, + Self::AttachEntity(_) => 0x3A, + Self::EntityVelocity(_) => 0x3B, + Self::EntityEquipment(_) => 0x3C, + Self::Experience(_) => 0x3D, + Self::UpdateHealth(_) => 0x3E, + Self::ScoreboardObjective(_) => 0x3F, + Self::SetPassengers(_) => 0x40, + Self::Teams(_) => 0x41, + Self::ScoreboardScore(_) => 0x42, + Self::SpawnPosition(_) => 0x43, + Self::UpdateTime(_) => 0x44, + Self::Title(_) => 0x45, + Self::ClientBoundUpdateSign(_) => 0x46, + Self::SoundEffect(_) => 0x47, + Self::PlayerlistHeader(_) => 0x48, + Self::Collect(_) => 0x49, + Self::EntityTeleport(_) => 0x4A, + Self::EntityUpdateAttributes(_) => 0x4B, + Self::EntityEffect(_) => 0x4C, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0E => Ok(Self::ClientBoundTabComplete), + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x13 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x23 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x24 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x25 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x26 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x27 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x28 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x29 => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2A => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2B => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2C => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2D => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2E => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x2F => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x30 => Ok(Self::EntityDestroy), + 0x31 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x32 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x33 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x34 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x35 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x36 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x37 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x38 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x39 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3A => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3B => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3C => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x3D => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x3E => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x3F => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x40 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x41 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x42 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x43 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x44 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x45 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x46 => { + let client_bound_update_sign = ClientBoundUpdateSign::decode(reader)?; + + Ok(Self::ClientBoundUpdateSign(client_bound_update_sign)) + } + 0x47 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x48 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x49 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x4A => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4B => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4C => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: u8, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: u8, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn client_bound_update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let client_bound_update_sign = ClientBoundUpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::ClientBoundUpdateSign(client_bound_update_sign) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: u8, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect(collected_entity_id: i32, collector_entity_id: i32) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + pub hash: String, + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundUpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: i8, + pub cursor_y: i8, + pub cursor_z: i8, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub type_: u8, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: u8, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundUpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: u8, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} diff --git a/protocol/src/version/v_1_9_2/handshake.rs b/protocol/src/version/v_1_9_2/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_9_2/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_9_2/login.rs b/protocol/src/version/v_1_9_2/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_1_9_2/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_1_9_2/mod.rs b/protocol/src/version/v_1_9_2/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_9_2/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_9_2/status.rs b/protocol/src/version/v_1_9_2/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_9_2/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_1_9_4/game.rs b/protocol/src/version/v_1_9_4/game.rs new file mode 100644 index 0000000..f229dba --- /dev/null +++ b/protocol/src/version/v_1_9_4/game.rs @@ -0,0 +1,2685 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::ServerBoundTabComplete(_) => 0x01, + Self::ServerBoundChat(_) => 0x02, + Self::ClientCommand(_) => 0x03, + Self::Settings(_) => 0x04, + Self::ServerBoundTransaction(_) => 0x05, + Self::EnchantItem(_) => 0x06, + Self::WindowClick(_) => 0x07, + Self::ServerBoundCloseWindow(_) => 0x08, + Self::ServerBoundCustomPayload(_) => 0x09, + Self::UseEntity(_) => 0x0A, + Self::ServerBoundKeepAlive(_) => 0x0B, + Self::ServerBoundPosition(_) => 0x0C, + Self::PositionLook(_) => 0x0D, + Self::Look(_) => 0x0E, + Self::Flying(_) => 0x0F, + Self::ServerBoundVehicleMove(_) => 0x10, + Self::SteerBoat(_) => 0x11, + Self::ServerBoundAbilities(_) => 0x12, + Self::BlockDig(_) => 0x13, + Self::EntityAction(_) => 0x14, + Self::SteerVehicle(_) => 0x15, + Self::ResourcePackReceive(_) => 0x16, + Self::ServerBoundHeldItemSlot(_) => 0x17, + Self::SetCreativeSlot(_) => 0x18, + Self::UpdateSign(_) => 0x19, + Self::ArmAnimation(_) => 0x1A, + Self::Spectate(_) => 0x1B, + Self::BlockPlace(_) => 0x1C, + Self::UseItem(_) => 0x1D, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x02 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x03 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x04 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x05 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x06 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x07 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x08 => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x09 => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0A => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0B => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x0C => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x0D => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x0E => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x0F => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x10 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x11 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x12 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x13 => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x14 => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x15 => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x16 => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x17 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x18 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x19 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x1A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x1B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x1C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x1D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn server_bound_tab_complete( + text: String, + assume_command: bool, + looked_at_block: Position, + ) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + text, + assume_command, + looked_at_block, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i32) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn resource_pack_receive(hash: String, result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { hash, result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + location: Position, + direction: i32, + hand: i32, + cursor_x: i8, + cursor_y: i8, + cursor_z: i8, + ) -> Self { + let block_place = BlockPlace { + location, + direction, + hand, + cursor_x, + cursor_y, + cursor_z, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete, + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + JoinGame(JoinGame), + Map(Map), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenSignEntity(OpenSignEntity), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + Bed(Bed), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::BlockBreakAnimation(_) => 0x08, + Self::TileEntityData(_) => 0x09, + Self::BlockAction(_) => 0x0A, + Self::BlockChange(_) => 0x0B, + Self::BossBar(_) => 0x0C, + Self::Difficulty(_) => 0x0D, + Self::ClientBoundTabComplete => 0x0E, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x11, + Self::ClientBoundCloseWindow(_) => 0x12, + Self::OpenWindow(_) => 0x13, + Self::WindowItems(_) => 0x14, + Self::CraftProgressBar(_) => 0x15, + Self::SetSlot(_) => 0x16, + Self::SetCooldown(_) => 0x17, + Self::ClientBoundCustomPayload(_) => 0x18, + Self::NamedSoundEffect(_) => 0x19, + Self::KickDisconnect(_) => 0x1A, + Self::EntityStatus(_) => 0x1B, + Self::Explosion(_) => 0x1C, + Self::UnloadChunk(_) => 0x1D, + Self::GameStateChange(_) => 0x1E, + Self::ClientBoundKeepAlive(_) => 0x1F, + Self::MapChunk(_) => 0x20, + Self::WorldEvent(_) => 0x21, + Self::WorldParticles(_) => 0x22, + Self::JoinGame(_) => 0x23, + Self::Map(_) => 0x24, + Self::RelEntityMove(_) => 0x25, + Self::EntityMoveLook(_) => 0x26, + Self::EntityLook(_) => 0x27, + Self::Entity(_) => 0x28, + Self::ClientBoundVehicleMove(_) => 0x29, + Self::OpenSignEntity(_) => 0x2A, + Self::ClientBoundAbilities(_) => 0x2B, + Self::CombatEvent(_) => 0x2C, + Self::PlayerInfo(_) => 0x2D, + Self::ClientBoundPosition(_) => 0x2E, + Self::Bed(_) => 0x2F, + Self::EntityDestroy => 0x30, + Self::RemoveEntityEffect(_) => 0x31, + Self::ResourcePackSend(_) => 0x32, + Self::Respawn(_) => 0x33, + Self::EntityHeadRotation(_) => 0x34, + Self::WorldBorder(_) => 0x35, + Self::Camera(_) => 0x36, + Self::ClientBoundHeldItemSlot(_) => 0x37, + Self::ScoreboardDisplayObjective(_) => 0x38, + Self::EntityMetadata(_) => 0x39, + Self::AttachEntity(_) => 0x3A, + Self::EntityVelocity(_) => 0x3B, + Self::EntityEquipment(_) => 0x3C, + Self::Experience(_) => 0x3D, + Self::UpdateHealth(_) => 0x3E, + Self::ScoreboardObjective(_) => 0x3F, + Self::SetPassengers(_) => 0x40, + Self::Teams(_) => 0x41, + Self::ScoreboardScore(_) => 0x42, + Self::SpawnPosition(_) => 0x43, + Self::UpdateTime(_) => 0x44, + Self::Title(_) => 0x45, + Self::SoundEffect(_) => 0x46, + Self::PlayerlistHeader(_) => 0x47, + Self::Collect(_) => 0x48, + Self::EntityTeleport(_) => 0x49, + Self::EntityUpdateAttributes(_) => 0x4A, + Self::EntityEffect(_) => 0x4B, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x08 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x09 => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0A => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0B => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0C => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0D => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x0E => Ok(Self::ClientBoundTabComplete), + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x11 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x12 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x13 => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x14 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x15 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x16 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x17 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x18 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x19 => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1A => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1B => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1C => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1D => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1E => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x1F => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x20 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x21 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x22 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x23 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x24 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x25 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x26 => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x27 => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x28 => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x29 => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2A => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x2B => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x2C => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x2D => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x2E => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x2F => { + let bed = Bed::decode(reader)?; + + Ok(Self::Bed(bed)) + } + 0x30 => Ok(Self::EntityDestroy), + 0x31 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x32 => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x33 => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x34 => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x35 => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x36 => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x37 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x38 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x39 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x3A => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x3B => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x3C => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x3D => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x3E => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x3F => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x40 => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x41 => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x42 => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x43 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x44 => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x45 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x46 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x47 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x48 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x49 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x4A => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x4B => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i8, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: u8, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + metadata: Metadata, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + metadata, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: String, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + metadata: Metadata, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + metadata, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8) -> Self { + let difficulty = Difficulty { difficulty }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete() -> Self { + Self::ClientBoundTabComplete + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window( + window_id: u8, + inventory_type: String, + window_title: String, + slot_count: u8, + ) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + slot_count, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: u8, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn client_bound_keep_alive(keep_alive_id: i32) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk(x: i32, z: i32, ground_up: bool, bit_map: i32, chunk_data: Vec) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f32, + y: f32, + z: f32, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + }; + + Self::WorldParticles(world_particles) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + difficulty: u8, + max_players: u8, + level_type: String, + reduced_debug_info: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + difficulty, + max_players, + level_type, + reduced_debug_info, + }; + + Self::JoinGame(join_game) + } + + pub fn map(item_damage: i32, scale: i8, tracking_position: bool, columns: i8) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + columns, + }; + + Self::Map(map) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn bed(entity_id: i32, location: Position) -> Self { + let bed = Bed { + entity_id, + location, + }; + + Self::Bed(bed) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, difficulty: u8, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + difficulty, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: u8, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect(collected_entity_id: i32, collector_entity_id: i32) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + pub text: String, + pub assume_command: bool, + pub looked_at_block: Position, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + pub hash: String, + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + #[packet(with = "var_int")] + pub hand: i32, + pub cursor_x: i8, + pub cursor_y: i8, + pub cursor_z: i8, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub type_: u8, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + pub title: String, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + pub window_id: u8, + pub inventory_type: String, + pub window_title: String, + pub slot_count: u8, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: u8, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + #[packet(with = "var_int")] + pub keep_alive_id: i32, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f32, + pub y: f32, + pub z: f32, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub difficulty: u8, + pub max_players: u8, + pub level_type: String, + pub reduced_debug_info: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Bed { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub difficulty: u8, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: u8, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} diff --git a/protocol/src/version/v_1_9_4/handshake.rs b/protocol/src/version/v_1_9_4/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_1_9_4/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_1_9_4/login.rs b/protocol/src/version/v_1_9_4/login.rs new file mode 100644 index 0000000..3de55c1 --- /dev/null +++ b/protocol/src/version/v_1_9_4/login.rs @@ -0,0 +1,162 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: String, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: String, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} diff --git a/protocol/src/version/v_1_9_4/mod.rs b/protocol/src/version/v_1_9_4/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_1_9_4/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_1_9_4/status.rs b/protocol/src/version/v_1_9_4/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_1_9_4/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +} diff --git a/protocol/src/version/v_20w13b/game.rs b/protocol/src/version/v_20w13b/game.rs new file mode 100644 index 0000000..b11ebad --- /dev/null +++ b/protocol/src/version/v_20w13b/game.rs @@ -0,0 +1,3579 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use crate::data::game::*; +use nbt::CompoundTag; +use uuid::Uuid; + +pub enum ServerBoundGamePacket { + TeleportConfirm(TeleportConfirm), + QueryBlockNbt(QueryBlockNbt), + SetDifficulty(SetDifficulty), + EditBook(EditBook), + QueryEntityNbt(QueryEntityNbt), + PickItem(PickItem), + NameItem(NameItem), + SelectTrade(SelectTrade), + SetBeaconEffect(SetBeaconEffect), + UpdateCommandBlock(UpdateCommandBlock), + UpdateCommandBlockMinecart(UpdateCommandBlockMinecart), + UpdateStructureBlock(UpdateStructureBlock), + ServerBoundTabComplete(ServerBoundTabComplete), + ServerBoundChat(ServerBoundChat), + ClientCommand(ClientCommand), + Settings(Settings), + ServerBoundTransaction(ServerBoundTransaction), + EnchantItem(EnchantItem), + WindowClick(WindowClick), + ServerBoundCloseWindow(ServerBoundCloseWindow), + ServerBoundCustomPayload(ServerBoundCustomPayload), + UseEntity(UseEntity), + ServerBoundKeepAlive(ServerBoundKeepAlive), + LockDifficulty(LockDifficulty), + ServerBoundPosition(ServerBoundPosition), + PositionLook(PositionLook), + Look(Look), + Flying(Flying), + ServerBoundVehicleMove(ServerBoundVehicleMove), + SteerBoat(SteerBoat), + CraftRecipeRequest(CraftRecipeRequest), + ServerBoundAbilities(ServerBoundAbilities), + BlockDig(BlockDig), + EntityAction(EntityAction), + SteerVehicle(SteerVehicle), + CraftingBookData(CraftingBookData), + ResourcePackReceive(ResourcePackReceive), + ServerBoundHeldItemSlot(ServerBoundHeldItemSlot), + SetCreativeSlot(SetCreativeSlot), + UpdateJigsawBlock(UpdateJigsawBlock), + UpdateSign(UpdateSign), + ArmAnimation(ArmAnimation), + Spectate(Spectate), + BlockPlace(BlockPlace), + UseItem(UseItem), + AdvancementTab(AdvancementTab), +} + +impl ServerBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::TeleportConfirm(_) => 0x00, + Self::QueryBlockNbt(_) => 0x01, + Self::SetDifficulty(_) => 0x02, + Self::EditBook(_) => 0x0C, + Self::QueryEntityNbt(_) => 0x0D, + Self::PickItem(_) => 0x17, + Self::NameItem(_) => 0x1E, + Self::SelectTrade(_) => 0x21, + Self::SetBeaconEffect(_) => 0x22, + Self::UpdateCommandBlock(_) => 0x24, + Self::UpdateCommandBlockMinecart(_) => 0x25, + Self::UpdateStructureBlock(_) => 0x28, + Self::ServerBoundTabComplete(_) => 0x06, + Self::ServerBoundChat(_) => 0x03, + Self::ClientCommand(_) => 0x04, + Self::Settings(_) => 0x05, + Self::ServerBoundTransaction(_) => 0x07, + Self::EnchantItem(_) => 0x08, + Self::WindowClick(_) => 0x09, + Self::ServerBoundCloseWindow(_) => 0x0A, + Self::ServerBoundCustomPayload(_) => 0x0B, + Self::UseEntity(_) => 0x0E, + Self::ServerBoundKeepAlive(_) => 0x0F, + Self::LockDifficulty(_) => 0x10, + Self::ServerBoundPosition(_) => 0x11, + Self::PositionLook(_) => 0x12, + Self::Look(_) => 0x13, + Self::Flying(_) => 0x14, + Self::ServerBoundVehicleMove(_) => 0x15, + Self::SteerBoat(_) => 0x16, + Self::CraftRecipeRequest(_) => 0x18, + Self::ServerBoundAbilities(_) => 0x19, + Self::BlockDig(_) => 0x1A, + Self::EntityAction(_) => 0x1B, + Self::SteerVehicle(_) => 0x1C, + Self::CraftingBookData(_) => 0x1D, + Self::ResourcePackReceive(_) => 0x1F, + Self::ServerBoundHeldItemSlot(_) => 0x23, + Self::SetCreativeSlot(_) => 0x26, + Self::UpdateJigsawBlock(_) => 0x27, + Self::UpdateSign(_) => 0x29, + Self::ArmAnimation(_) => 0x2A, + Self::Spectate(_) => 0x2B, + Self::BlockPlace(_) => 0x2C, + Self::UseItem(_) => 0x2D, + Self::AdvancementTab(_) => 0x20, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let teleport_confirm = TeleportConfirm::decode(reader)?; + + Ok(Self::TeleportConfirm(teleport_confirm)) + } + 0x01 => { + let query_block_nbt = QueryBlockNbt::decode(reader)?; + + Ok(Self::QueryBlockNbt(query_block_nbt)) + } + 0x02 => { + let set_difficulty = SetDifficulty::decode(reader)?; + + Ok(Self::SetDifficulty(set_difficulty)) + } + 0x0C => { + let edit_book = EditBook::decode(reader)?; + + Ok(Self::EditBook(edit_book)) + } + 0x0D => { + let query_entity_nbt = QueryEntityNbt::decode(reader)?; + + Ok(Self::QueryEntityNbt(query_entity_nbt)) + } + 0x17 => { + let pick_item = PickItem::decode(reader)?; + + Ok(Self::PickItem(pick_item)) + } + 0x1E => { + let name_item = NameItem::decode(reader)?; + + Ok(Self::NameItem(name_item)) + } + 0x21 => { + let select_trade = SelectTrade::decode(reader)?; + + Ok(Self::SelectTrade(select_trade)) + } + 0x22 => { + let set_beacon_effect = SetBeaconEffect::decode(reader)?; + + Ok(Self::SetBeaconEffect(set_beacon_effect)) + } + 0x24 => { + let update_command_block = UpdateCommandBlock::decode(reader)?; + + Ok(Self::UpdateCommandBlock(update_command_block)) + } + 0x25 => { + let update_command_block_minecart = UpdateCommandBlockMinecart::decode(reader)?; + + Ok(Self::UpdateCommandBlockMinecart( + update_command_block_minecart, + )) + } + 0x28 => { + let update_structure_block = UpdateStructureBlock::decode(reader)?; + + Ok(Self::UpdateStructureBlock(update_structure_block)) + } + 0x06 => { + let server_bound_tab_complete = ServerBoundTabComplete::decode(reader)?; + + Ok(Self::ServerBoundTabComplete(server_bound_tab_complete)) + } + 0x03 => { + let server_bound_chat = ServerBoundChat::decode(reader)?; + + Ok(Self::ServerBoundChat(server_bound_chat)) + } + 0x04 => { + let client_command = ClientCommand::decode(reader)?; + + Ok(Self::ClientCommand(client_command)) + } + 0x05 => { + let settings = Settings::decode(reader)?; + + Ok(Self::Settings(settings)) + } + 0x07 => { + let server_bound_transaction = ServerBoundTransaction::decode(reader)?; + + Ok(Self::ServerBoundTransaction(server_bound_transaction)) + } + 0x08 => { + let enchant_item = EnchantItem::decode(reader)?; + + Ok(Self::EnchantItem(enchant_item)) + } + 0x09 => { + let window_click = WindowClick::decode(reader)?; + + Ok(Self::WindowClick(window_click)) + } + 0x0A => { + let server_bound_close_window = ServerBoundCloseWindow::decode(reader)?; + + Ok(Self::ServerBoundCloseWindow(server_bound_close_window)) + } + 0x0B => { + let server_bound_custom_payload = ServerBoundCustomPayload::decode(reader)?; + + Ok(Self::ServerBoundCustomPayload(server_bound_custom_payload)) + } + 0x0E => { + let use_entity = UseEntity::decode(reader)?; + + Ok(Self::UseEntity(use_entity)) + } + 0x0F => { + let server_bound_keep_alive = ServerBoundKeepAlive::decode(reader)?; + + Ok(Self::ServerBoundKeepAlive(server_bound_keep_alive)) + } + 0x10 => { + let lock_difficulty = LockDifficulty::decode(reader)?; + + Ok(Self::LockDifficulty(lock_difficulty)) + } + 0x11 => { + let server_bound_position = ServerBoundPosition::decode(reader)?; + + Ok(Self::ServerBoundPosition(server_bound_position)) + } + 0x12 => { + let position_look = PositionLook::decode(reader)?; + + Ok(Self::PositionLook(position_look)) + } + 0x13 => { + let look = Look::decode(reader)?; + + Ok(Self::Look(look)) + } + 0x14 => { + let flying = Flying::decode(reader)?; + + Ok(Self::Flying(flying)) + } + 0x15 => { + let server_bound_vehicle_move = ServerBoundVehicleMove::decode(reader)?; + + Ok(Self::ServerBoundVehicleMove(server_bound_vehicle_move)) + } + 0x16 => { + let steer_boat = SteerBoat::decode(reader)?; + + Ok(Self::SteerBoat(steer_boat)) + } + 0x18 => { + let craft_recipe_request = CraftRecipeRequest::decode(reader)?; + + Ok(Self::CraftRecipeRequest(craft_recipe_request)) + } + 0x19 => { + let server_bound_abilities = ServerBoundAbilities::decode(reader)?; + + Ok(Self::ServerBoundAbilities(server_bound_abilities)) + } + 0x1A => { + let block_dig = BlockDig::decode(reader)?; + + Ok(Self::BlockDig(block_dig)) + } + 0x1B => { + let entity_action = EntityAction::decode(reader)?; + + Ok(Self::EntityAction(entity_action)) + } + 0x1C => { + let steer_vehicle = SteerVehicle::decode(reader)?; + + Ok(Self::SteerVehicle(steer_vehicle)) + } + 0x1D => { + let crafting_book_data = CraftingBookData::decode(reader)?; + + Ok(Self::CraftingBookData(crafting_book_data)) + } + 0x1F => { + let resource_pack_receive = ResourcePackReceive::decode(reader)?; + + Ok(Self::ResourcePackReceive(resource_pack_receive)) + } + 0x23 => { + let server_bound_held_item_slot = ServerBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ServerBoundHeldItemSlot(server_bound_held_item_slot)) + } + 0x26 => { + let set_creative_slot = SetCreativeSlot::decode(reader)?; + + Ok(Self::SetCreativeSlot(set_creative_slot)) + } + 0x27 => { + let update_jigsaw_block = UpdateJigsawBlock::decode(reader)?; + + Ok(Self::UpdateJigsawBlock(update_jigsaw_block)) + } + 0x29 => { + let update_sign = UpdateSign::decode(reader)?; + + Ok(Self::UpdateSign(update_sign)) + } + 0x2A => { + let arm_animation = ArmAnimation::decode(reader)?; + + Ok(Self::ArmAnimation(arm_animation)) + } + 0x2B => { + let spectate = Spectate::decode(reader)?; + + Ok(Self::Spectate(spectate)) + } + 0x2C => { + let block_place = BlockPlace::decode(reader)?; + + Ok(Self::BlockPlace(block_place)) + } + 0x2D => { + let use_item = UseItem::decode(reader)?; + + Ok(Self::UseItem(use_item)) + } + 0x20 => { + let advancement_tab = AdvancementTab::decode(reader)?; + + Ok(Self::AdvancementTab(advancement_tab)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn teleport_confirm(teleport_id: i32) -> Self { + let teleport_confirm = TeleportConfirm { teleport_id }; + + Self::TeleportConfirm(teleport_confirm) + } + + pub fn query_block_nbt(transaction_id: i32, location: Position) -> Self { + let query_block_nbt = QueryBlockNbt { + transaction_id, + location, + }; + + Self::QueryBlockNbt(query_block_nbt) + } + + pub fn set_difficulty(new_difficulty: u8) -> Self { + let set_difficulty = SetDifficulty { new_difficulty }; + + Self::SetDifficulty(set_difficulty) + } + + pub fn edit_book(new_book: Option, signing: bool, hand: i32) -> Self { + let edit_book = EditBook { + new_book, + signing, + hand, + }; + + Self::EditBook(edit_book) + } + + pub fn query_entity_nbt(transaction_id: i32, entity_id: i32) -> Self { + let query_entity_nbt = QueryEntityNbt { + transaction_id, + entity_id, + }; + + Self::QueryEntityNbt(query_entity_nbt) + } + + pub fn pick_item(slot: i32) -> Self { + let pick_item = PickItem { slot }; + + Self::PickItem(pick_item) + } + + pub fn name_item(name: String) -> Self { + let name_item = NameItem { name }; + + Self::NameItem(name_item) + } + + pub fn select_trade(slot: i32) -> Self { + let select_trade = SelectTrade { slot }; + + Self::SelectTrade(select_trade) + } + + pub fn set_beacon_effect(primary_effect: i32, secondary_effect: i32) -> Self { + let set_beacon_effect = SetBeaconEffect { + primary_effect, + secondary_effect, + }; + + Self::SetBeaconEffect(set_beacon_effect) + } + + pub fn update_command_block(location: Position, command: String, mode: i32, flags: u8) -> Self { + let update_command_block = UpdateCommandBlock { + location, + command, + mode, + flags, + }; + + Self::UpdateCommandBlock(update_command_block) + } + + pub fn update_command_block_minecart( + entity_id: i32, + command: String, + track_output: bool, + ) -> Self { + let update_command_block_minecart = UpdateCommandBlockMinecart { + entity_id, + command, + track_output, + }; + + Self::UpdateCommandBlockMinecart(update_command_block_minecart) + } + + pub fn update_structure_block( + location: Position, + action: i32, + mode: i32, + name: String, + offset_x: u8, + offset_y: u8, + offset_z: u8, + size_x: u8, + size_y: u8, + size_z: u8, + mirror: i32, + rotation: i32, + metadata: String, + integrity: f32, + seed: i32, + flags: u8, + ) -> Self { + let update_structure_block = UpdateStructureBlock { + location, + action, + mode, + name, + offset_x, + offset_y, + offset_z, + size_x, + size_y, + size_z, + mirror, + rotation, + metadata, + integrity, + seed, + flags, + }; + + Self::UpdateStructureBlock(update_structure_block) + } + + pub fn server_bound_tab_complete(transaction_id: i32, text: String) -> Self { + let server_bound_tab_complete = ServerBoundTabComplete { + transaction_id, + text, + }; + + Self::ServerBoundTabComplete(server_bound_tab_complete) + } + + pub fn server_bound_chat(message: String) -> Self { + let server_bound_chat = ServerBoundChat { message }; + + Self::ServerBoundChat(server_bound_chat) + } + + pub fn client_command(action_id: i32) -> Self { + let client_command = ClientCommand { action_id }; + + Self::ClientCommand(client_command) + } + + pub fn settings( + locale: String, + view_distance: i8, + chat_flags: i32, + chat_colors: bool, + skin_parts: u8, + main_hand: i32, + ) -> Self { + let settings = Settings { + locale, + view_distance, + chat_flags, + chat_colors, + skin_parts, + main_hand, + }; + + Self::Settings(settings) + } + + pub fn server_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let server_bound_transaction = ServerBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ServerBoundTransaction(server_bound_transaction) + } + + pub fn enchant_item(window_id: i8, enchantment: i8) -> Self { + let enchant_item = EnchantItem { + window_id, + enchantment, + }; + + Self::EnchantItem(enchant_item) + } + + pub fn window_click( + window_id: u8, + slot: i16, + mouse_button: i8, + action: i16, + mode: i8, + item: Option, + ) -> Self { + let window_click = WindowClick { + window_id, + slot, + mouse_button, + action, + mode, + item, + }; + + Self::WindowClick(window_click) + } + + pub fn server_bound_close_window(window_id: u8) -> Self { + let server_bound_close_window = ServerBoundCloseWindow { window_id }; + + Self::ServerBoundCloseWindow(server_bound_close_window) + } + + pub fn server_bound_custom_payload(channel: String, data: Vec) -> Self { + let server_bound_custom_payload = ServerBoundCustomPayload { channel, data }; + + Self::ServerBoundCustomPayload(server_bound_custom_payload) + } + + pub fn use_entity(target: i32, mouse: i32) -> Self { + let use_entity = UseEntity { target, mouse }; + + Self::UseEntity(use_entity) + } + + pub fn server_bound_keep_alive(keep_alive_id: i64) -> Self { + let server_bound_keep_alive = ServerBoundKeepAlive { keep_alive_id }; + + Self::ServerBoundKeepAlive(server_bound_keep_alive) + } + + pub fn lock_difficulty(locked: bool) -> Self { + let lock_difficulty = LockDifficulty { locked }; + + Self::LockDifficulty(lock_difficulty) + } + + pub fn server_bound_position(x: f64, y: f64, z: f64, on_ground: bool) -> Self { + let server_bound_position = ServerBoundPosition { x, y, z, on_ground }; + + Self::ServerBoundPosition(server_bound_position) + } + + pub fn position_look(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> Self { + let position_look = PositionLook { + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::PositionLook(position_look) + } + + pub fn look(yaw: f32, pitch: f32, on_ground: bool) -> Self { + let look = Look { + yaw, + pitch, + on_ground, + }; + + Self::Look(look) + } + + pub fn flying(on_ground: bool) -> Self { + let flying = Flying { on_ground }; + + Self::Flying(flying) + } + + pub fn server_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let server_bound_vehicle_move = ServerBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ServerBoundVehicleMove(server_bound_vehicle_move) + } + + pub fn steer_boat(left_paddle: bool, right_paddle: bool) -> Self { + let steer_boat = SteerBoat { + left_paddle, + right_paddle, + }; + + Self::SteerBoat(steer_boat) + } + + pub fn craft_recipe_request(window_id: i8, recipe: String, make_all: bool) -> Self { + let craft_recipe_request = CraftRecipeRequest { + window_id, + recipe, + make_all, + }; + + Self::CraftRecipeRequest(craft_recipe_request) + } + + pub fn server_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let server_bound_abilities = ServerBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ServerBoundAbilities(server_bound_abilities) + } + + pub fn block_dig(status: i8, location: Position, face: i8) -> Self { + let block_dig = BlockDig { + status, + location, + face, + }; + + Self::BlockDig(block_dig) + } + + pub fn entity_action(entity_id: i32, action_id: i32, jump_boost: i32) -> Self { + let entity_action = EntityAction { + entity_id, + action_id, + jump_boost, + }; + + Self::EntityAction(entity_action) + } + + pub fn steer_vehicle(sideways: f32, forward: f32, jump: u8) -> Self { + let steer_vehicle = SteerVehicle { + sideways, + forward, + jump, + }; + + Self::SteerVehicle(steer_vehicle) + } + + pub fn crafting_book_data(type_: i32) -> Self { + let crafting_book_data = CraftingBookData { type_ }; + + Self::CraftingBookData(crafting_book_data) + } + + pub fn resource_pack_receive(result: i32) -> Self { + let resource_pack_receive = ResourcePackReceive { result }; + + Self::ResourcePackReceive(resource_pack_receive) + } + + pub fn server_bound_held_item_slot(slot_id: i16) -> Self { + let server_bound_held_item_slot = ServerBoundHeldItemSlot { slot_id }; + + Self::ServerBoundHeldItemSlot(server_bound_held_item_slot) + } + + pub fn set_creative_slot(slot: i16, item: Option) -> Self { + let set_creative_slot = SetCreativeSlot { slot, item }; + + Self::SetCreativeSlot(set_creative_slot) + } + + pub fn update_jigsaw_block( + location: Position, + name: String, + target: String, + pool: String, + final_state: String, + joint_type: String, + ) -> Self { + let update_jigsaw_block = UpdateJigsawBlock { + location, + name, + target, + pool, + final_state, + joint_type, + }; + + Self::UpdateJigsawBlock(update_jigsaw_block) + } + + pub fn update_sign( + location: Position, + text1: String, + text2: String, + text3: String, + text4: String, + ) -> Self { + let update_sign = UpdateSign { + location, + text1, + text2, + text3, + text4, + }; + + Self::UpdateSign(update_sign) + } + + pub fn arm_animation(hand: i32) -> Self { + let arm_animation = ArmAnimation { hand }; + + Self::ArmAnimation(arm_animation) + } + + pub fn spectate(target: Uuid) -> Self { + let spectate = Spectate { target }; + + Self::Spectate(spectate) + } + + pub fn block_place( + hand: i32, + location: Position, + direction: i32, + cursor_x: f32, + cursor_y: f32, + cursor_z: f32, + inside_block: bool, + ) -> Self { + let block_place = BlockPlace { + hand, + location, + direction, + cursor_x, + cursor_y, + cursor_z, + inside_block, + }; + + Self::BlockPlace(block_place) + } + + pub fn use_item(hand: i32) -> Self { + let use_item = UseItem { hand }; + + Self::UseItem(use_item) + } + + pub fn advancement_tab(action: i32) -> Self { + let advancement_tab = AdvancementTab { action }; + + Self::AdvancementTab(advancement_tab) + } +} + +pub enum ClientBoundGamePacket { + SpawnEntity(SpawnEntity), + SpawnEntityExperienceOrb(SpawnEntityExperienceOrb), + SpawnEntityWeather(SpawnEntityWeather), + SpawnEntityLiving(SpawnEntityLiving), + SpawnEntityPainting(SpawnEntityPainting), + NamedEntitySpawn(NamedEntitySpawn), + Animation(Animation), + Statistics, + Advancements(Advancements), + BlockBreakAnimation(BlockBreakAnimation), + TileEntityData(TileEntityData), + BlockAction(BlockAction), + BlockChange(BlockChange), + BossBar(BossBar), + Difficulty(Difficulty), + ClientBoundTabComplete(ClientBoundTabComplete), + DeclareCommands(DeclareCommands), + FacePlayer(FacePlayer), + NbtQueryResponse(NbtQueryResponse), + ClientBoundChat(ClientBoundChat), + MultiBlockChange(MultiBlockChange), + ClientBoundTransaction(ClientBoundTransaction), + ClientBoundCloseWindow(ClientBoundCloseWindow), + OpenWindow(OpenWindow), + WindowItems(WindowItems), + CraftProgressBar(CraftProgressBar), + SetSlot(SetSlot), + SetCooldown(SetCooldown), + ClientBoundCustomPayload(ClientBoundCustomPayload), + NamedSoundEffect(NamedSoundEffect), + KickDisconnect(KickDisconnect), + EntityStatus(EntityStatus), + Explosion(Explosion), + UnloadChunk(UnloadChunk), + GameStateChange(GameStateChange), + OpenHorseWindow(OpenHorseWindow), + ClientBoundKeepAlive(ClientBoundKeepAlive), + MapChunk(MapChunk), + WorldEvent(WorldEvent), + WorldParticles(WorldParticles), + UpdateLight(UpdateLight), + JoinGame(JoinGame), + Map(Map), + TradeList(TradeList), + RelEntityMove(RelEntityMove), + EntityMoveLook(EntityMoveLook), + EntityLook(EntityLook), + Entity(Entity), + ClientBoundVehicleMove(ClientBoundVehicleMove), + OpenBook(OpenBook), + OpenSignEntity(OpenSignEntity), + CraftRecipeResponse(CraftRecipeResponse), + ClientBoundAbilities(ClientBoundAbilities), + CombatEvent(CombatEvent), + PlayerInfo(PlayerInfo), + ClientBoundPosition(ClientBoundPosition), + UnlockRecipes(UnlockRecipes), + EntityDestroy, + RemoveEntityEffect(RemoveEntityEffect), + ResourcePackSend(ResourcePackSend), + Respawn(Respawn), + EntityHeadRotation(EntityHeadRotation), + WorldBorder(WorldBorder), + Camera(Camera), + ClientBoundHeldItemSlot(ClientBoundHeldItemSlot), + UpdateViewPosition(UpdateViewPosition), + UpdateViewDistance(UpdateViewDistance), + ScoreboardDisplayObjective(ScoreboardDisplayObjective), + EntityMetadata(EntityMetadata), + AttachEntity(AttachEntity), + EntityVelocity(EntityVelocity), + EntityEquipment(EntityEquipment), + Experience(Experience), + UpdateHealth(UpdateHealth), + ScoreboardObjective(ScoreboardObjective), + SetPassengers(SetPassengers), + Teams(Teams), + ScoreboardScore(ScoreboardScore), + SpawnPosition(SpawnPosition), + UpdateTime(UpdateTime), + Title(Title), + EntitySoundEffect(EntitySoundEffect), + StopSound(StopSound), + SoundEffect(SoundEffect), + PlayerlistHeader(PlayerlistHeader), + Collect(Collect), + EntityTeleport(EntityTeleport), + EntityUpdateAttributes(EntityUpdateAttributes), + EntityEffect(EntityEffect), + SelectAdvancementTab(SelectAdvancementTab), + DeclareRecipes, + Tags(Tags), + AcknowledgePlayerDigging(AcknowledgePlayerDigging), +} + +impl ClientBoundGamePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SpawnEntity(_) => 0x00, + Self::SpawnEntityExperienceOrb(_) => 0x01, + Self::SpawnEntityWeather(_) => 0x02, + Self::SpawnEntityLiving(_) => 0x03, + Self::SpawnEntityPainting(_) => 0x04, + Self::NamedEntitySpawn(_) => 0x05, + Self::Animation(_) => 0x06, + Self::Statistics => 0x07, + Self::Advancements(_) => 0x58, + Self::BlockBreakAnimation(_) => 0x09, + Self::TileEntityData(_) => 0x0A, + Self::BlockAction(_) => 0x0B, + Self::BlockChange(_) => 0x0C, + Self::BossBar(_) => 0x0D, + Self::Difficulty(_) => 0x0E, + Self::ClientBoundTabComplete(_) => 0x11, + Self::DeclareCommands(_) => 0x12, + Self::FacePlayer(_) => 0x35, + Self::NbtQueryResponse(_) => 0x55, + Self::ClientBoundChat(_) => 0x0F, + Self::MultiBlockChange(_) => 0x10, + Self::ClientBoundTransaction(_) => 0x13, + Self::ClientBoundCloseWindow(_) => 0x14, + Self::OpenWindow(_) => 0x2F, + Self::WindowItems(_) => 0x15, + Self::CraftProgressBar(_) => 0x16, + Self::SetSlot(_) => 0x17, + Self::SetCooldown(_) => 0x18, + Self::ClientBoundCustomPayload(_) => 0x19, + Self::NamedSoundEffect(_) => 0x1A, + Self::KickDisconnect(_) => 0x1B, + Self::EntityStatus(_) => 0x1C, + Self::Explosion(_) => 0x1D, + Self::UnloadChunk(_) => 0x1E, + Self::GameStateChange(_) => 0x1F, + Self::OpenHorseWindow(_) => 0x20, + Self::ClientBoundKeepAlive(_) => 0x21, + Self::MapChunk(_) => 0x22, + Self::WorldEvent(_) => 0x23, + Self::WorldParticles(_) => 0x24, + Self::UpdateLight(_) => 0x25, + Self::JoinGame(_) => 0x26, + Self::Map(_) => 0x27, + Self::TradeList(_) => 0x28, + Self::RelEntityMove(_) => 0x29, + Self::EntityMoveLook(_) => 0x2A, + Self::EntityLook(_) => 0x2B, + Self::Entity(_) => 0x2C, + Self::ClientBoundVehicleMove(_) => 0x2D, + Self::OpenBook(_) => 0x2E, + Self::OpenSignEntity(_) => 0x30, + Self::CraftRecipeResponse(_) => 0x31, + Self::ClientBoundAbilities(_) => 0x32, + Self::CombatEvent(_) => 0x33, + Self::PlayerInfo(_) => 0x34, + Self::ClientBoundPosition(_) => 0x36, + Self::UnlockRecipes(_) => 0x37, + Self::EntityDestroy => 0x38, + Self::RemoveEntityEffect(_) => 0x39, + Self::ResourcePackSend(_) => 0x3A, + Self::Respawn(_) => 0x3B, + Self::EntityHeadRotation(_) => 0x3C, + Self::WorldBorder(_) => 0x3E, + Self::Camera(_) => 0x3F, + Self::ClientBoundHeldItemSlot(_) => 0x40, + Self::UpdateViewPosition(_) => 0x41, + Self::UpdateViewDistance(_) => 0x42, + Self::ScoreboardDisplayObjective(_) => 0x44, + Self::EntityMetadata(_) => 0x45, + Self::AttachEntity(_) => 0x46, + Self::EntityVelocity(_) => 0x47, + Self::EntityEquipment(_) => 0x48, + Self::Experience(_) => 0x49, + Self::UpdateHealth(_) => 0x4A, + Self::ScoreboardObjective(_) => 0x4B, + Self::SetPassengers(_) => 0x4C, + Self::Teams(_) => 0x4D, + Self::ScoreboardScore(_) => 0x4E, + Self::SpawnPosition(_) => 0x43, + Self::UpdateTime(_) => 0x4F, + Self::Title(_) => 0x50, + Self::EntitySoundEffect(_) => 0x51, + Self::StopSound(_) => 0x53, + Self::SoundEffect(_) => 0x52, + Self::PlayerlistHeader(_) => 0x54, + Self::Collect(_) => 0x56, + Self::EntityTeleport(_) => 0x57, + Self::EntityUpdateAttributes(_) => 0x59, + Self::EntityEffect(_) => 0x5A, + Self::SelectAdvancementTab(_) => 0x3D, + Self::DeclareRecipes => 0x5B, + Self::Tags(_) => 0x5C, + Self::AcknowledgePlayerDigging(_) => 0x08, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let spawn_entity = SpawnEntity::decode(reader)?; + + Ok(Self::SpawnEntity(spawn_entity)) + } + 0x01 => { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb::decode(reader)?; + + Ok(Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb)) + } + 0x02 => { + let spawn_entity_weather = SpawnEntityWeather::decode(reader)?; + + Ok(Self::SpawnEntityWeather(spawn_entity_weather)) + } + 0x03 => { + let spawn_entity_living = SpawnEntityLiving::decode(reader)?; + + Ok(Self::SpawnEntityLiving(spawn_entity_living)) + } + 0x04 => { + let spawn_entity_painting = SpawnEntityPainting::decode(reader)?; + + Ok(Self::SpawnEntityPainting(spawn_entity_painting)) + } + 0x05 => { + let named_entity_spawn = NamedEntitySpawn::decode(reader)?; + + Ok(Self::NamedEntitySpawn(named_entity_spawn)) + } + 0x06 => { + let animation = Animation::decode(reader)?; + + Ok(Self::Animation(animation)) + } + 0x07 => Ok(Self::Statistics), + 0x58 => { + let advancements = Advancements::decode(reader)?; + + Ok(Self::Advancements(advancements)) + } + 0x09 => { + let block_break_animation = BlockBreakAnimation::decode(reader)?; + + Ok(Self::BlockBreakAnimation(block_break_animation)) + } + 0x0A => { + let tile_entity_data = TileEntityData::decode(reader)?; + + Ok(Self::TileEntityData(tile_entity_data)) + } + 0x0B => { + let block_action = BlockAction::decode(reader)?; + + Ok(Self::BlockAction(block_action)) + } + 0x0C => { + let block_change = BlockChange::decode(reader)?; + + Ok(Self::BlockChange(block_change)) + } + 0x0D => { + let boss_bar = BossBar::decode(reader)?; + + Ok(Self::BossBar(boss_bar)) + } + 0x0E => { + let difficulty = Difficulty::decode(reader)?; + + Ok(Self::Difficulty(difficulty)) + } + 0x11 => { + let client_bound_tab_complete = ClientBoundTabComplete::decode(reader)?; + + Ok(Self::ClientBoundTabComplete(client_bound_tab_complete)) + } + 0x12 => { + let declare_commands = DeclareCommands::decode(reader)?; + + Ok(Self::DeclareCommands(declare_commands)) + } + 0x35 => { + let face_player = FacePlayer::decode(reader)?; + + Ok(Self::FacePlayer(face_player)) + } + 0x55 => { + let nbt_query_response = NbtQueryResponse::decode(reader)?; + + Ok(Self::NbtQueryResponse(nbt_query_response)) + } + 0x0F => { + let client_bound_chat = ClientBoundChat::decode(reader)?; + + Ok(Self::ClientBoundChat(client_bound_chat)) + } + 0x10 => { + let multi_block_change = MultiBlockChange::decode(reader)?; + + Ok(Self::MultiBlockChange(multi_block_change)) + } + 0x13 => { + let client_bound_transaction = ClientBoundTransaction::decode(reader)?; + + Ok(Self::ClientBoundTransaction(client_bound_transaction)) + } + 0x14 => { + let client_bound_close_window = ClientBoundCloseWindow::decode(reader)?; + + Ok(Self::ClientBoundCloseWindow(client_bound_close_window)) + } + 0x2F => { + let open_window = OpenWindow::decode(reader)?; + + Ok(Self::OpenWindow(open_window)) + } + 0x15 => { + let window_items = WindowItems::decode(reader)?; + + Ok(Self::WindowItems(window_items)) + } + 0x16 => { + let craft_progress_bar = CraftProgressBar::decode(reader)?; + + Ok(Self::CraftProgressBar(craft_progress_bar)) + } + 0x17 => { + let set_slot = SetSlot::decode(reader)?; + + Ok(Self::SetSlot(set_slot)) + } + 0x18 => { + let set_cooldown = SetCooldown::decode(reader)?; + + Ok(Self::SetCooldown(set_cooldown)) + } + 0x19 => { + let client_bound_custom_payload = ClientBoundCustomPayload::decode(reader)?; + + Ok(Self::ClientBoundCustomPayload(client_bound_custom_payload)) + } + 0x1A => { + let named_sound_effect = NamedSoundEffect::decode(reader)?; + + Ok(Self::NamedSoundEffect(named_sound_effect)) + } + 0x1B => { + let kick_disconnect = KickDisconnect::decode(reader)?; + + Ok(Self::KickDisconnect(kick_disconnect)) + } + 0x1C => { + let entity_status = EntityStatus::decode(reader)?; + + Ok(Self::EntityStatus(entity_status)) + } + 0x1D => { + let explosion = Explosion::decode(reader)?; + + Ok(Self::Explosion(explosion)) + } + 0x1E => { + let unload_chunk = UnloadChunk::decode(reader)?; + + Ok(Self::UnloadChunk(unload_chunk)) + } + 0x1F => { + let game_state_change = GameStateChange::decode(reader)?; + + Ok(Self::GameStateChange(game_state_change)) + } + 0x20 => { + let open_horse_window = OpenHorseWindow::decode(reader)?; + + Ok(Self::OpenHorseWindow(open_horse_window)) + } + 0x21 => { + let client_bound_keep_alive = ClientBoundKeepAlive::decode(reader)?; + + Ok(Self::ClientBoundKeepAlive(client_bound_keep_alive)) + } + 0x22 => { + let map_chunk = MapChunk::decode(reader)?; + + Ok(Self::MapChunk(map_chunk)) + } + 0x23 => { + let world_event = WorldEvent::decode(reader)?; + + Ok(Self::WorldEvent(world_event)) + } + 0x24 => { + let world_particles = WorldParticles::decode(reader)?; + + Ok(Self::WorldParticles(world_particles)) + } + 0x25 => { + let update_light = UpdateLight::decode(reader)?; + + Ok(Self::UpdateLight(update_light)) + } + 0x26 => { + let join_game = JoinGame::decode(reader)?; + + Ok(Self::JoinGame(join_game)) + } + 0x27 => { + let map = Map::decode(reader)?; + + Ok(Self::Map(map)) + } + 0x28 => { + let trade_list = TradeList::decode(reader)?; + + Ok(Self::TradeList(trade_list)) + } + 0x29 => { + let rel_entity_move = RelEntityMove::decode(reader)?; + + Ok(Self::RelEntityMove(rel_entity_move)) + } + 0x2A => { + let entity_move_look = EntityMoveLook::decode(reader)?; + + Ok(Self::EntityMoveLook(entity_move_look)) + } + 0x2B => { + let entity_look = EntityLook::decode(reader)?; + + Ok(Self::EntityLook(entity_look)) + } + 0x2C => { + let entity = Entity::decode(reader)?; + + Ok(Self::Entity(entity)) + } + 0x2D => { + let client_bound_vehicle_move = ClientBoundVehicleMove::decode(reader)?; + + Ok(Self::ClientBoundVehicleMove(client_bound_vehicle_move)) + } + 0x2E => { + let open_book = OpenBook::decode(reader)?; + + Ok(Self::OpenBook(open_book)) + } + 0x30 => { + let open_sign_entity = OpenSignEntity::decode(reader)?; + + Ok(Self::OpenSignEntity(open_sign_entity)) + } + 0x31 => { + let craft_recipe_response = CraftRecipeResponse::decode(reader)?; + + Ok(Self::CraftRecipeResponse(craft_recipe_response)) + } + 0x32 => { + let client_bound_abilities = ClientBoundAbilities::decode(reader)?; + + Ok(Self::ClientBoundAbilities(client_bound_abilities)) + } + 0x33 => { + let combat_event = CombatEvent::decode(reader)?; + + Ok(Self::CombatEvent(combat_event)) + } + 0x34 => { + let player_info = PlayerInfo::decode(reader)?; + + Ok(Self::PlayerInfo(player_info)) + } + 0x36 => { + let client_bound_position = ClientBoundPosition::decode(reader)?; + + Ok(Self::ClientBoundPosition(client_bound_position)) + } + 0x37 => { + let unlock_recipes = UnlockRecipes::decode(reader)?; + + Ok(Self::UnlockRecipes(unlock_recipes)) + } + 0x38 => Ok(Self::EntityDestroy), + 0x39 => { + let remove_entity_effect = RemoveEntityEffect::decode(reader)?; + + Ok(Self::RemoveEntityEffect(remove_entity_effect)) + } + 0x3A => { + let resource_pack_send = ResourcePackSend::decode(reader)?; + + Ok(Self::ResourcePackSend(resource_pack_send)) + } + 0x3B => { + let respawn = Respawn::decode(reader)?; + + Ok(Self::Respawn(respawn)) + } + 0x3C => { + let entity_head_rotation = EntityHeadRotation::decode(reader)?; + + Ok(Self::EntityHeadRotation(entity_head_rotation)) + } + 0x3E => { + let world_border = WorldBorder::decode(reader)?; + + Ok(Self::WorldBorder(world_border)) + } + 0x3F => { + let camera = Camera::decode(reader)?; + + Ok(Self::Camera(camera)) + } + 0x40 => { + let client_bound_held_item_slot = ClientBoundHeldItemSlot::decode(reader)?; + + Ok(Self::ClientBoundHeldItemSlot(client_bound_held_item_slot)) + } + 0x41 => { + let update_view_position = UpdateViewPosition::decode(reader)?; + + Ok(Self::UpdateViewPosition(update_view_position)) + } + 0x42 => { + let update_view_distance = UpdateViewDistance::decode(reader)?; + + Ok(Self::UpdateViewDistance(update_view_distance)) + } + 0x44 => { + let scoreboard_display_objective = ScoreboardDisplayObjective::decode(reader)?; + + Ok(Self::ScoreboardDisplayObjective( + scoreboard_display_objective, + )) + } + 0x45 => { + let entity_metadata = EntityMetadata::decode(reader)?; + + Ok(Self::EntityMetadata(entity_metadata)) + } + 0x46 => { + let attach_entity = AttachEntity::decode(reader)?; + + Ok(Self::AttachEntity(attach_entity)) + } + 0x47 => { + let entity_velocity = EntityVelocity::decode(reader)?; + + Ok(Self::EntityVelocity(entity_velocity)) + } + 0x48 => { + let entity_equipment = EntityEquipment::decode(reader)?; + + Ok(Self::EntityEquipment(entity_equipment)) + } + 0x49 => { + let experience = Experience::decode(reader)?; + + Ok(Self::Experience(experience)) + } + 0x4A => { + let update_health = UpdateHealth::decode(reader)?; + + Ok(Self::UpdateHealth(update_health)) + } + 0x4B => { + let scoreboard_objective = ScoreboardObjective::decode(reader)?; + + Ok(Self::ScoreboardObjective(scoreboard_objective)) + } + 0x4C => { + let set_passengers = SetPassengers::decode(reader)?; + + Ok(Self::SetPassengers(set_passengers)) + } + 0x4D => { + let teams = Teams::decode(reader)?; + + Ok(Self::Teams(teams)) + } + 0x4E => { + let scoreboard_score = ScoreboardScore::decode(reader)?; + + Ok(Self::ScoreboardScore(scoreboard_score)) + } + 0x43 => { + let spawn_position = SpawnPosition::decode(reader)?; + + Ok(Self::SpawnPosition(spawn_position)) + } + 0x4F => { + let update_time = UpdateTime::decode(reader)?; + + Ok(Self::UpdateTime(update_time)) + } + 0x50 => { + let title = Title::decode(reader)?; + + Ok(Self::Title(title)) + } + 0x51 => { + let entity_sound_effect = EntitySoundEffect::decode(reader)?; + + Ok(Self::EntitySoundEffect(entity_sound_effect)) + } + 0x53 => { + let stop_sound = StopSound::decode(reader)?; + + Ok(Self::StopSound(stop_sound)) + } + 0x52 => { + let sound_effect = SoundEffect::decode(reader)?; + + Ok(Self::SoundEffect(sound_effect)) + } + 0x54 => { + let playerlist_header = PlayerlistHeader::decode(reader)?; + + Ok(Self::PlayerlistHeader(playerlist_header)) + } + 0x56 => { + let collect = Collect::decode(reader)?; + + Ok(Self::Collect(collect)) + } + 0x57 => { + let entity_teleport = EntityTeleport::decode(reader)?; + + Ok(Self::EntityTeleport(entity_teleport)) + } + 0x59 => { + let entity_update_attributes = EntityUpdateAttributes::decode(reader)?; + + Ok(Self::EntityUpdateAttributes(entity_update_attributes)) + } + 0x5A => { + let entity_effect = EntityEffect::decode(reader)?; + + Ok(Self::EntityEffect(entity_effect)) + } + 0x3D => { + let select_advancement_tab = SelectAdvancementTab::decode(reader)?; + + Ok(Self::SelectAdvancementTab(select_advancement_tab)) + } + 0x5B => Ok(Self::DeclareRecipes), + 0x5C => { + let tags = Tags::decode(reader)?; + + Ok(Self::Tags(tags)) + } + 0x08 => { + let acknowledge_player_digging = AcknowledgePlayerDigging::decode(reader)?; + + Ok(Self::AcknowledgePlayerDigging(acknowledge_player_digging)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn spawn_entity( + entity_id: i32, + object_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + pitch: i8, + yaw: i8, + object_data: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity = SpawnEntity { + entity_id, + object_uuid, + type_, + x, + y, + z, + pitch, + yaw, + object_data, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntity(spawn_entity) + } + + pub fn spawn_entity_experience_orb(entity_id: i32, x: f64, y: f64, z: f64, count: i16) -> Self { + let spawn_entity_experience_orb = SpawnEntityExperienceOrb { + entity_id, + x, + y, + z, + count, + }; + + Self::SpawnEntityExperienceOrb(spawn_entity_experience_orb) + } + + pub fn spawn_entity_weather(entity_id: i32, type_: i8, x: f64, y: f64, z: f64) -> Self { + let spawn_entity_weather = SpawnEntityWeather { + entity_id, + type_, + x, + y, + z, + }; + + Self::SpawnEntityWeather(spawn_entity_weather) + } + + pub fn spawn_entity_living( + entity_id: i32, + entity_uuid: Uuid, + type_: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + head_pitch: i8, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let spawn_entity_living = SpawnEntityLiving { + entity_id, + entity_uuid, + type_, + x, + y, + z, + yaw, + pitch, + head_pitch, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::SpawnEntityLiving(spawn_entity_living) + } + + pub fn spawn_entity_painting( + entity_id: i32, + entity_uuid: Uuid, + title: i32, + location: Position, + direction: u8, + ) -> Self { + let spawn_entity_painting = SpawnEntityPainting { + entity_id, + entity_uuid, + title, + location, + direction, + }; + + Self::SpawnEntityPainting(spawn_entity_painting) + } + + pub fn named_entity_spawn( + entity_id: i32, + player_uuid: Uuid, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + ) -> Self { + let named_entity_spawn = NamedEntitySpawn { + entity_id, + player_uuid, + x, + y, + z, + yaw, + pitch, + }; + + Self::NamedEntitySpawn(named_entity_spawn) + } + + pub fn animation(entity_id: i32, animation: u8) -> Self { + let animation = Animation { + entity_id, + animation, + }; + + Self::Animation(animation) + } + + pub fn statistics() -> Self { + Self::Statistics + } + + pub fn advancements(reset: bool) -> Self { + let advancements = Advancements { reset }; + + Self::Advancements(advancements) + } + + pub fn block_break_animation(entity_id: i32, location: Position, destroy_stage: i8) -> Self { + let block_break_animation = BlockBreakAnimation { + entity_id, + location, + destroy_stage, + }; + + Self::BlockBreakAnimation(block_break_animation) + } + + pub fn tile_entity_data(location: Position, action: u8, nbt_data: CompoundTag) -> Self { + let tile_entity_data = TileEntityData { + location, + action, + nbt_data, + }; + + Self::TileEntityData(tile_entity_data) + } + + pub fn block_action(location: Position, byte1: u8, byte2: u8, block_id: i32) -> Self { + let block_action = BlockAction { + location, + byte1, + byte2, + block_id, + }; + + Self::BlockAction(block_action) + } + + pub fn block_change(location: Position, type_: i32) -> Self { + let block_change = BlockChange { location, type_ }; + + Self::BlockChange(block_change) + } + + pub fn boss_bar(entity_uuid: Uuid, action: i32) -> Self { + let boss_bar = BossBar { + entity_uuid, + action, + }; + + Self::BossBar(boss_bar) + } + + pub fn difficulty(difficulty: u8, difficulty_locked: bool) -> Self { + let difficulty = Difficulty { + difficulty, + difficulty_locked, + }; + + Self::Difficulty(difficulty) + } + + pub fn client_bound_tab_complete(transaction_id: i32, start: i32, length: i32) -> Self { + let client_bound_tab_complete = ClientBoundTabComplete { + transaction_id, + start, + length, + }; + + Self::ClientBoundTabComplete(client_bound_tab_complete) + } + + pub fn declare_commands(root_index: i32) -> Self { + let declare_commands = DeclareCommands { root_index }; + + Self::DeclareCommands(declare_commands) + } + + pub fn face_player(feet_eyes: i32, x: f64, y: f64, z: f64, is_entity: bool) -> Self { + let face_player = FacePlayer { + feet_eyes, + x, + y, + z, + is_entity, + }; + + Self::FacePlayer(face_player) + } + + pub fn nbt_query_response(transaction_id: i32, nbt: CompoundTag) -> Self { + let nbt_query_response = NbtQueryResponse { + transaction_id, + nbt, + }; + + Self::NbtQueryResponse(nbt_query_response) + } + + pub fn client_bound_chat(message: String, position: i8) -> Self { + let client_bound_chat = ClientBoundChat { message, position }; + + Self::ClientBoundChat(client_bound_chat) + } + + pub fn multi_block_change(chunk_x: i32, chunk_z: i32) -> Self { + let multi_block_change = MultiBlockChange { chunk_x, chunk_z }; + + Self::MultiBlockChange(multi_block_change) + } + + pub fn client_bound_transaction(window_id: i8, action: i16, accepted: bool) -> Self { + let client_bound_transaction = ClientBoundTransaction { + window_id, + action, + accepted, + }; + + Self::ClientBoundTransaction(client_bound_transaction) + } + + pub fn client_bound_close_window(window_id: u8) -> Self { + let client_bound_close_window = ClientBoundCloseWindow { window_id }; + + Self::ClientBoundCloseWindow(client_bound_close_window) + } + + pub fn open_window(window_id: i32, inventory_type: i32, window_title: String) -> Self { + let open_window = OpenWindow { + window_id, + inventory_type, + window_title, + }; + + Self::OpenWindow(open_window) + } + + pub fn window_items(window_id: u8) -> Self { + let window_items = WindowItems { window_id }; + + Self::WindowItems(window_items) + } + + pub fn craft_progress_bar(window_id: u8, property: i16, value: i16) -> Self { + let craft_progress_bar = CraftProgressBar { + window_id, + property, + value, + }; + + Self::CraftProgressBar(craft_progress_bar) + } + + pub fn set_slot(window_id: i8, slot: i16, item: Option) -> Self { + let set_slot = SetSlot { + window_id, + slot, + item, + }; + + Self::SetSlot(set_slot) + } + + pub fn set_cooldown(item_id: i32, cooldown_ticks: i32) -> Self { + let set_cooldown = SetCooldown { + item_id, + cooldown_ticks, + }; + + Self::SetCooldown(set_cooldown) + } + + pub fn client_bound_custom_payload(channel: String, data: Vec) -> Self { + let client_bound_custom_payload = ClientBoundCustomPayload { channel, data }; + + Self::ClientBoundCustomPayload(client_bound_custom_payload) + } + + pub fn named_sound_effect( + sound_name: String, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let named_sound_effect = NamedSoundEffect { + sound_name, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::NamedSoundEffect(named_sound_effect) + } + + pub fn kick_disconnect(reason: String) -> Self { + let kick_disconnect = KickDisconnect { reason }; + + Self::KickDisconnect(kick_disconnect) + } + + pub fn entity_status(entity_id: i32, entity_status: i8) -> Self { + let entity_status = EntityStatus { + entity_id, + entity_status, + }; + + Self::EntityStatus(entity_status) + } + + pub fn explosion( + x: f32, + y: f32, + z: f32, + radius: f32, + player_motion_x: f32, + player_motion_y: f32, + player_motion_z: f32, + ) -> Self { + let explosion = Explosion { + x, + y, + z, + radius, + player_motion_x, + player_motion_y, + player_motion_z, + }; + + Self::Explosion(explosion) + } + + pub fn unload_chunk(chunk_x: i32, chunk_z: i32) -> Self { + let unload_chunk = UnloadChunk { chunk_x, chunk_z }; + + Self::UnloadChunk(unload_chunk) + } + + pub fn game_state_change(reason: u8, game_mode: f32) -> Self { + let game_state_change = GameStateChange { reason, game_mode }; + + Self::GameStateChange(game_state_change) + } + + pub fn open_horse_window(window_id: u8, nb_slots: i32, entity_id: i32) -> Self { + let open_horse_window = OpenHorseWindow { + window_id, + nb_slots, + entity_id, + }; + + Self::OpenHorseWindow(open_horse_window) + } + + pub fn client_bound_keep_alive(keep_alive_id: i64) -> Self { + let client_bound_keep_alive = ClientBoundKeepAlive { keep_alive_id }; + + Self::ClientBoundKeepAlive(client_bound_keep_alive) + } + + pub fn map_chunk( + x: i32, + z: i32, + ground_up: bool, + bit_map: i32, + heightmaps: CompoundTag, + chunk_data: Vec, + ) -> Self { + let map_chunk = MapChunk { + x, + z, + ground_up, + bit_map, + heightmaps, + chunk_data, + }; + + Self::MapChunk(map_chunk) + } + + pub fn world_event(effect_id: i32, location: Position, data: i32, global: bool) -> Self { + let world_event = WorldEvent { + effect_id, + location, + data, + global, + }; + + Self::WorldEvent(world_event) + } + + pub fn world_particles( + particle_id: i32, + long_distance: bool, + x: f64, + y: f64, + z: f64, + offset_x: f32, + offset_y: f32, + offset_z: f32, + particle_data: f32, + particles: i32, + data: ParticleData, + ) -> Self { + let world_particles = WorldParticles { + particle_id, + long_distance, + x, + y, + z, + offset_x, + offset_y, + offset_z, + particle_data, + particles, + data, + }; + + Self::WorldParticles(world_particles) + } + + pub fn update_light( + chunk_x: i32, + chunk_z: i32, + sky_light_mask: i32, + block_light_mask: i32, + empty_sky_light_mask: i32, + empty_block_light_mask: i32, + data: Vec, + ) -> Self { + let update_light = UpdateLight { + chunk_x, + chunk_z, + sky_light_mask, + block_light_mask, + empty_sky_light_mask, + empty_block_light_mask, + data, + }; + + Self::UpdateLight(update_light) + } + + pub fn join_game( + entity_id: i32, + game_mode: u8, + dimension: i32, + hashed_seed: i64, + max_players: u8, + level_type: String, + view_distance: i32, + reduced_debug_info: bool, + enable_respawn_screen: bool, + ) -> Self { + let join_game = JoinGame { + entity_id, + game_mode, + dimension, + hashed_seed, + max_players, + level_type, + view_distance, + reduced_debug_info, + enable_respawn_screen, + }; + + Self::JoinGame(join_game) + } + + pub fn map( + item_damage: i32, + scale: i8, + tracking_position: bool, + locked: bool, + columns: i8, + ) -> Self { + let map = Map { + item_damage, + scale, + tracking_position, + locked, + columns, + }; + + Self::Map(map) + } + + pub fn trade_list( + window_id: i32, + villager_level: i32, + experience: i32, + is_regular_villager: bool, + can_restock: bool, + ) -> Self { + let trade_list = TradeList { + window_id, + villager_level, + experience, + is_regular_villager, + can_restock, + }; + + Self::TradeList(trade_list) + } + + pub fn rel_entity_move(entity_id: i32, d_x: i16, d_y: i16, d_z: i16, on_ground: bool) -> Self { + let rel_entity_move = RelEntityMove { + entity_id, + d_x, + d_y, + d_z, + on_ground, + }; + + Self::RelEntityMove(rel_entity_move) + } + + pub fn entity_move_look( + entity_id: i32, + d_x: i16, + d_y: i16, + d_z: i16, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_move_look = EntityMoveLook { + entity_id, + d_x, + d_y, + d_z, + yaw, + pitch, + on_ground, + }; + + Self::EntityMoveLook(entity_move_look) + } + + pub fn entity_look(entity_id: i32, yaw: i8, pitch: i8, on_ground: bool) -> Self { + let entity_look = EntityLook { + entity_id, + yaw, + pitch, + on_ground, + }; + + Self::EntityLook(entity_look) + } + + pub fn entity(entity_id: i32) -> Self { + let entity = Entity { entity_id }; + + Self::Entity(entity) + } + + pub fn client_bound_vehicle_move(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> Self { + let client_bound_vehicle_move = ClientBoundVehicleMove { + x, + y, + z, + yaw, + pitch, + }; + + Self::ClientBoundVehicleMove(client_bound_vehicle_move) + } + + pub fn open_book(hand: i32) -> Self { + let open_book = OpenBook { hand }; + + Self::OpenBook(open_book) + } + + pub fn open_sign_entity(location: Position) -> Self { + let open_sign_entity = OpenSignEntity { location }; + + Self::OpenSignEntity(open_sign_entity) + } + + pub fn craft_recipe_response(window_id: i8, recipe: String) -> Self { + let craft_recipe_response = CraftRecipeResponse { window_id, recipe }; + + Self::CraftRecipeResponse(craft_recipe_response) + } + + pub fn client_bound_abilities(flags: i8, flying_speed: f32, walking_speed: f32) -> Self { + let client_bound_abilities = ClientBoundAbilities { + flags, + flying_speed, + walking_speed, + }; + + Self::ClientBoundAbilities(client_bound_abilities) + } + + pub fn combat_event(event: i32) -> Self { + let combat_event = CombatEvent { event }; + + Self::CombatEvent(combat_event) + } + + pub fn player_info(action: i32) -> Self { + let player_info = PlayerInfo { action }; + + Self::PlayerInfo(player_info) + } + + pub fn client_bound_position( + x: f64, + y: f64, + z: f64, + yaw: f32, + pitch: f32, + flags: i8, + teleport_id: i32, + ) -> Self { + let client_bound_position = ClientBoundPosition { + x, + y, + z, + yaw, + pitch, + flags, + teleport_id, + }; + + Self::ClientBoundPosition(client_bound_position) + } + + pub fn unlock_recipes( + action: i32, + crafting_book_open: bool, + filtering_craftable: bool, + smelting_book_open: bool, + filtering_smeltable: bool, + ) -> Self { + let unlock_recipes = UnlockRecipes { + action, + crafting_book_open, + filtering_craftable, + smelting_book_open, + filtering_smeltable, + }; + + Self::UnlockRecipes(unlock_recipes) + } + + pub fn entity_destroy() -> Self { + Self::EntityDestroy + } + + pub fn remove_entity_effect(entity_id: i32, effect_id: i8) -> Self { + let remove_entity_effect = RemoveEntityEffect { + entity_id, + effect_id, + }; + + Self::RemoveEntityEffect(remove_entity_effect) + } + + pub fn resource_pack_send(url: String, hash: String) -> Self { + let resource_pack_send = ResourcePackSend { url, hash }; + + Self::ResourcePackSend(resource_pack_send) + } + + pub fn respawn(dimension: i32, hashed_seed: i64, gamemode: u8, level_type: String) -> Self { + let respawn = Respawn { + dimension, + hashed_seed, + gamemode, + level_type, + }; + + Self::Respawn(respawn) + } + + pub fn entity_head_rotation(entity_id: i32, head_yaw: i8) -> Self { + let entity_head_rotation = EntityHeadRotation { + entity_id, + head_yaw, + }; + + Self::EntityHeadRotation(entity_head_rotation) + } + + pub fn world_border(action: i32) -> Self { + let world_border = WorldBorder { action }; + + Self::WorldBorder(world_border) + } + + pub fn camera(camera_id: i32) -> Self { + let camera = Camera { camera_id }; + + Self::Camera(camera) + } + + pub fn client_bound_held_item_slot(slot: i8) -> Self { + let client_bound_held_item_slot = ClientBoundHeldItemSlot { slot }; + + Self::ClientBoundHeldItemSlot(client_bound_held_item_slot) + } + + pub fn update_view_position(chunk_x: i32, chunk_z: i32) -> Self { + let update_view_position = UpdateViewPosition { chunk_x, chunk_z }; + + Self::UpdateViewPosition(update_view_position) + } + + pub fn update_view_distance(view_distance: i32) -> Self { + let update_view_distance = UpdateViewDistance { view_distance }; + + Self::UpdateViewDistance(update_view_distance) + } + + pub fn scoreboard_display_objective(position: i8, name: String) -> Self { + let scoreboard_display_objective = ScoreboardDisplayObjective { position, name }; + + Self::ScoreboardDisplayObjective(scoreboard_display_objective) + } + + pub fn entity_metadata(entity_id: i32, metadata: Metadata) -> Self { + let entity_metadata = EntityMetadata { + entity_id, + metadata, + }; + + Self::EntityMetadata(entity_metadata) + } + + pub fn attach_entity(entity_id: i32, vehicle_id: i32) -> Self { + let attach_entity = AttachEntity { + entity_id, + vehicle_id, + }; + + Self::AttachEntity(attach_entity) + } + + pub fn entity_velocity( + entity_id: i32, + velocity_x: i16, + velocity_y: i16, + velocity_z: i16, + ) -> Self { + let entity_velocity = EntityVelocity { + entity_id, + velocity_x, + velocity_y, + velocity_z, + }; + + Self::EntityVelocity(entity_velocity) + } + + pub fn entity_equipment(entity_id: i32, slot: i32, item: Option) -> Self { + let entity_equipment = EntityEquipment { + entity_id, + slot, + item, + }; + + Self::EntityEquipment(entity_equipment) + } + + pub fn experience(experience_bar: f32, level: i32, total_experience: i32) -> Self { + let experience = Experience { + experience_bar, + level, + total_experience, + }; + + Self::Experience(experience) + } + + pub fn update_health(health: f32, food: i32, food_saturation: f32) -> Self { + let update_health = UpdateHealth { + health, + food, + food_saturation, + }; + + Self::UpdateHealth(update_health) + } + + pub fn scoreboard_objective(name: String, action: i8) -> Self { + let scoreboard_objective = ScoreboardObjective { name, action }; + + Self::ScoreboardObjective(scoreboard_objective) + } + + pub fn set_passengers(entity_id: i32) -> Self { + let set_passengers = SetPassengers { entity_id }; + + Self::SetPassengers(set_passengers) + } + + pub fn teams(team: String, mode: i8) -> Self { + let teams = Teams { team, mode }; + + Self::Teams(teams) + } + + pub fn scoreboard_score(item_name: String, action: i8, score_name: String) -> Self { + let scoreboard_score = ScoreboardScore { + item_name, + action, + score_name, + }; + + Self::ScoreboardScore(scoreboard_score) + } + + pub fn spawn_position(location: Position) -> Self { + let spawn_position = SpawnPosition { location }; + + Self::SpawnPosition(spawn_position) + } + + pub fn update_time(age: i64, time: i64) -> Self { + let update_time = UpdateTime { age, time }; + + Self::UpdateTime(update_time) + } + + pub fn title(action: i32) -> Self { + let title = Title { action }; + + Self::Title(title) + } + + pub fn entity_sound_effect( + sound_id: i32, + sound_category: i32, + entity_id: i32, + volume: f32, + pitch: f32, + ) -> Self { + let entity_sound_effect = EntitySoundEffect { + sound_id, + sound_category, + entity_id, + volume, + pitch, + }; + + Self::EntitySoundEffect(entity_sound_effect) + } + + pub fn stop_sound(flags: i8) -> Self { + let stop_sound = StopSound { flags }; + + Self::StopSound(stop_sound) + } + + pub fn sound_effect( + sound_id: i32, + sound_category: i32, + x: i32, + y: i32, + z: i32, + volume: f32, + pitch: f32, + ) -> Self { + let sound_effect = SoundEffect { + sound_id, + sound_category, + x, + y, + z, + volume, + pitch, + }; + + Self::SoundEffect(sound_effect) + } + + pub fn playerlist_header(header: String, footer: String) -> Self { + let playerlist_header = PlayerlistHeader { header, footer }; + + Self::PlayerlistHeader(playerlist_header) + } + + pub fn collect( + collected_entity_id: i32, + collector_entity_id: i32, + pickup_item_count: i32, + ) -> Self { + let collect = Collect { + collected_entity_id, + collector_entity_id, + pickup_item_count, + }; + + Self::Collect(collect) + } + + pub fn entity_teleport( + entity_id: i32, + x: f64, + y: f64, + z: f64, + yaw: i8, + pitch: i8, + on_ground: bool, + ) -> Self { + let entity_teleport = EntityTeleport { + entity_id, + x, + y, + z, + yaw, + pitch, + on_ground, + }; + + Self::EntityTeleport(entity_teleport) + } + + pub fn entity_update_attributes(entity_id: i32) -> Self { + let entity_update_attributes = EntityUpdateAttributes { entity_id }; + + Self::EntityUpdateAttributes(entity_update_attributes) + } + + pub fn entity_effect( + entity_id: i32, + effect_id: i8, + amplifier: i8, + duration: i32, + hide_particles: i8, + ) -> Self { + let entity_effect = EntityEffect { + entity_id, + effect_id, + amplifier, + duration, + hide_particles, + }; + + Self::EntityEffect(entity_effect) + } + + pub fn select_advancement_tab(id: String) -> Self { + let select_advancement_tab = SelectAdvancementTab { id }; + + Self::SelectAdvancementTab(select_advancement_tab) + } + + pub fn declare_recipes() -> Self { + Self::DeclareRecipes + } + + pub fn tags( + block_tags: TagsMap, + item_tags: TagsMap, + fluid_tags: TagsMap, + entity_tags: TagsMap, + ) -> Self { + let tags = Tags { + block_tags, + item_tags, + fluid_tags, + entity_tags, + }; + + Self::Tags(tags) + } + + pub fn acknowledge_player_digging( + location: Position, + block: i32, + status: i32, + successful: bool, + ) -> Self { + let acknowledge_player_digging = AcknowledgePlayerDigging { + location, + block, + status, + successful, + }; + + Self::AcknowledgePlayerDigging(acknowledge_player_digging) + } +} + +#[derive(Packet, Debug)] +pub struct TeleportConfirm { + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryBlockNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct SetDifficulty { + pub new_difficulty: u8, +} + +#[derive(Packet, Debug)] +pub struct EditBook { + pub new_book: Option, + pub signing: bool, + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct QueryEntityNbt { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct PickItem { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct NameItem { + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct SelectTrade { + #[packet(with = "var_int")] + pub slot: i32, +} + +#[derive(Packet, Debug)] +pub struct SetBeaconEffect { + #[packet(with = "var_int")] + pub primary_effect: i32, + #[packet(with = "var_int")] + pub secondary_effect: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlock { + pub location: Position, + pub command: String, + #[packet(with = "var_int")] + pub mode: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct UpdateCommandBlockMinecart { + #[packet(with = "var_int")] + pub entity_id: i32, + pub command: String, + pub track_output: bool, +} + +#[derive(Packet, Debug)] +pub struct UpdateStructureBlock { + pub location: Position, + #[packet(with = "var_int")] + pub action: i32, + #[packet(with = "var_int")] + pub mode: i32, + pub name: String, + pub offset_x: u8, + pub offset_y: u8, + pub offset_z: u8, + pub size_x: u8, + pub size_y: u8, + pub size_z: u8, + #[packet(with = "var_int")] + pub mirror: i32, + #[packet(with = "var_int")] + pub rotation: i32, + pub metadata: String, + pub integrity: f32, + #[packet(with = "var_int")] + pub seed: i32, + pub flags: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub text: String, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundChat { + pub message: String, +} + +#[derive(Packet, Debug)] +pub struct ClientCommand { + #[packet(with = "var_int")] + pub action_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Settings { + pub locale: String, + pub view_distance: i8, + #[packet(with = "var_int")] + pub chat_flags: i32, + pub chat_colors: bool, + pub skin_parts: u8, + #[packet(with = "var_int")] + pub main_hand: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct EnchantItem { + pub window_id: i8, + pub enchantment: i8, +} + +#[derive(Packet, Debug)] +pub struct WindowClick { + pub window_id: u8, + pub slot: i16, + pub mouse_button: i8, + pub action: i16, + pub mode: i8, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct UseEntity { + #[packet(with = "var_int")] + pub target: i32, + #[packet(with = "var_int")] + pub mouse: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct LockDifficulty { + pub locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct PositionLook { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Look { + pub yaw: f32, + pub pitch: f32, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Flying { + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct SteerBoat { + pub left_paddle: bool, + pub right_paddle: bool, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeRequest { + pub window_id: i8, + pub recipe: String, + pub make_all: bool, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct BlockDig { + pub status: i8, + pub location: Position, + pub face: i8, +} + +#[derive(Packet, Debug)] +pub struct EntityAction { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub action_id: i32, + #[packet(with = "var_int")] + pub jump_boost: i32, +} + +#[derive(Packet, Debug)] +pub struct SteerVehicle { + pub sideways: f32, + pub forward: f32, + pub jump: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftingBookData { + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackReceive { + #[packet(with = "var_int")] + pub result: i32, +} + +#[derive(Packet, Debug)] +pub struct ServerBoundHeldItemSlot { + pub slot_id: i16, +} + +#[derive(Packet, Debug)] +pub struct SetCreativeSlot { + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct UpdateJigsawBlock { + pub location: Position, + pub name: String, + pub target: String, + pub pool: String, + pub final_state: String, + pub joint_type: String, +} + +#[derive(Packet, Debug)] +pub struct UpdateSign { + pub location: Position, + pub text1: String, + pub text2: String, + pub text3: String, + pub text4: String, +} + +#[derive(Packet, Debug)] +pub struct ArmAnimation { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct Spectate { + pub target: Uuid, +} + +#[derive(Packet, Debug)] +pub struct BlockPlace { + #[packet(with = "var_int")] + pub hand: i32, + pub location: Position, + #[packet(with = "var_int")] + pub direction: i32, + pub cursor_x: f32, + pub cursor_y: f32, + pub cursor_z: f32, + pub inside_block: bool, +} + +#[derive(Packet, Debug)] +pub struct UseItem { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct AdvancementTab { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub object_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub pitch: i8, + pub yaw: i8, + pub object_data: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityExperienceOrb { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub count: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityWeather { + #[packet(with = "var_int")] + pub entity_id: i32, + pub type_: i8, + pub x: f64, + pub y: f64, + pub z: f64, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityLiving { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub type_: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub head_pitch: i8, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct SpawnEntityPainting { + #[packet(with = "var_int")] + pub entity_id: i32, + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub title: i32, + pub location: Position, + pub direction: u8, +} + +#[derive(Packet, Debug)] +pub struct NamedEntitySpawn { + #[packet(with = "var_int")] + pub entity_id: i32, + pub player_uuid: Uuid, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, +} + +#[derive(Packet, Debug)] +pub struct Animation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub animation: u8, +} + +#[derive(Packet, Debug)] +pub struct Advancements { + pub reset: bool, +} + +#[derive(Packet, Debug)] +pub struct BlockBreakAnimation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub location: Position, + pub destroy_stage: i8, +} + +#[derive(Packet, Debug)] +pub struct TileEntityData { + pub location: Position, + pub action: u8, + pub nbt_data: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct BlockAction { + pub location: Position, + pub byte1: u8, + pub byte2: u8, + #[packet(with = "var_int")] + pub block_id: i32, +} + +#[derive(Packet, Debug)] +pub struct BlockChange { + pub location: Position, + #[packet(with = "var_int")] + pub type_: i32, +} + +#[derive(Packet, Debug)] +pub struct BossBar { + pub entity_uuid: Uuid, + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Difficulty { + pub difficulty: u8, + pub difficulty_locked: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTabComplete { + #[packet(with = "var_int")] + pub transaction_id: i32, + #[packet(with = "var_int")] + pub start: i32, + #[packet(with = "var_int")] + pub length: i32, +} + +#[derive(Packet, Debug)] +pub struct DeclareCommands { + #[packet(with = "var_int")] + pub root_index: i32, +} + +#[derive(Packet, Debug)] +pub struct FacePlayer { + #[packet(with = "var_int")] + pub feet_eyes: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub is_entity: bool, +} + +#[derive(Packet, Debug)] +pub struct NbtQueryResponse { + #[packet(with = "var_int")] + pub transaction_id: i32, + pub nbt: CompoundTag, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundChat { + pub message: String, + pub position: i8, +} + +#[derive(Packet, Debug)] +pub struct MultiBlockChange { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundTransaction { + pub window_id: i8, + pub action: i16, + pub accepted: bool, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCloseWindow { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct OpenWindow { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub inventory_type: i32, + pub window_title: String, +} + +#[derive(Packet, Debug)] +pub struct WindowItems { + pub window_id: u8, +} + +#[derive(Packet, Debug)] +pub struct CraftProgressBar { + pub window_id: u8, + pub property: i16, + pub value: i16, +} + +#[derive(Packet, Debug)] +pub struct SetSlot { + pub window_id: i8, + pub slot: i16, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct SetCooldown { + #[packet(with = "var_int")] + pub item_id: i32, + #[packet(with = "var_int")] + pub cooldown_ticks: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundCustomPayload { + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct NamedSoundEffect { + pub sound_name: String, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct KickDisconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EntityStatus { + pub entity_id: i32, + pub entity_status: i8, +} + +#[derive(Packet, Debug)] +pub struct Explosion { + pub x: f32, + pub y: f32, + pub z: f32, + pub radius: f32, + pub player_motion_x: f32, + pub player_motion_y: f32, + pub player_motion_z: f32, +} + +#[derive(Packet, Debug)] +pub struct UnloadChunk { + pub chunk_x: i32, + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct GameStateChange { + pub reason: u8, + pub game_mode: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenHorseWindow { + pub window_id: u8, + #[packet(with = "var_int")] + pub nb_slots: i32, + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundKeepAlive { + pub keep_alive_id: i64, +} + +#[derive(Packet, Debug)] +pub struct MapChunk { + pub x: i32, + pub z: i32, + pub ground_up: bool, + #[packet(with = "var_int")] + pub bit_map: i32, + pub heightmaps: CompoundTag, + pub chunk_data: Vec, +} + +#[derive(Packet, Debug)] +pub struct WorldEvent { + pub effect_id: i32, + pub location: Position, + pub data: i32, + pub global: bool, +} + +#[derive(Packet, Debug)] +pub struct WorldParticles { + pub particle_id: i32, + pub long_distance: bool, + pub x: f64, + pub y: f64, + pub z: f64, + pub offset_x: f32, + pub offset_y: f32, + pub offset_z: f32, + pub particle_data: f32, + pub particles: i32, + pub data: ParticleData, +} + +#[derive(Packet, Debug)] +pub struct UpdateLight { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, + #[packet(with = "var_int")] + pub sky_light_mask: i32, + #[packet(with = "var_int")] + pub block_light_mask: i32, + #[packet(with = "var_int")] + pub empty_sky_light_mask: i32, + #[packet(with = "var_int")] + pub empty_block_light_mask: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct JoinGame { + pub entity_id: i32, + pub game_mode: u8, + pub dimension: i32, + pub hashed_seed: i64, + pub max_players: u8, + pub level_type: String, + #[packet(with = "var_int")] + pub view_distance: i32, + pub reduced_debug_info: bool, + pub enable_respawn_screen: bool, +} + +#[derive(Packet, Debug)] +pub struct Map { + #[packet(with = "var_int")] + pub item_damage: i32, + pub scale: i8, + pub tracking_position: bool, + pub locked: bool, + pub columns: i8, +} + +#[derive(Packet, Debug)] +pub struct TradeList { + #[packet(with = "var_int")] + pub window_id: i32, + #[packet(with = "var_int")] + pub villager_level: i32, + #[packet(with = "var_int")] + pub experience: i32, + pub is_regular_villager: bool, + pub can_restock: bool, +} + +#[derive(Packet, Debug)] +pub struct RelEntityMove { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityMoveLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub d_x: i16, + pub d_y: i16, + pub d_z: i16, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityLook { + #[packet(with = "var_int")] + pub entity_id: i32, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct Entity { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundVehicleMove { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct OpenBook { + #[packet(with = "var_int")] + pub hand: i32, +} + +#[derive(Packet, Debug)] +pub struct OpenSignEntity { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct CraftRecipeResponse { + pub window_id: i8, + pub recipe: String, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundAbilities { + pub flags: i8, + pub flying_speed: f32, + pub walking_speed: f32, +} + +#[derive(Packet, Debug)] +pub struct CombatEvent { + #[packet(with = "var_int")] + pub event: i32, +} + +#[derive(Packet, Debug)] +pub struct PlayerInfo { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundPosition { + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: f32, + pub pitch: f32, + pub flags: i8, + #[packet(with = "var_int")] + pub teleport_id: i32, +} + +#[derive(Packet, Debug)] +pub struct UnlockRecipes { + #[packet(with = "var_int")] + pub action: i32, + pub crafting_book_open: bool, + pub filtering_craftable: bool, + pub smelting_book_open: bool, + pub filtering_smeltable: bool, +} + +#[derive(Packet, Debug)] +pub struct RemoveEntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, +} + +#[derive(Packet, Debug)] +pub struct ResourcePackSend { + pub url: String, + pub hash: String, +} + +#[derive(Packet, Debug)] +pub struct Respawn { + pub dimension: i32, + pub hashed_seed: i64, + pub gamemode: u8, + pub level_type: String, +} + +#[derive(Packet, Debug)] +pub struct EntityHeadRotation { + #[packet(with = "var_int")] + pub entity_id: i32, + pub head_yaw: i8, +} + +#[derive(Packet, Debug)] +pub struct WorldBorder { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct Camera { + #[packet(with = "var_int")] + pub camera_id: i32, +} + +#[derive(Packet, Debug)] +pub struct ClientBoundHeldItemSlot { + pub slot: i8, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewPosition { + #[packet(with = "var_int")] + pub chunk_x: i32, + #[packet(with = "var_int")] + pub chunk_z: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateViewDistance { + #[packet(with = "var_int")] + pub view_distance: i32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardDisplayObjective { + pub position: i8, + pub name: String, +} + +#[derive(Packet, Debug)] +pub struct EntityMetadata { + #[packet(with = "var_int")] + pub entity_id: i32, + pub metadata: Metadata, +} + +#[derive(Packet, Debug)] +pub struct AttachEntity { + pub entity_id: i32, + pub vehicle_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityVelocity { + #[packet(with = "var_int")] + pub entity_id: i32, + pub velocity_x: i16, + pub velocity_y: i16, + pub velocity_z: i16, +} + +#[derive(Packet, Debug)] +pub struct EntityEquipment { + #[packet(with = "var_int")] + pub entity_id: i32, + #[packet(with = "var_int")] + pub slot: i32, + pub item: Option, +} + +#[derive(Packet, Debug)] +pub struct Experience { + pub experience_bar: f32, + #[packet(with = "var_int")] + pub level: i32, + #[packet(with = "var_int")] + pub total_experience: i32, +} + +#[derive(Packet, Debug)] +pub struct UpdateHealth { + pub health: f32, + #[packet(with = "var_int")] + pub food: i32, + pub food_saturation: f32, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardObjective { + pub name: String, + pub action: i8, +} + +#[derive(Packet, Debug)] +pub struct SetPassengers { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct Teams { + pub team: String, + pub mode: i8, +} + +#[derive(Packet, Debug)] +pub struct ScoreboardScore { + pub item_name: String, + pub action: i8, + pub score_name: String, +} + +#[derive(Packet, Debug)] +pub struct SpawnPosition { + pub location: Position, +} + +#[derive(Packet, Debug)] +pub struct UpdateTime { + pub age: i64, + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct Title { + #[packet(with = "var_int")] + pub action: i32, +} + +#[derive(Packet, Debug)] +pub struct EntitySoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + #[packet(with = "var_int")] + pub entity_id: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct StopSound { + pub flags: i8, +} + +#[derive(Packet, Debug)] +pub struct SoundEffect { + #[packet(with = "var_int")] + pub sound_id: i32, + #[packet(with = "var_int")] + pub sound_category: i32, + pub x: i32, + pub y: i32, + pub z: i32, + pub volume: f32, + pub pitch: f32, +} + +#[derive(Packet, Debug)] +pub struct PlayerlistHeader { + pub header: String, + pub footer: String, +} + +#[derive(Packet, Debug)] +pub struct Collect { + #[packet(with = "var_int")] + pub collected_entity_id: i32, + #[packet(with = "var_int")] + pub collector_entity_id: i32, + #[packet(with = "var_int")] + pub pickup_item_count: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityTeleport { + #[packet(with = "var_int")] + pub entity_id: i32, + pub x: f64, + pub y: f64, + pub z: f64, + pub yaw: i8, + pub pitch: i8, + pub on_ground: bool, +} + +#[derive(Packet, Debug)] +pub struct EntityUpdateAttributes { + #[packet(with = "var_int")] + pub entity_id: i32, +} + +#[derive(Packet, Debug)] +pub struct EntityEffect { + #[packet(with = "var_int")] + pub entity_id: i32, + pub effect_id: i8, + pub amplifier: i8, + #[packet(with = "var_int")] + pub duration: i32, + pub hide_particles: i8, +} + +#[derive(Packet, Debug)] +pub struct SelectAdvancementTab { + pub id: String, +} + +#[derive(Packet, Debug)] +pub struct Tags { + pub block_tags: TagsMap, + pub item_tags: TagsMap, + pub fluid_tags: TagsMap, + pub entity_tags: TagsMap, +} + +#[derive(Packet, Debug)] +pub struct AcknowledgePlayerDigging { + pub location: Position, + #[packet(with = "var_int")] + pub block: i32, + #[packet(with = "var_int")] + pub status: i32, + pub successful: bool, +} diff --git a/protocol/src/version/v_20w13b/handshake.rs b/protocol/src/version/v_20w13b/handshake.rs new file mode 100644 index 0000000..0ca7960 --- /dev/null +++ b/protocol/src/version/v_20w13b/handshake.rs @@ -0,0 +1,55 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundHandshakePacket { + SetProtocol(SetProtocol), +} + +impl ServerBoundHandshakePacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::SetProtocol(_) => 0x00, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let set_protocol = SetProtocol::decode(reader)?; + + Ok(Self::SetProtocol(set_protocol)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn set_protocol( + protocol_version: i32, + server_host: String, + server_port: u16, + next_state: i32, + ) -> Self { + let set_protocol = SetProtocol { + protocol_version, + server_host, + server_port, + next_state, + }; + + Self::SetProtocol(set_protocol) + } +} + +#[derive(Packet, Debug)] +pub struct SetProtocol { + #[packet(with = "var_int")] + pub protocol_version: i32, + pub server_host: String, + pub server_port: u16, + #[packet(with = "var_int")] + pub next_state: i32, +} diff --git a/protocol/src/version/v_20w13b/login.rs b/protocol/src/version/v_20w13b/login.rs new file mode 100644 index 0000000..d29fe54 --- /dev/null +++ b/protocol/src/version/v_20w13b/login.rs @@ -0,0 +1,211 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +use uuid::Uuid; + +pub enum ServerBoundLoginPacket { + LoginStart(LoginStart), + EncryptionResponse(EncryptionResponse), + LoginPluginResponse(LoginPluginResponse), +} + +impl ServerBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::LoginStart(_) => 0x00, + Self::EncryptionResponse(_) => 0x01, + Self::LoginPluginResponse(_) => 0x02, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let login_start = LoginStart::decode(reader)?; + + Ok(Self::LoginStart(login_start)) + } + 0x01 => { + let encryption_response = EncryptionResponse::decode(reader)?; + + Ok(Self::EncryptionResponse(encryption_response)) + } + 0x02 => { + let login_plugin_response = LoginPluginResponse::decode(reader)?; + + Ok(Self::LoginPluginResponse(login_plugin_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn login_start(username: String) -> Self { + let login_start = LoginStart { username }; + + Self::LoginStart(login_start) + } + + pub fn encryption_response(shared_secret: Vec, verify_token: Vec) -> Self { + let encryption_response = EncryptionResponse { + shared_secret, + verify_token, + }; + + Self::EncryptionResponse(encryption_response) + } + + pub fn login_plugin_response(message_id: i32, data: Vec) -> Self { + let login_plugin_response = LoginPluginResponse { message_id, data }; + + Self::LoginPluginResponse(login_plugin_response) + } +} + +pub enum ClientBoundLoginPacket { + Disconnect(Disconnect), + EncryptionRequest(EncryptionRequest), + Success(Success), + Compress(Compress), + LoginPluginRequest(LoginPluginRequest), +} + +impl ClientBoundLoginPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::Disconnect(_) => 0x00, + Self::EncryptionRequest(_) => 0x01, + Self::Success(_) => 0x02, + Self::Compress(_) => 0x03, + Self::LoginPluginRequest(_) => 0x04, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let disconnect = Disconnect::decode(reader)?; + + Ok(Self::Disconnect(disconnect)) + } + 0x01 => { + let encryption_request = EncryptionRequest::decode(reader)?; + + Ok(Self::EncryptionRequest(encryption_request)) + } + 0x02 => { + let success = Success::decode(reader)?; + + Ok(Self::Success(success)) + } + 0x03 => { + let compress = Compress::decode(reader)?; + + Ok(Self::Compress(compress)) + } + 0x04 => { + let login_plugin_request = LoginPluginRequest::decode(reader)?; + + Ok(Self::LoginPluginRequest(login_plugin_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn disconnect(reason: String) -> Self { + let disconnect = Disconnect { reason }; + + Self::Disconnect(disconnect) + } + + pub fn encryption_request( + server_id: String, + public_key: Vec, + verify_token: Vec, + ) -> Self { + let encryption_request = EncryptionRequest { + server_id, + public_key, + verify_token, + }; + + Self::EncryptionRequest(encryption_request) + } + + pub fn success(uuid: Uuid, username: String) -> Self { + let success = Success { uuid, username }; + + Self::Success(success) + } + + pub fn compress(threshold: i32) -> Self { + let compress = Compress { threshold }; + + Self::Compress(compress) + } + + pub fn login_plugin_request(message_id: i32, channel: String, data: Vec) -> Self { + let login_plugin_request = LoginPluginRequest { + message_id, + channel, + data, + }; + + Self::LoginPluginRequest(login_plugin_request) + } +} + +#[derive(Packet, Debug)] +pub struct LoginStart { + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionResponse { + pub shared_secret: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginResponse { + #[packet(with = "var_int")] + pub message_id: i32, + #[packet(with = "rest")] + pub data: Vec, +} + +#[derive(Packet, Debug)] +pub struct Disconnect { + pub reason: String, +} + +#[derive(Packet, Debug)] +pub struct EncryptionRequest { + pub server_id: String, + pub public_key: Vec, + pub verify_token: Vec, +} + +#[derive(Packet, Debug)] +pub struct Success { + pub uuid: Uuid, + pub username: String, +} + +#[derive(Packet, Debug)] +pub struct Compress { + #[packet(with = "var_int")] + pub threshold: i32, +} + +#[derive(Packet, Debug)] +pub struct LoginPluginRequest { + #[packet(with = "var_int")] + pub message_id: i32, + pub channel: String, + #[packet(with = "rest")] + pub data: Vec, +} diff --git a/protocol/src/version/v_20w13b/mod.rs b/protocol/src/version/v_20w13b/mod.rs new file mode 100644 index 0000000..be1079b --- /dev/null +++ b/protocol/src/version/v_20w13b/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// It is not intended for manual editing. +pub mod game; +pub mod handshake; +pub mod login; +pub mod status; diff --git a/protocol/src/version/v_20w13b/status.rs b/protocol/src/version/v_20w13b/status.rs new file mode 100644 index 0000000..20fb7b7 --- /dev/null +++ b/protocol/src/version/v_20w13b/status.rs @@ -0,0 +1,99 @@ +// This file is automatically generated. +// It is not intended for manual editing. +use crate::DecodeError; +use crate::Decoder; +use minecraft_protocol_derive::Packet; +use std::io::Read; + +pub enum ServerBoundStatusPacket { + StatusRequest, + PingRequest(PingRequest), +} + +impl ServerBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusRequest => 0x00, + Self::PingRequest(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => Ok(Self::StatusRequest), + 0x01 => { + let ping_request = PingRequest::decode(reader)?; + + Ok(Self::PingRequest(ping_request)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_request() -> Self { + Self::StatusRequest + } + + pub fn ping_request(time: i64) -> Self { + let ping_request = PingRequest { time }; + + Self::PingRequest(ping_request) + } +} + +pub enum ClientBoundStatusPacket { + StatusResponse(StatusResponse), + PingResponse(PingResponse), +} + +impl ClientBoundStatusPacket { + pub fn get_type_id(&self) -> u8 { + match self { + Self::StatusResponse(_) => 0x00, + Self::PingResponse(_) => 0x01, + } + } + + pub fn decode(type_id: u8, reader: &mut R) -> Result { + match type_id { + 0x00 => { + let status_response = StatusResponse::decode(reader)?; + + Ok(Self::StatusResponse(status_response)) + } + 0x01 => { + let ping_response = PingResponse::decode(reader)?; + + Ok(Self::PingResponse(ping_response)) + } + _ => Err(DecodeError::UnknownPacketType { type_id }), + } + } + + pub fn status_response(response: String) -> Self { + let status_response = StatusResponse { response }; + + Self::StatusResponse(status_response) + } + + pub fn ping_response(time: i64) -> Self { + let ping_response = PingResponse { time }; + + Self::PingResponse(ping_response) + } +} + +#[derive(Packet, Debug)] +pub struct PingRequest { + pub time: i64, +} + +#[derive(Packet, Debug)] +pub struct StatusResponse { + pub response: String, +} + +#[derive(Packet, Debug)] +pub struct PingResponse { + pub time: i64, +}