Skip to main content

ghast_protocol/generated/defs/p776/play/
serverbound.rs

1// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
2// (data/pc/26.1/protocol.json + codegen/protocol/delta/776.json). Do not edit; run `cargo run -p ghast-codegen-protocol`.
3// minecraft-data is MIT licensed, Copyright (c) 2015 PrismarineJS; see the NOTICE file
4// in crates/ghast-protocol/src/generated/.
5
6//! Serverbound packets of the play state.
7
8#![allow(
9    unused_imports,
10    unused_variables,
11    unused_mut,
12    unused_parens,
13    unused_braces,
14    clippy::all,
15    clippy::pedantic,
16    non_camel_case_types,
17    non_snake_case
18)]
19use crate::codec::{Decode, DecodeResult, Encode, EncodeResult, McWrite, Reader, decode_exact};
20use crate::error::{DecodeError, EncodeError};
21use crate::nbt::{AnonNbt, RawNbt};
22use crate::packet::{Direction, PacketSet, RawPacket, State};
23#[cfg(feature = "testgen")]
24use crate::testgen::{Gen, Generate};
25use crate::types::{BlockPos, ByteString, Holder, HolderSet, LpVec3, PositionLayout, Uuid};
26use bytes::{BufMut, Bytes, BytesMut};
27
28#[cfg(feature = "v26_2")]
29/// Nested container.
30#[derive(Debug, Clone, PartialEq)]
31pub struct WindowClickChangedSlots {
32    /// `location`
33    pub location: i16,
34    /// `item`
35    pub item: Option<crate::defs::p776::types::HashedSlot>,
36}
37
38#[cfg(feature = "v26_2")]
39/// `window_click` (serverbound play).
40#[derive(Debug, Clone, PartialEq)]
41pub struct WindowClick<const V: i32> {
42    /// `windowId`
43    pub window_id: i32,
44    /// `stateId`
45    pub state_id: i32,
46    /// `slot`
47    pub slot: i16,
48    /// `mouseButton`
49    pub mouse_button: i8,
50    /// `mode`
51    pub mode: i32,
52    /// `changedSlots`
53    pub changed_slots: Vec<crate::defs::p776::play::serverbound::WindowClickChangedSlots>,
54    /// `cursorItem`
55    pub cursor_item: Option<crate::defs::p776::types::HashedSlot>,
56}
57#[cfg(feature = "v26_2")]
58impl<const V: i32> Decode for WindowClick<V> {
59    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
60        Ok({
61            let v1 = r.read_varint()?;
62            let v2 = r.read_varint()?;
63            let v3 = r.read_i16()?;
64            let v4 = r.read_i8()?;
65            let v5 = r.read_varint()?;
66            let v6 = {
67                let v7 = {
68                    let c = r.read_varint()?;
69                    r.check_count(i64::from(c), 3)?
70                };
71                let mut v8 = Vec::with_capacity(v7.min(crate::codec::PREALLOC_LIMIT));
72                for _ in 0..v7 {
73                    v8.push({
74                        let v9 = r.read_i16()?;
75                        let v10 = if r.read_bool()? {
76                            Some(<crate::defs::p776::types::HashedSlot as Decode>::decode(r)?)
77                        } else {
78                            None
79                        };
80                        crate::defs::p776::play::serverbound::WindowClickChangedSlots {
81                            location: v9,
82                            item: v10,
83                        }
84                    });
85                }
86                v8
87            };
88            let v11 = if r.read_bool()? {
89                Some(<crate::defs::p776::types::HashedSlot as Decode>::decode(r)?)
90            } else {
91                None
92            };
93            Self {
94                window_id: v1,
95                state_id: v2,
96                slot: v3,
97                mouse_button: v4,
98                mode: v5,
99                changed_slots: v6,
100                cursor_item: v11,
101            }
102        })
103    }
104}
105#[cfg(feature = "v26_2")]
106impl<const V: i32> Encode for WindowClick<V> {
107    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
108        w.put_varint((*self).window_id);
109        w.put_varint((*self).state_id);
110        w.put_i16((*self).slot);
111        w.put_i8((*self).mouse_button);
112        w.put_varint((*self).mode);
113        w.put_len_varint((*self).changed_slots.len())?;
114        for v1 in (*self).changed_slots.iter() {
115            w.put_i16((*v1).location);
116            match &(*v1).item {
117                Some(v2) => {
118                    w.put_u8(1);
119                    (*v2).encode(w)?;
120                }
121                None => w.put_u8(0),
122            }
123        }
124        match &(*self).cursor_item {
125            Some(v3) => {
126                w.put_u8(1);
127                (*v3).encode(w)?;
128            }
129            None => w.put_u8(0),
130        }
131        Ok(())
132    }
133}
134#[cfg(feature = "v26_2")]
135#[cfg(feature = "testgen")]
136impl<const V: i32> Generate for WindowClick<V> {
137    fn generate(g: &mut Gen) -> Self {
138        {
139            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
140            let v2 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
141            let v3 = (g.int_in(-32768, 32767, &[]) as i16);
142            let v4 = (g.int_in(-128, 127, &[]) as i8);
143            let v5 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
144            let v6 = {
145                let v7 = g.count();
146                let mut v8 = Vec::with_capacity(v7.min(crate::codec::PREALLOC_LIMIT));
147                for _ in 0..v7 {
148                    v8.push({
149                        let v9 = (g.int_in(-32768, 32767, &[]) as i16);
150                        let v10 = if g.bool() {
151                            Some(<crate::defs::p776::types::HashedSlot as Generate>::generate(g))
152                        } else {
153                            None
154                        };
155                        crate::defs::p776::play::serverbound::WindowClickChangedSlots {
156                            location: v9,
157                            item: v10,
158                        }
159                    });
160                }
161                v8
162            };
163            let v11 = if g.bool() {
164                Some(<crate::defs::p776::types::HashedSlot as Generate>::generate(g))
165            } else {
166                None
167            };
168            Self {
169                window_id: v1,
170                state_id: v2,
171                slot: v3,
172                mouse_button: v4,
173                mode: v5,
174                changed_slots: v6,
175                cursor_item: v11,
176            }
177        }
178    }
179}
180
181#[cfg(feature = "v26_2")]
182/// `set_creative_slot` (serverbound play).
183#[derive(Debug, Clone, PartialEq)]
184pub struct SetCreativeSlot<const V: i32> {
185    /// `slot`
186    pub slot: i16,
187    /// `item`
188    pub item: crate::defs::p776::types::UntrustedSlot,
189}
190#[cfg(feature = "v26_2")]
191impl<const V: i32> Decode for SetCreativeSlot<V> {
192    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
193        Ok({
194            let v1 = r.read_i16()?;
195            let v2 = <crate::defs::p776::types::UntrustedSlot as Decode>::decode(r)?;
196            Self { slot: v1, item: v2 }
197        })
198    }
199}
200#[cfg(feature = "v26_2")]
201impl<const V: i32> Encode for SetCreativeSlot<V> {
202    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
203        w.put_i16((*self).slot);
204        (*self).item.encode(w)?;
205        Ok(())
206    }
207}
208#[cfg(feature = "v26_2")]
209#[cfg(feature = "testgen")]
210impl<const V: i32> Generate for SetCreativeSlot<V> {
211    fn generate(g: &mut Gen) -> Self {
212        {
213            let v1 = (g.int_in(-32768, 32767, &[]) as i16);
214            let v2 = <crate::defs::p776::types::UntrustedSlot as Generate>::generate(g);
215            Self { slot: v1, item: v2 }
216        }
217    }
218}
219
220#[cfg(feature = "v26_2")]
221/// `spectator_action` (serverbound play).
222#[derive(Debug, Clone, PartialEq)]
223pub struct SpectatorAction<const V: i32> {
224    /// `spectateEntityId`
225    pub spectate_entity_id: i32,
226}
227#[cfg(feature = "v26_2")]
228impl<const V: i32> Decode for SpectatorAction<V> {
229    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
230        Ok({
231            let v1 = r.read_varint()?;
232            Self {
233                spectate_entity_id: v1,
234            }
235        })
236    }
237}
238#[cfg(feature = "v26_2")]
239impl<const V: i32> Encode for SpectatorAction<V> {
240    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
241        w.put_varint((*self).spectate_entity_id);
242        Ok(())
243    }
244}
245#[cfg(feature = "v26_2")]
246#[cfg(feature = "testgen")]
247impl<const V: i32> Generate for SpectatorAction<V> {
248    fn generate(g: &mut Gen) -> Self {
249        {
250            let v1 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
251            Self {
252                spectate_entity_id: v1,
253            }
254        }
255    }
256}