#[derive(Debug, PartialEq, Clone)]
pub struct Handshake {
protocol_version: i32,
server_address: String,
server_port: u16,
next_state: i32,
}
impl Handshake {
const PACKET_ID: i32 = 0;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::Handshake(Handshake {
protocol_version: read_varint(r)?,
server_address: read_String(r)?,
server_port: read_u16(r)?,
next_state: read_varint(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.protocol_version, &mut ret)?;
write_String(&self.server_address, &mut ret)?;
write_u16(&self.server_port, &mut ret)?;
write_varint(&self.next_state, &mut ret)?;
Ok(ret)
}
pub fn new(protocol_version: i32, server_address: String, server_port: u16, next_state: i32) -> ServerboundPacket {
ServerboundPacket::Handshake(Handshake {
protocol_version: protocol_version,
server_address: server_address,
server_port: server_port,
next_state: next_state,
})
}
pub fn get_protocol_version(&self) -> &i32 {
&self.protocol_version
} pub fn get_server_address(&self) -> &String {
&self.server_address
} pub fn get_server_port(&self) -> &u16 {
&self.server_port
} pub fn get_next_state(&self) -> &i32 {
&self.next_state
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct StatusRequest {
}
impl StatusRequest {
const PACKET_ID: i32 = 0;
pub fn new_raw() -> ServerboundPacket {
ServerboundPacket::StatusRequest(StatusRequest {
})
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct StatusPing {
id: u64,
}
impl StatusPing {
const PACKET_ID: i32 = 1;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::StatusPing(StatusPing {
id: read_u64(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_u64(&self.id, &mut ret)?;
Ok(ret)
}
pub fn new(id: u64) -> ServerboundPacket {
ServerboundPacket::StatusPing(StatusPing {
id: id,
})
}
pub fn get_id(&self) -> &u64 {
&self.id
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct LoginStart {
name: String,
}
impl LoginStart {
const PACKET_ID: i32 = 0;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::LoginStart(LoginStart {
name: read_String(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_String(&self.name, &mut ret)?;
Ok(ret)
}
pub fn new(name: String) -> ServerboundPacket {
ServerboundPacket::LoginStart(LoginStart {
name: name,
})
}
pub fn get_name(&self) -> &String {
&self.name
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct EncryptionResponse {
shared_secret: Vec<u8>,
verify_token: Vec<u8>,
}
impl EncryptionResponse {
const PACKET_ID: i32 = 1;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::EncryptionResponse(EncryptionResponse {
shared_secret: read_prefixed_bytearray(r)?,
verify_token: read_prefixed_bytearray(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_prefixed_bytearray(&self.shared_secret, &mut ret)?;
write_prefixed_bytearray(&self.verify_token, &mut ret)?;
Ok(ret)
}
pub fn new(shared_secret: Vec<u8>, verify_token: Vec<u8>) -> ServerboundPacket {
ServerboundPacket::EncryptionResponse(EncryptionResponse {
shared_secret: shared_secret,
verify_token: verify_token,
})
}
pub fn get_shared_secret(&self) -> &Vec<u8> {
&self.shared_secret
} pub fn get_verify_token(&self) -> &Vec<u8> {
&self.verify_token
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct LoginPluginResponse {
message_id: i32,
successful: bool,
data: Vec<u8>,
}
impl LoginPluginResponse {
const PACKET_ID: i32 = 2;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::LoginPluginResponse(LoginPluginResponse {
message_id: read_varint(r)?,
successful: read_bool(r)?,
data: read_bytearray_to_end(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.message_id, &mut ret)?;
write_bool(&self.successful, &mut ret)?;
write_bytearray_to_end(&self.data, &mut ret)?;
Ok(ret)
}
pub fn new(message_id: i32, successful: bool, data: Vec<u8>) -> ServerboundPacket {
ServerboundPacket::LoginPluginResponse(LoginPluginResponse {
message_id: message_id,
successful: successful,
data: data,
})
}
pub fn get_message_id(&self) -> &i32 {
&self.message_id
} pub fn get_successful(&self) -> &bool {
&self.successful
} pub fn get_data(&self) -> &Vec<u8> {
&self.data
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct TeleportConfirm {
id: i32,
}
impl TeleportConfirm {
const PACKET_ID: i32 = 0;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::TeleportConfirm(TeleportConfirm {
id: read_varint(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.id, &mut ret)?;
Ok(ret)
}
pub fn new(id: i32) -> ServerboundPacket {
ServerboundPacket::TeleportConfirm(TeleportConfirm {
id: id,
})
}
pub fn get_id(&self) -> &i32 {
&self.id
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct QueryBlockNBT {
transaction_id: i32,
location: (i32, i32, i32),
}
impl QueryBlockNBT {
const PACKET_ID: i32 = 1;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::QueryBlockNBT(QueryBlockNBT {
transaction_id: read_varint(r)?,
location: read_position(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.transaction_id, &mut ret)?;
write_position(&self.location, &mut ret)?;
Ok(ret)
}
pub fn new(transaction_id: i32, location: (i32, i32, i32)) -> ServerboundPacket {
ServerboundPacket::QueryBlockNBT(QueryBlockNBT {
transaction_id: transaction_id,
location: location,
})
}
pub fn get_transaction_id(&self) -> &i32 {
&self.transaction_id
} pub fn get_location(&self) -> &(i32, i32, i32) {
&self.location
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct SetDifficulty {
new_difficulty: u8,
}
impl SetDifficulty {
const PACKET_ID: i32 = 2;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::SetDifficulty(SetDifficulty {
new_difficulty: read_u8(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_u8(&self.new_difficulty, &mut ret)?;
Ok(ret)
}
pub fn new(new_difficulty: u8) -> ServerboundPacket {
ServerboundPacket::SetDifficulty(SetDifficulty {
new_difficulty: new_difficulty,
})
}
pub fn get_new_difficulty(&self) -> &u8 {
&self.new_difficulty
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct ChatMessage {
message: String,
}
impl ChatMessage {
const PACKET_ID: i32 = 3;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::ChatMessage(ChatMessage {
message: read_String(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_String(&self.message, &mut ret)?;
Ok(ret)
}
pub fn new(message: String) -> ServerboundPacket {
ServerboundPacket::ChatMessage(ChatMessage {
message: message,
})
}
pub fn get_message(&self) -> &String {
&self.message
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct ClientStatus {
action: i32,
}
impl ClientStatus {
const PACKET_ID: i32 = 4;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::ClientStatus(ClientStatus {
action: read_varint(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.action, &mut ret)?;
Ok(ret)
}
pub fn new(action: i32) -> ServerboundPacket {
ServerboundPacket::ClientStatus(ClientStatus {
action: action,
})
}
pub fn get_action(&self) -> &i32 {
&self.action
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct ClientSettings {
locale: String,
view_distance: u8,
chat_mode: i32,
chat_colors: bool,
displayed_skin_parts: u8,
main_hand: i32,
}
impl ClientSettings {
const PACKET_ID: i32 = 5;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::ClientSettings(ClientSettings {
locale: read_String(r)?,
view_distance: read_u8(r)?,
chat_mode: read_varint(r)?,
chat_colors: read_bool(r)?,
displayed_skin_parts: read_u8(r)?,
main_hand: read_varint(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_String(&self.locale, &mut ret)?;
write_u8(&self.view_distance, &mut ret)?;
write_varint(&self.chat_mode, &mut ret)?;
write_bool(&self.chat_colors, &mut ret)?;
write_u8(&self.displayed_skin_parts, &mut ret)?;
write_varint(&self.main_hand, &mut ret)?;
Ok(ret)
}
pub fn new(locale: String, view_distance: u8, chat_mode: i32, chat_colors: bool, displayed_skin_parts: u8, main_hand: i32) -> ServerboundPacket {
ServerboundPacket::ClientSettings(ClientSettings {
locale: locale,
view_distance: view_distance,
chat_mode: chat_mode,
chat_colors: chat_colors,
displayed_skin_parts: displayed_skin_parts,
main_hand: main_hand,
})
}
pub fn get_locale(&self) -> &String {
&self.locale
} pub fn get_view_distance(&self) -> &u8 {
&self.view_distance
} pub fn get_chat_mode(&self) -> &i32 {
&self.chat_mode
} pub fn get_chat_colors(&self) -> &bool {
&self.chat_colors
} pub fn get_displayed_skin_parts(&self) -> &u8 {
&self.displayed_skin_parts
} pub fn get_main_hand(&self) -> &i32 {
&self.main_hand
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct TabComplete {
transaction_id: i32,
text: String,
}
impl TabComplete {
const PACKET_ID: i32 = 6;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::TabComplete(TabComplete {
transaction_id: read_varint(r)?,
text: read_String(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.transaction_id, &mut ret)?;
write_String(&self.text, &mut ret)?;
Ok(ret)
}
pub fn new(transaction_id: i32, text: String) -> ServerboundPacket {
ServerboundPacket::TabComplete(TabComplete {
transaction_id: transaction_id,
text: text,
})
}
pub fn get_transaction_id(&self) -> &i32 {
&self.transaction_id
} pub fn get_text(&self) -> &String {
&self.text
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct ConfirmTransaction {
window_id: u8,
id: i16,
accepted: bool,
}
impl ConfirmTransaction {
const PACKET_ID: i32 = 7;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::ConfirmTransaction(ConfirmTransaction {
window_id: read_u8(r)?,
id: read_i16(r)?,
accepted: read_bool(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_u8(&self.window_id, &mut ret)?;
write_i16(&self.id, &mut ret)?;
write_bool(&self.accepted, &mut ret)?;
Ok(ret)
}
pub fn new(window_id: u8, id: i16, accepted: bool) -> ServerboundPacket {
ServerboundPacket::ConfirmTransaction(ConfirmTransaction {
window_id: window_id,
id: id,
accepted: accepted,
})
}
pub fn get_window_id(&self) -> &u8 {
&self.window_id
} pub fn get_id(&self) -> &i16 {
&self.id
} pub fn get_accepted(&self) -> &bool {
&self.accepted
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct EnchantItem {
window_id: u8,
enchantment: i8,
}
impl EnchantItem {
const PACKET_ID: i32 = 8;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::EnchantItem(EnchantItem {
window_id: read_u8(r)?,
enchantment: read_i8(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_u8(&self.window_id, &mut ret)?;
write_i8(&self.enchantment, &mut ret)?;
Ok(ret)
}
pub fn new(window_id: u8, enchantment: i8) -> ServerboundPacket {
ServerboundPacket::EnchantItem(EnchantItem {
window_id: window_id,
enchantment: enchantment,
})
}
pub fn get_window_id(&self) -> &u8 {
&self.window_id
} pub fn get_enchantment(&self) -> &i8 {
&self.enchantment
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct ClickWindow {
window_id: u8,
slot_id: i16,
button: i8,
id: i16,
mode: i32,
slot: Vec<u8>,
}
impl ClickWindow {
const PACKET_ID: i32 = 9;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::ClickWindow(ClickWindow {
window_id: read_u8(r)?,
slot_id: read_i16(r)?,
button: read_i8(r)?,
id: read_i16(r)?,
mode: read_varint(r)?,
slot: read_bytearray(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_u8(&self.window_id, &mut ret)?;
write_i16(&self.slot_id, &mut ret)?;
write_i8(&self.button, &mut ret)?;
write_i16(&self.id, &mut ret)?;
write_varint(&self.mode, &mut ret)?;
write_bytearray(&self.slot, &mut ret)?;
Ok(ret)
}
pub fn new(window_id: u8, slot_id: i16, button: i8, id: i16, mode: i32, slot: Vec<u8>) -> ServerboundPacket {
ServerboundPacket::ClickWindow(ClickWindow {
window_id: window_id,
slot_id: slot_id,
button: button,
id: id,
mode: mode,
slot: slot,
})
}
pub fn get_window_id(&self) -> &u8 {
&self.window_id
} pub fn get_slot_id(&self) -> &i16 {
&self.slot_id
} pub fn get_button(&self) -> &i8 {
&self.button
} pub fn get_id(&self) -> &i16 {
&self.id
} pub fn get_mode(&self) -> &i32 {
&self.mode
} pub fn get_slot(&self) -> &Vec<u8> {
&self.slot
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct CloseWindow {
window_id: u8,
}
impl CloseWindow {
const PACKET_ID: i32 = 10;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::CloseWindow(CloseWindow {
window_id: read_u8(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_u8(&self.window_id, &mut ret)?;
Ok(ret)
}
pub fn new(window_id: u8) -> ServerboundPacket {
ServerboundPacket::CloseWindow(CloseWindow {
window_id: window_id,
})
}
pub fn get_window_id(&self) -> &u8 {
&self.window_id
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct PluginMessage {
channel: String,
data: Vec<u8>,
}
impl PluginMessage {
const PACKET_ID: i32 = 11;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::PluginMessage(PluginMessage {
channel: read_String(r)?,
data: read_bytearray(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_String(&self.channel, &mut ret)?;
write_bytearray(&self.data, &mut ret)?;
Ok(ret)
}
pub fn new(channel: String, data: Vec<u8>) -> ServerboundPacket {
ServerboundPacket::PluginMessage(PluginMessage {
channel: channel,
data: data,
})
}
pub fn get_channel(&self) -> &String {
&self.channel
} pub fn get_data(&self) -> &Vec<u8> {
&self.data
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct EditBook {
data: Vec<u8>,
}
impl EditBook {
const PACKET_ID: i32 = 12;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::EditBook(EditBook {
data: read_bytearray_to_end(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_bytearray_to_end(&self.data, &mut ret)?;
Ok(ret)
}
pub fn new(data: Vec<u8>) -> ServerboundPacket {
ServerboundPacket::EditBook(EditBook {
data: data,
})
}
pub fn get_data(&self) -> &Vec<u8> {
&self.data
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct QueryEntityNBT {
transaction_id: i32,
entity_id: i32,
}
impl QueryEntityNBT {
const PACKET_ID: i32 = 13;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::QueryEntityNBT(QueryEntityNBT {
transaction_id: read_varint(r)?,
entity_id: read_varint(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.transaction_id, &mut ret)?;
write_varint(&self.entity_id, &mut ret)?;
Ok(ret)
}
pub fn new(transaction_id: i32, entity_id: i32) -> ServerboundPacket {
ServerboundPacket::QueryEntityNBT(QueryEntityNBT {
transaction_id: transaction_id,
entity_id: entity_id,
})
}
pub fn get_transaction_id(&self) -> &i32 {
&self.transaction_id
} pub fn get_entity_id(&self) -> &i32 {
&self.entity_id
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct UseEntity {
target: i32,
action: i32,
location: Option<(f32, f32, f32)>,
hand: Option<i32>,
}
impl UseEntity {
const PACKET_ID: i32 = 14;
pub fn new_raw(target: i32, action: i32, location: Option<(f32, f32, f32)>, hand: Option<i32>) -> ServerboundPacket {
ServerboundPacket::UseEntity(UseEntity {
target: target,
action: action,
location: location,
hand: hand,
})
}
pub fn get_target(&self) -> &i32 {
&self.target
} pub fn get_action(&self) -> &i32 {
&self.action
} pub fn get_location(&self) -> &Option<(f32, f32, f32)> {
&self.location
} pub fn get_hand(&self) -> &Option<i32> {
&self.hand
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct KeepAlive {
id: i64,
}
impl KeepAlive {
const PACKET_ID: i32 = 15;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::KeepAlive(KeepAlive {
id: read_i64(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_i64(&self.id, &mut ret)?;
Ok(ret)
}
pub fn new(id: i64) -> ServerboundPacket {
ServerboundPacket::KeepAlive(KeepAlive {
id: id,
})
}
pub fn get_id(&self) -> &i64 {
&self.id
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct LockDifficulty {
locked: bool,
}
impl LockDifficulty {
const PACKET_ID: i32 = 16;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::LockDifficulty(LockDifficulty {
locked: read_bool(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_bool(&self.locked, &mut ret)?;
Ok(ret)
}
pub fn new(locked: bool) -> ServerboundPacket {
ServerboundPacket::LockDifficulty(LockDifficulty {
locked: locked,
})
}
pub fn get_locked(&self) -> &bool {
&self.locked
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct PlayerPosition {
x: f64,
y: f64,
z: f64,
on_ground: bool,
}
impl PlayerPosition {
const PACKET_ID: i32 = 17;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::PlayerPosition(PlayerPosition {
x: read_f64(r)?,
y: read_f64(r)?,
z: read_f64(r)?,
on_ground: read_bool(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_f64(&self.x, &mut ret)?;
write_f64(&self.y, &mut ret)?;
write_f64(&self.z, &mut ret)?;
write_bool(&self.on_ground, &mut ret)?;
Ok(ret)
}
pub fn new(x: f64, y: f64, z: f64, on_ground: bool) -> ServerboundPacket {
ServerboundPacket::PlayerPosition(PlayerPosition {
x: x,
y: y,
z: z,
on_ground: on_ground,
})
}
pub fn get_x(&self) -> &f64 {
&self.x
} pub fn get_y(&self) -> &f64 {
&self.y
} pub fn get_z(&self) -> &f64 {
&self.z
} pub fn get_on_ground(&self) -> &bool {
&self.on_ground
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct PlayerPositionAndLook {
x: f64,
y: f64,
z: f64,
yaw: f32,
pitch: f32,
on_ground: bool,
}
impl PlayerPositionAndLook {
const PACKET_ID: i32 = 18;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::PlayerPositionAndLook(PlayerPositionAndLook {
x: read_f64(r)?,
y: read_f64(r)?,
z: read_f64(r)?,
yaw: read_f32(r)?,
pitch: read_f32(r)?,
on_ground: read_bool(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_f64(&self.x, &mut ret)?;
write_f64(&self.y, &mut ret)?;
write_f64(&self.z, &mut ret)?;
write_f32(&self.yaw, &mut ret)?;
write_f32(&self.pitch, &mut ret)?;
write_bool(&self.on_ground, &mut ret)?;
Ok(ret)
}
pub fn new(x: f64, y: f64, z: f64, yaw: f32, pitch: f32, on_ground: bool) -> ServerboundPacket {
ServerboundPacket::PlayerPositionAndLook(PlayerPositionAndLook {
x: x,
y: y,
z: z,
yaw: yaw,
pitch: pitch,
on_ground: on_ground,
})
}
pub fn get_x(&self) -> &f64 {
&self.x
} pub fn get_y(&self) -> &f64 {
&self.y
} pub fn get_z(&self) -> &f64 {
&self.z
} pub fn get_yaw(&self) -> &f32 {
&self.yaw
} pub fn get_pitch(&self) -> &f32 {
&self.pitch
} pub fn get_on_ground(&self) -> &bool {
&self.on_ground
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct PlayerLook {
yaw: f32,
pitch: f32,
on_ground: bool,
}
impl PlayerLook {
const PACKET_ID: i32 = 19;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::PlayerLook(PlayerLook {
yaw: read_f32(r)?,
pitch: read_f32(r)?,
on_ground: read_bool(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_f32(&self.yaw, &mut ret)?;
write_f32(&self.pitch, &mut ret)?;
write_bool(&self.on_ground, &mut ret)?;
Ok(ret)
}
pub fn new(yaw: f32, pitch: f32, on_ground: bool) -> ServerboundPacket {
ServerboundPacket::PlayerLook(PlayerLook {
yaw: yaw,
pitch: pitch,
on_ground: on_ground,
})
}
pub fn get_yaw(&self) -> &f32 {
&self.yaw
} pub fn get_pitch(&self) -> &f32 {
&self.pitch
} pub fn get_on_ground(&self) -> &bool {
&self.on_ground
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct Player {
on_ground: bool,
}
impl Player {
const PACKET_ID: i32 = 20;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::Player(Player {
on_ground: read_bool(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_bool(&self.on_ground, &mut ret)?;
Ok(ret)
}
pub fn new(on_ground: bool) -> ServerboundPacket {
ServerboundPacket::Player(Player {
on_ground: on_ground,
})
}
pub fn get_on_ground(&self) -> &bool {
&self.on_ground
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct VehicleMove {
x: f64,
y: f64,
z: f64,
yaw: f32,
pitch: f32,
}
impl VehicleMove {
const PACKET_ID: i32 = 21;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::VehicleMove(VehicleMove {
x: read_f64(r)?,
y: read_f64(r)?,
z: read_f64(r)?,
yaw: read_f32(r)?,
pitch: read_f32(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_f64(&self.x, &mut ret)?;
write_f64(&self.y, &mut ret)?;
write_f64(&self.z, &mut ret)?;
write_f32(&self.yaw, &mut ret)?;
write_f32(&self.pitch, &mut ret)?;
Ok(ret)
}
pub fn new(x: f64, y: f64, z: f64, yaw: f32, pitch: f32) -> ServerboundPacket {
ServerboundPacket::VehicleMove(VehicleMove {
x: x,
y: y,
z: z,
yaw: yaw,
pitch: pitch,
})
}
pub fn get_x(&self) -> &f64 {
&self.x
} pub fn get_y(&self) -> &f64 {
&self.y
} pub fn get_z(&self) -> &f64 {
&self.z
} pub fn get_yaw(&self) -> &f32 {
&self.yaw
} pub fn get_pitch(&self) -> &f32 {
&self.pitch
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct SteerBoat {
right: bool,
left: bool,
}
impl SteerBoat {
const PACKET_ID: i32 = 22;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::SteerBoat(SteerBoat {
right: read_bool(r)?,
left: read_bool(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_bool(&self.right, &mut ret)?;
write_bool(&self.left, &mut ret)?;
Ok(ret)
}
pub fn new(right: bool, left: bool) -> ServerboundPacket {
ServerboundPacket::SteerBoat(SteerBoat {
right: right,
left: left,
})
}
pub fn get_right(&self) -> &bool {
&self.right
} pub fn get_left(&self) -> &bool {
&self.left
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct PickItem {
slot_to_use: i32,
}
impl PickItem {
const PACKET_ID: i32 = 23;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::PickItem(PickItem {
slot_to_use: read_varint(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.slot_to_use, &mut ret)?;
Ok(ret)
}
pub fn new(slot_to_use: i32) -> ServerboundPacket {
ServerboundPacket::PickItem(PickItem {
slot_to_use: slot_to_use,
})
}
pub fn get_slot_to_use(&self) -> &i32 {
&self.slot_to_use
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct CraftRecipeRequest {
window_id: u8,
recipe: i32,
make_all: bool,
}
impl CraftRecipeRequest {
const PACKET_ID: i32 = 24;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::CraftRecipeRequest(CraftRecipeRequest {
window_id: read_u8(r)?,
recipe: read_varint(r)?,
make_all: read_bool(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_u8(&self.window_id, &mut ret)?;
write_varint(&self.recipe, &mut ret)?;
write_bool(&self.make_all, &mut ret)?;
Ok(ret)
}
pub fn new(window_id: u8, recipe: i32, make_all: bool) -> ServerboundPacket {
ServerboundPacket::CraftRecipeRequest(CraftRecipeRequest {
window_id: window_id,
recipe: recipe,
make_all: make_all,
})
}
pub fn get_window_id(&self) -> &u8 {
&self.window_id
} pub fn get_recipe(&self) -> &i32 {
&self.recipe
} pub fn get_make_all(&self) -> &bool {
&self.make_all
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct PlayerAbilities {
flags: u8,
flying_speed: f32,
walking_speed: f32,
}
impl PlayerAbilities {
const PACKET_ID: i32 = 25;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::PlayerAbilities(PlayerAbilities {
flags: read_u8(r)?,
flying_speed: read_f32(r)?,
walking_speed: read_f32(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_u8(&self.flags, &mut ret)?;
write_f32(&self.flying_speed, &mut ret)?;
write_f32(&self.walking_speed, &mut ret)?;
Ok(ret)
}
pub fn new(flags: u8, flying_speed: f32, walking_speed: f32) -> ServerboundPacket {
ServerboundPacket::PlayerAbilities(PlayerAbilities {
flags: flags,
flying_speed: flying_speed,
walking_speed: walking_speed,
})
}
pub fn get_flags(&self) -> &u8 {
&self.flags
} pub fn get_flying_speed(&self) -> &f32 {
&self.flying_speed
} pub fn get_walking_speed(&self) -> &f32 {
&self.walking_speed
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct PlayerDigging {
status: i32,
location: (i32, i32, i32),
face: u8,
}
impl PlayerDigging {
const PACKET_ID: i32 = 26;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::PlayerDigging(PlayerDigging {
status: read_varint(r)?,
location: read_position(r)?,
face: read_u8(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.status, &mut ret)?;
write_position(&self.location, &mut ret)?;
write_u8(&self.face, &mut ret)?;
Ok(ret)
}
pub fn new(status: i32, location: (i32, i32, i32), face: u8) -> ServerboundPacket {
ServerboundPacket::PlayerDigging(PlayerDigging {
status: status,
location: location,
face: face,
})
}
pub fn get_status(&self) -> &i32 {
&self.status
} pub fn get_location(&self) -> &(i32, i32, i32) {
&self.location
} pub fn get_face(&self) -> &u8 {
&self.face
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct EntityAction {
entity_id: i32,
action: i32,
jump_boost: i32,
}
impl EntityAction {
const PACKET_ID: i32 = 27;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::EntityAction(EntityAction {
entity_id: read_varint(r)?,
action: read_varint(r)?,
jump_boost: read_varint(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.entity_id, &mut ret)?;
write_varint(&self.action, &mut ret)?;
write_varint(&self.jump_boost, &mut ret)?;
Ok(ret)
}
pub fn new(entity_id: i32, action: i32, jump_boost: i32) -> ServerboundPacket {
ServerboundPacket::EntityAction(EntityAction {
entity_id: entity_id,
action: action,
jump_boost: jump_boost,
})
}
pub fn get_entity_id(&self) -> &i32 {
&self.entity_id
} pub fn get_action(&self) -> &i32 {
&self.action
} pub fn get_jump_boost(&self) -> &i32 {
&self.jump_boost
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct SteerVehicle {
sideways: f32,
forward: f32,
flags: u8,
}
impl SteerVehicle {
const PACKET_ID: i32 = 28;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::SteerVehicle(SteerVehicle {
sideways: read_f32(r)?,
forward: read_f32(r)?,
flags: read_u8(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_f32(&self.sideways, &mut ret)?;
write_f32(&self.forward, &mut ret)?;
write_u8(&self.flags, &mut ret)?;
Ok(ret)
}
pub fn new(sideways: f32, forward: f32, flags: u8) -> ServerboundPacket {
ServerboundPacket::SteerVehicle(SteerVehicle {
sideways: sideways,
forward: forward,
flags: flags,
})
}
pub fn get_sideways(&self) -> &f32 {
&self.sideways
} pub fn get_forward(&self) -> &f32 {
&self.forward
} pub fn get_flags(&self) -> &u8 {
&self.flags
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct RecipeBookData {
displayed_recipe: Option<String>,
recipe_book_states: Option<(bool, bool, bool, bool)>,
}
impl RecipeBookData {
const PACKET_ID: i32 = 29;
pub fn new_raw(displayed_recipe: Option<String>, recipe_book_states: Option<(bool, bool, bool, bool)>) -> ServerboundPacket {
ServerboundPacket::RecipeBookData(RecipeBookData {
displayed_recipe: displayed_recipe,
recipe_book_states: recipe_book_states,
})
}
pub fn get_displayed_recipe(&self) -> &Option<String> {
&self.displayed_recipe
} pub fn get_recipe_book_states(&self) -> &Option<(bool, bool, bool, bool)> {
&self.recipe_book_states
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct NameItem {
name: String,
}
impl NameItem {
const PACKET_ID: i32 = 30;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::NameItem(NameItem {
name: read_String(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_String(&self.name, &mut ret)?;
Ok(ret)
}
pub fn new(name: String) -> ServerboundPacket {
ServerboundPacket::NameItem(NameItem {
name: name,
})
}
pub fn get_name(&self) -> &String {
&self.name
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct ResourcePackStatus {
result: i32,
}
impl ResourcePackStatus {
const PACKET_ID: i32 = 31;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::ResourcePackStatus(ResourcePackStatus {
result: read_varint(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.result, &mut ret)?;
Ok(ret)
}
pub fn new(result: i32) -> ServerboundPacket {
ServerboundPacket::ResourcePackStatus(ResourcePackStatus {
result: result,
})
}
pub fn get_result(&self) -> &i32 {
&self.result
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct AdvancementTab {
tab_id: Option<String>,
}
impl AdvancementTab {
const PACKET_ID: i32 = 32;
pub fn new_raw(tab_id: Option<String>) -> ServerboundPacket {
ServerboundPacket::AdvancementTab(AdvancementTab {
tab_id: tab_id,
})
}
pub fn get_tab_id(&self) -> &Option<String> {
&self.tab_id
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct SelectTrade {
selected_slot: i32,
}
impl SelectTrade {
const PACKET_ID: i32 = 33;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::SelectTrade(SelectTrade {
selected_slot: read_varint(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.selected_slot, &mut ret)?;
Ok(ret)
}
pub fn new(selected_slot: i32) -> ServerboundPacket {
ServerboundPacket::SelectTrade(SelectTrade {
selected_slot: selected_slot,
})
}
pub fn get_selected_slot(&self) -> &i32 {
&self.selected_slot
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct SetBeaconEffect {
primary_effect: i32,
secondary_effect: i32,
}
impl SetBeaconEffect {
const PACKET_ID: i32 = 34;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::SetBeaconEffect(SetBeaconEffect {
primary_effect: read_varint(r)?,
secondary_effect: read_varint(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.primary_effect, &mut ret)?;
write_varint(&self.secondary_effect, &mut ret)?;
Ok(ret)
}
pub fn new(primary_effect: i32, secondary_effect: i32) -> ServerboundPacket {
ServerboundPacket::SetBeaconEffect(SetBeaconEffect {
primary_effect: primary_effect,
secondary_effect: secondary_effect,
})
}
pub fn get_primary_effect(&self) -> &i32 {
&self.primary_effect
} pub fn get_secondary_effect(&self) -> &i32 {
&self.secondary_effect
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct HeldItemChange {
slot: i16,
}
impl HeldItemChange {
const PACKET_ID: i32 = 35;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::HeldItemChange(HeldItemChange {
slot: read_i16(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_i16(&self.slot, &mut ret)?;
Ok(ret)
}
pub fn new(slot: i16) -> ServerboundPacket {
ServerboundPacket::HeldItemChange(HeldItemChange {
slot: slot,
})
}
pub fn get_slot(&self) -> &i16 {
&self.slot
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct UpdateCommandBlock {
location: (i32, i32, i32),
command: String,
mode: i32,
flags: u8,
}
impl UpdateCommandBlock {
const PACKET_ID: i32 = 36;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::UpdateCommandBlock(UpdateCommandBlock {
location: read_position(r)?,
command: read_String(r)?,
mode: read_varint(r)?,
flags: read_u8(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_position(&self.location, &mut ret)?;
write_String(&self.command, &mut ret)?;
write_varint(&self.mode, &mut ret)?;
write_u8(&self.flags, &mut ret)?;
Ok(ret)
}
pub fn new(location: (i32, i32, i32), command: String, mode: i32, flags: u8) -> ServerboundPacket {
ServerboundPacket::UpdateCommandBlock(UpdateCommandBlock {
location: location,
command: command,
mode: mode,
flags: flags,
})
}
pub fn get_location(&self) -> &(i32, i32, i32) {
&self.location
} pub fn get_command(&self) -> &String {
&self.command
} pub fn get_mode(&self) -> &i32 {
&self.mode
} pub fn get_flags(&self) -> &u8 {
&self.flags
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct UpdateCommandBlockMinecart {
id: i32,
command: String,
track_output: bool,
}
impl UpdateCommandBlockMinecart {
const PACKET_ID: i32 = 37;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::UpdateCommandBlockMinecart(UpdateCommandBlockMinecart {
id: read_varint(r)?,
command: read_String(r)?,
track_output: read_bool(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.id, &mut ret)?;
write_String(&self.command, &mut ret)?;
write_bool(&self.track_output, &mut ret)?;
Ok(ret)
}
pub fn new(id: i32, command: String, track_output: bool) -> ServerboundPacket {
ServerboundPacket::UpdateCommandBlockMinecart(UpdateCommandBlockMinecart {
id: id,
command: command,
track_output: track_output,
})
}
pub fn get_id(&self) -> &i32 {
&self.id
} pub fn get_command(&self) -> &String {
&self.command
} pub fn get_track_output(&self) -> &bool {
&self.track_output
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct CreativeInventoryAction {
slot_id: i16,
slot: Vec<u8>,
}
impl CreativeInventoryAction {
const PACKET_ID: i32 = 38;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::CreativeInventoryAction(CreativeInventoryAction {
slot_id: read_i16(r)?,
slot: read_bytearray(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_i16(&self.slot_id, &mut ret)?;
write_bytearray(&self.slot, &mut ret)?;
Ok(ret)
}
pub fn new(slot_id: i16, slot: Vec<u8>) -> ServerboundPacket {
ServerboundPacket::CreativeInventoryAction(CreativeInventoryAction {
slot_id: slot_id,
slot: slot,
})
}
pub fn get_slot_id(&self) -> &i16 {
&self.slot_id
} pub fn get_slot(&self) -> &Vec<u8> {
&self.slot
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct UpdateJigsawBlock {
location: (i32, i32, i32),
attachment_type: String,
target_pool: String,
final_state: String,
}
impl UpdateJigsawBlock {
const PACKET_ID: i32 = 39;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::UpdateJigsawBlock(UpdateJigsawBlock {
location: read_position(r)?,
attachment_type: read_String(r)?,
target_pool: read_String(r)?,
final_state: read_String(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_position(&self.location, &mut ret)?;
write_String(&self.attachment_type, &mut ret)?;
write_String(&self.target_pool, &mut ret)?;
write_String(&self.final_state, &mut ret)?;
Ok(ret)
}
pub fn new(location: (i32, i32, i32), attachment_type: String, target_pool: String, final_state: String) -> ServerboundPacket {
ServerboundPacket::UpdateJigsawBlock(UpdateJigsawBlock {
location: location,
attachment_type: attachment_type,
target_pool: target_pool,
final_state: final_state,
})
}
pub fn get_location(&self) -> &(i32, i32, i32) {
&self.location
} pub fn get_attachment_type(&self) -> &String {
&self.attachment_type
} pub fn get_target_pool(&self) -> &String {
&self.target_pool
} pub fn get_final_state(&self) -> &String {
&self.final_state
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct UpdateStructureBlock {
location: (i32, i32, i32),
action: i32,
mode: i32,
name: String,
offset_x: i8,
offset_y: i8,
offset_z: i8,
size_x: i8,
size_y: i8,
size_z: i8,
mirror: i32,
rotation: i32,
metadata: String,
integrity: f32,
seed: i64,
flags: u8,
}
impl UpdateStructureBlock {
const PACKET_ID: i32 = 40;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::UpdateStructureBlock(UpdateStructureBlock {
location: read_position(r)?,
action: read_varint(r)?,
mode: read_varint(r)?,
name: read_String(r)?,
offset_x: read_i8(r)?,
offset_y: read_i8(r)?,
offset_z: read_i8(r)?,
size_x: read_i8(r)?,
size_y: read_i8(r)?,
size_z: read_i8(r)?,
mirror: read_varint(r)?,
rotation: read_varint(r)?,
metadata: read_String(r)?,
integrity: read_f32(r)?,
seed: read_varlong(r)?,
flags: read_u8(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_position(&self.location, &mut ret)?;
write_varint(&self.action, &mut ret)?;
write_varint(&self.mode, &mut ret)?;
write_String(&self.name, &mut ret)?;
write_i8(&self.offset_x, &mut ret)?;
write_i8(&self.offset_y, &mut ret)?;
write_i8(&self.offset_z, &mut ret)?;
write_i8(&self.size_x, &mut ret)?;
write_i8(&self.size_y, &mut ret)?;
write_i8(&self.size_z, &mut ret)?;
write_varint(&self.mirror, &mut ret)?;
write_varint(&self.rotation, &mut ret)?;
write_String(&self.metadata, &mut ret)?;
write_f32(&self.integrity, &mut ret)?;
write_varlong(&self.seed, &mut ret)?;
write_u8(&self.flags, &mut ret)?;
Ok(ret)
}
pub fn new(location: (i32, i32, i32), action: i32, mode: i32, name: String, offset_x: i8, offset_y: i8, offset_z: i8, size_x: i8, size_y: i8, size_z: i8, mirror: i32, rotation: i32, metadata: String, integrity: f32, seed: i64, flags: u8) -> ServerboundPacket {
ServerboundPacket::UpdateStructureBlock(UpdateStructureBlock {
location: location,
action: action,
mode: mode,
name: name,
offset_x: offset_x,
offset_y: offset_y,
offset_z: offset_z,
size_x: size_x,
size_y: size_y,
size_z: size_z,
mirror: mirror,
rotation: rotation,
metadata: metadata,
integrity: integrity,
seed: seed,
flags: flags,
})
}
pub fn get_location(&self) -> &(i32, i32, i32) {
&self.location
} pub fn get_action(&self) -> &i32 {
&self.action
} pub fn get_mode(&self) -> &i32 {
&self.mode
} pub fn get_name(&self) -> &String {
&self.name
} pub fn get_offset_x(&self) -> &i8 {
&self.offset_x
} pub fn get_offset_y(&self) -> &i8 {
&self.offset_y
} pub fn get_offset_z(&self) -> &i8 {
&self.offset_z
} pub fn get_size_x(&self) -> &i8 {
&self.size_x
} pub fn get_size_y(&self) -> &i8 {
&self.size_y
} pub fn get_size_z(&self) -> &i8 {
&self.size_z
} pub fn get_mirror(&self) -> &i32 {
&self.mirror
} pub fn get_rotation(&self) -> &i32 {
&self.rotation
} pub fn get_metadata(&self) -> &String {
&self.metadata
} pub fn get_integrity(&self) -> &f32 {
&self.integrity
} pub fn get_seed(&self) -> &i64 {
&self.seed
} pub fn get_flags(&self) -> &u8 {
&self.flags
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct UpdateSign {
location: (i32, i32, i32),
line1: String,
line2: String,
line3: String,
line4: String,
}
impl UpdateSign {
const PACKET_ID: i32 = 41;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::UpdateSign(UpdateSign {
location: read_position(r)?,
line1: read_String(r)?,
line2: read_String(r)?,
line3: read_String(r)?,
line4: read_String(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_position(&self.location, &mut ret)?;
write_String(&self.line1, &mut ret)?;
write_String(&self.line2, &mut ret)?;
write_String(&self.line3, &mut ret)?;
write_String(&self.line4, &mut ret)?;
Ok(ret)
}
pub fn new(location: (i32, i32, i32), line1: String, line2: String, line3: String, line4: String) -> ServerboundPacket {
ServerboundPacket::UpdateSign(UpdateSign {
location: location,
line1: line1,
line2: line2,
line3: line3,
line4: line4,
})
}
pub fn get_location(&self) -> &(i32, i32, i32) {
&self.location
} pub fn get_line1(&self) -> &String {
&self.line1
} pub fn get_line2(&self) -> &String {
&self.line2
} pub fn get_line3(&self) -> &String {
&self.line3
} pub fn get_line4(&self) -> &String {
&self.line4
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct Animation {
hand: i32,
}
impl Animation {
const PACKET_ID: i32 = 42;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::Animation(Animation {
hand: read_varint(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.hand, &mut ret)?;
Ok(ret)
}
pub fn new(hand: i32) -> ServerboundPacket {
ServerboundPacket::Animation(Animation {
hand: hand,
})
}
pub fn get_hand(&self) -> &i32 {
&self.hand
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct Spectate {
target: u128,
}
impl Spectate {
const PACKET_ID: i32 = 43;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::Spectate(Spectate {
target: read_u128(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_u128(&self.target, &mut ret)?;
Ok(ret)
}
pub fn new(target: u128) -> ServerboundPacket {
ServerboundPacket::Spectate(Spectate {
target: target,
})
}
pub fn get_target(&self) -> &u128 {
&self.target
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct PlayerBlockPlacement {
hand: i32,
location: (i32, i32, i32),
face: i32,
x: f32,
y: f32,
z: f32,
inside_block: bool,
}
impl PlayerBlockPlacement {
const PACKET_ID: i32 = 44;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::PlayerBlockPlacement(PlayerBlockPlacement {
hand: read_varint(r)?,
location: read_position(r)?,
face: read_varint(r)?,
x: read_f32(r)?,
y: read_f32(r)?,
z: read_f32(r)?,
inside_block: read_bool(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.hand, &mut ret)?;
write_position(&self.location, &mut ret)?;
write_varint(&self.face, &mut ret)?;
write_f32(&self.x, &mut ret)?;
write_f32(&self.y, &mut ret)?;
write_f32(&self.z, &mut ret)?;
write_bool(&self.inside_block, &mut ret)?;
Ok(ret)
}
pub fn new(hand: i32, location: (i32, i32, i32), face: i32, x: f32, y: f32, z: f32, inside_block: bool) -> ServerboundPacket {
ServerboundPacket::PlayerBlockPlacement(PlayerBlockPlacement {
hand: hand,
location: location,
face: face,
x: x,
y: y,
z: z,
inside_block: inside_block,
})
}
pub fn get_hand(&self) -> &i32 {
&self.hand
} pub fn get_location(&self) -> &(i32, i32, i32) {
&self.location
} pub fn get_face(&self) -> &i32 {
&self.face
} pub fn get_x(&self) -> &f32 {
&self.x
} pub fn get_y(&self) -> &f32 {
&self.y
} pub fn get_z(&self) -> &f32 {
&self.z
} pub fn get_inside_block(&self) -> &bool {
&self.inside_block
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct UseItem {
hand: i32,
}
impl UseItem {
const PACKET_ID: i32 = 45;
pub fn deserialize<R: Read>(r: &mut R) -> Result<ServerboundPacket> {
Ok(ServerboundPacket::UseItem(UseItem {
hand: read_varint(r)?,
}))
}
pub fn to_u8(&self) -> Result<Vec<u8>> {
let mut ret = Vec::new();
write_varint(&Self::PACKET_ID, &mut ret)?;
write_varint(&self.hand, &mut ret)?;
Ok(ret)
}
pub fn new(hand: i32) -> ServerboundPacket {
ServerboundPacket::UseItem(UseItem {
hand: hand,
})
}
pub fn get_hand(&self) -> &i32 {
&self.hand
}
}