ghast-protocol 0.4.4

Minecraft Java Edition network protocol for the ghast client library: generated per-version packets, framing, compression, encryption, NBT
Documentation
// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
// (data/pc/26.1/protocol.json + codegen/protocol/delta/776.json). Do not edit; run `cargo run -p ghast-codegen-protocol`.
// minecraft-data is MIT licensed, Copyright (c) 2015 PrismarineJS; see the NOTICE file
// in crates/ghast-protocol/src/generated/.

//! Serverbound packets of the play state.

#![allow(
    unused_imports,
    unused_variables,
    unused_mut,
    unused_parens,
    unused_braces,
    clippy::all,
    clippy::pedantic,
    non_camel_case_types,
    non_snake_case
)]
use crate::codec::{Decode, DecodeResult, Encode, EncodeResult, McWrite, Reader, decode_exact};
use crate::error::{DecodeError, EncodeError};
use crate::nbt::{AnonNbt, RawNbt};
use crate::packet::{Direction, PacketSet, RawPacket, State};
#[cfg(feature = "testgen")]
use crate::testgen::{Gen, Generate};
use crate::types::{BlockPos, ByteString, Holder, HolderSet, LpVec3, PositionLayout, Uuid};
use bytes::{BufMut, Bytes, BytesMut};

#[cfg(feature = "v26_2")]
/// Nested container.
#[derive(Debug, Clone, PartialEq)]
pub struct WindowClickChangedSlots {
    /// `location`
    pub location: i16,
    /// `item`
    pub item: Option<crate::defs::p776::types::HashedSlot>,
}

#[cfg(feature = "v26_2")]
/// `window_click` (serverbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct WindowClick<const V: i32> {
    /// `windowId`
    pub window_id: i32,
    /// `stateId`
    pub state_id: i32,
    /// `slot`
    pub slot: i16,
    /// `mouseButton`
    pub mouse_button: i8,
    /// `mode`
    pub mode: i32,
    /// `changedSlots`
    pub changed_slots: Vec<crate::defs::p776::play::serverbound::WindowClickChangedSlots>,
    /// `cursorItem`
    pub cursor_item: Option<crate::defs::p776::types::HashedSlot>,
}
#[cfg(feature = "v26_2")]
impl<const V: i32> Decode for WindowClick<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_varint()?;
            let v2 = r.read_varint()?;
            let v3 = r.read_i16()?;
            let v4 = r.read_i8()?;
            let v5 = r.read_varint()?;
            let v6 = {
                let v7 = {
                    let c = r.read_varint()?;
                    r.check_count(i64::from(c), 3)?
                };
                let mut v8 = Vec::with_capacity(v7.min(crate::codec::PREALLOC_LIMIT));
                for _ in 0..v7 {
                    v8.push({
                        let v9 = r.read_i16()?;
                        let v10 = if r.read_bool()? {
                            Some(<crate::defs::p776::types::HashedSlot as Decode>::decode(r)?)
                        } else {
                            None
                        };
                        crate::defs::p776::play::serverbound::WindowClickChangedSlots {
                            location: v9,
                            item: v10,
                        }
                    });
                }
                v8
            };
            let v11 = if r.read_bool()? {
                Some(<crate::defs::p776::types::HashedSlot as Decode>::decode(r)?)
            } else {
                None
            };
            Self {
                window_id: v1,
                state_id: v2,
                slot: v3,
                mouse_button: v4,
                mode: v5,
                changed_slots: v6,
                cursor_item: v11,
            }
        })
    }
}
#[cfg(feature = "v26_2")]
impl<const V: i32> Encode for WindowClick<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_varint((*self).window_id);
        w.put_varint((*self).state_id);
        w.put_i16((*self).slot);
        w.put_i8((*self).mouse_button);
        w.put_varint((*self).mode);
        w.put_len_varint((*self).changed_slots.len())?;
        for v1 in (*self).changed_slots.iter() {
            w.put_i16((*v1).location);
            match &(*v1).item {
                Some(v2) => {
                    w.put_u8(1);
                    (*v2).encode(w)?;
                }
                None => w.put_u8(0),
            }
        }
        match &(*self).cursor_item {
            Some(v3) => {
                w.put_u8(1);
                (*v3).encode(w)?;
            }
            None => w.put_u8(0),
        }
        Ok(())
    }
}
#[cfg(feature = "v26_2")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for WindowClick<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            let v3 = (g.int_in(-32768, 32767, &[]) as i16);
            let v4 = (g.int_in(-128, 127, &[]) as i8);
            let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            let v6 = {
                let v7 = g.count();
                let mut v8 = Vec::with_capacity(v7.min(crate::codec::PREALLOC_LIMIT));
                for _ in 0..v7 {
                    v8.push({
                        let v9 = (g.int_in(-32768, 32767, &[]) as i16);
                        let v10 = if g.bool() {
                            Some(<crate::defs::p776::types::HashedSlot as Generate>::generate(g))
                        } else {
                            None
                        };
                        crate::defs::p776::play::serverbound::WindowClickChangedSlots {
                            location: v9,
                            item: v10,
                        }
                    });
                }
                v8
            };
            let v11 = if g.bool() {
                Some(<crate::defs::p776::types::HashedSlot as Generate>::generate(g))
            } else {
                None
            };
            Self {
                window_id: v1,
                state_id: v2,
                slot: v3,
                mouse_button: v4,
                mode: v5,
                changed_slots: v6,
                cursor_item: v11,
            }
        }
    }
}

#[cfg(feature = "v26_2")]
/// `set_creative_slot` (serverbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct SetCreativeSlot<const V: i32> {
    /// `slot`
    pub slot: i16,
    /// `item`
    pub item: crate::defs::p776::types::UntrustedSlot,
}
#[cfg(feature = "v26_2")]
impl<const V: i32> Decode for SetCreativeSlot<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_i16()?;
            let v2 = <crate::defs::p776::types::UntrustedSlot as Decode>::decode(r)?;
            Self { slot: v1, item: v2 }
        })
    }
}
#[cfg(feature = "v26_2")]
impl<const V: i32> Encode for SetCreativeSlot<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_i16((*self).slot);
        (*self).item.encode(w)?;
        Ok(())
    }
}
#[cfg(feature = "v26_2")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for SetCreativeSlot<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = (g.int_in(-32768, 32767, &[]) as i16);
            let v2 = <crate::defs::p776::types::UntrustedSlot as Generate>::generate(g);
            Self { slot: v1, item: v2 }
        }
    }
}

#[cfg(feature = "v26_2")]
/// `spectator_action` (serverbound play).
#[derive(Debug, Clone, PartialEq)]
pub struct SpectatorAction<const V: i32> {
    /// `spectateEntityId`
    pub spectate_entity_id: i32,
}
#[cfg(feature = "v26_2")]
impl<const V: i32> Decode for SpectatorAction<V> {
    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
        Ok({
            let v1 = r.read_varint()?;
            Self {
                spectate_entity_id: v1,
            }
        })
    }
}
#[cfg(feature = "v26_2")]
impl<const V: i32> Encode for SpectatorAction<V> {
    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
        w.put_varint((*self).spectate_entity_id);
        Ok(())
    }
}
#[cfg(feature = "v26_2")]
#[cfg(feature = "testgen")]
impl<const V: i32> Generate for SpectatorAction<V> {
    fn generate(g: &mut Gen) -> Self {
        {
            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
            Self {
                spectate_entity_id: v1,
            }
        }
    }
}