1 /*
2  * This file has been automatically generated by Soupply and released under the MIT license.
3  * Generated from bedrock141
4  */
5 module soupply.bedrock141.metadata;
6 
7 import packetmaker;
8 import packetmaker.maker : EndianType, writeLength, writeImpl, readLength, readImpl;
9 
10 import soupply.util;
11 
12 static import soupply.bedrock141.types;
13 
14 enum MetadataType : uint
15 {
16     BYTE = 0,
17     SHORT = 1,
18     INT = 2,
19     FLOAT = 3,
20     STRING = 4,
21     SLOT = 5,
22     BLOCK_POSITION = 6,
23     LONG = 7,
24     ENTITY_POSITION = 8,
25 }
26 
27 class MetadataValue : PacketImpl!(Endian.littleEndian, varuint, varuint)
28 {
29 
30     @Var @EncodeOnly uint type;
31 
32     this(uint type) pure nothrow @safe @nogc
33     {
34         this.type = type;
35     }
36 
37     mixin Make;
38 
39 }
40 
41 class MetadataByte : MetadataValue
42 {
43 
44     byte value;
45 
46     this() pure nothrow @safe @nogc
47     {
48         super(0);
49     }
50 
51     this(byte value) pure nothrow @safe @nogc
52     {
53         this();
54         this.value = value;
55     }
56 
57     mixin Make;
58 
59 }
60 
61 class MetadataShort : MetadataValue
62 {
63 
64     short value;
65 
66     this() pure nothrow @safe @nogc
67     {
68         super(1);
69     }
70 
71     this(short value) pure nothrow @safe @nogc
72     {
73         this();
74         this.value = value;
75     }
76 
77     mixin Make;
78 
79 }
80 
81 class MetadataInt : MetadataValue
82 {
83 
84     @Var int value;
85 
86     this() pure nothrow @safe @nogc
87     {
88         super(2);
89     }
90 
91     this(int value) pure nothrow @safe @nogc
92     {
93         this();
94         this.value = value;
95     }
96 
97     mixin Make;
98 
99 }
100 
101 class MetadataFloat : MetadataValue
102 {
103 
104     float value;
105 
106     this() pure nothrow @safe @nogc
107     {
108         super(3);
109     }
110 
111     this(float value) pure nothrow @safe @nogc
112     {
113         this();
114         this.value = value;
115     }
116 
117     mixin Make;
118 
119 }
120 
121 class MetadataString : MetadataValue
122 {
123 
124     string value;
125 
126     this() pure nothrow @safe @nogc
127     {
128         super(4);
129     }
130 
131     this(string value) pure nothrow @safe @nogc
132     {
133         this();
134         this.value = value;
135     }
136 
137     mixin Make;
138 
139 }
140 
141 class MetadataSlot : MetadataValue
142 {
143 
144     soupply.bedrock141.types.Slot value;
145 
146     this() pure nothrow @safe @nogc
147     {
148         super(5);
149     }
150 
151     this(soupply.bedrock141.types.Slot value) pure nothrow @safe @nogc
152     {
153         this();
154         this.value = value;
155     }
156 
157     mixin Make;
158 
159 }
160 
161 class MetadataBlockPosition : MetadataValue
162 {
163 
164     @Var Vector!(int, "xyz") value;
165 
166     this() pure nothrow @safe @nogc
167     {
168         super(6);
169     }
170 
171     this(Vector!(int, "xyz") value) pure nothrow @safe @nogc
172     {
173         this();
174         this.value = value;
175     }
176 
177     mixin Make;
178 
179 }
180 
181 class MetadataLong : MetadataValue
182 {
183 
184     @Var long value;
185 
186     this() pure nothrow @safe @nogc
187     {
188         super(7);
189     }
190 
191     this(long value) pure nothrow @safe @nogc
192     {
193         this();
194         this.value = value;
195     }
196 
197     mixin Make;
198 
199 }
200 
201 class MetadataEntityPosition : MetadataValue
202 {
203 
204     Vector!(float, "xyz") value;
205 
206     this() pure nothrow @safe @nogc
207     {
208         super(8);
209     }
210 
211     this(Vector!(float, "xyz") value) pure nothrow @safe @nogc
212     {
213         this();
214         this.value = value;
215     }
216 
217     mixin Make;
218 
219 }
220 
221 struct Metadata
222 {
223 
224     MetadataValue[uint] values;
225 
226     void encodeBody(Buffer buffer)
227     {
228         writeLength!(EndianType.var, uint)(buffer, values.length);
229         foreach(id, value; values)
230         {
231             writeImpl!(EndianType.var, uint)(buffer, id);
232             value.encodeBody(buffer);
233         }
234     }
235 
236     void decodeBody(Buffer buffer)
237     {
238         foreach(i ; 0..readLength!(EndianType.var, uint)(buffer))
239         {
240             uint id = readImpl!(EndianType.var, uint)(buffer);
241             switch(readImpl!(EndianType.var, uint)(buffer))
242             {
243                 case 0:
244                     auto value = new MetadataByte();
245                     value.decodeBody(buffer);
246                     this.values[id] = value;
247                     break;
248                 case 1:
249                     auto value = new MetadataShort();
250                     value.decodeBody(buffer);
251                     this.values[id] = value;
252                     break;
253                 case 2:
254                     auto value = new MetadataInt();
255                     value.decodeBody(buffer);
256                     this.values[id] = value;
257                     break;
258                 case 3:
259                     auto value = new MetadataFloat();
260                     value.decodeBody(buffer);
261                     this.values[id] = value;
262                     break;
263                 case 4:
264                     auto value = new MetadataString();
265                     value.decodeBody(buffer);
266                     this.values[id] = value;
267                     break;
268                 case 5:
269                     auto value = new MetadataSlot();
270                     value.decodeBody(buffer);
271                     this.values[id] = value;
272                     break;
273                 case 6:
274                     auto value = new MetadataBlockPosition();
275                     value.decodeBody(buffer);
276                     this.values[id] = value;
277                     break;
278                 case 7:
279                     auto value = new MetadataLong();
280                     value.decodeBody(buffer);
281                     this.values[id] = value;
282                     break;
283                 case 8:
284                     auto value = new MetadataEntityPosition();
285                     value.decodeBody(buffer);
286                     this.values[id] = value;
287                     break;
288                 default: throw new Exception("Unknown metadata type");
289             }
290         }
291     }
292 
293 }