1 /*
2  * This file has been automatically generated by Soupply and released under the MIT license.
3  * Generated from java335
4  */
5 module soupply.java335.metadata;
6 
7 import packetmaker;
8 import packetmaker.maker : EndianType, writeLength, writeImpl, readLength, readImpl;
9 
10 import soupply.util;
11 
12 static import soupply.java335.types;
13 
14 enum MetadataType : ubyte
15 {
16     BYTE = 0,
17     INT = 1,
18     FLOAT = 2,
19     STRING = 3,
20     CHAT = 4,
21     SLOT = 5,
22     BOOL = 6,
23     ROTATION = 7,
24     POSITION = 8,
25     OPTIONAL_POSITION = 9,
26     DIRECTION = 10,
27     UUID = 11,
28     BLOCK = 12,
29     NBT = 13,
30 }
31 
32 class MetadataValue : PacketImpl!(Endian.bigEndian, varuint, varuint)
33 {
34 
35     @EncodeOnly ubyte type;
36 
37     this(ubyte type) pure nothrow @safe @nogc
38     {
39         this.type = type;
40     }
41 
42     mixin Make;
43 
44 }
45 
46 class MetadataByte : MetadataValue
47 {
48 
49     byte value;
50 
51     this() pure nothrow @safe @nogc
52     {
53         super(0);
54     }
55 
56     this(byte value) pure nothrow @safe @nogc
57     {
58         this();
59         this.value = value;
60     }
61 
62     mixin Make;
63 
64 }
65 
66 class MetadataInt : MetadataValue
67 {
68 
69     @Var uint value;
70 
71     this() pure nothrow @safe @nogc
72     {
73         super(1);
74     }
75 
76     this(uint value) pure nothrow @safe @nogc
77     {
78         this();
79         this.value = value;
80     }
81 
82     mixin Make;
83 
84 }
85 
86 class MetadataFloat : MetadataValue
87 {
88 
89     float value;
90 
91     this() pure nothrow @safe @nogc
92     {
93         super(2);
94     }
95 
96     this(float value) pure nothrow @safe @nogc
97     {
98         this();
99         this.value = value;
100     }
101 
102     mixin Make;
103 
104 }
105 
106 class MetadataString : MetadataValue
107 {
108 
109     string value;
110 
111     this() pure nothrow @safe @nogc
112     {
113         super(3);
114     }
115 
116     this(string value) pure nothrow @safe @nogc
117     {
118         this();
119         this.value = value;
120     }
121 
122     mixin Make;
123 
124 }
125 
126 class MetadataChat : MetadataValue
127 {
128 
129     string value;
130 
131     this() pure nothrow @safe @nogc
132     {
133         super(4);
134     }
135 
136     this(string value) pure nothrow @safe @nogc
137     {
138         this();
139         this.value = value;
140     }
141 
142     mixin Make;
143 
144 }
145 
146 class MetadataSlot : MetadataValue
147 {
148 
149     soupply.java335.types.Slot value;
150 
151     this() pure nothrow @safe @nogc
152     {
153         super(5);
154     }
155 
156     this(soupply.java335.types.Slot value) pure nothrow @safe @nogc
157     {
158         this();
159         this.value = value;
160     }
161 
162     mixin Make;
163 
164 }
165 
166 class MetadataBool : MetadataValue
167 {
168 
169     bool value;
170 
171     this() pure nothrow @safe @nogc
172     {
173         super(6);
174     }
175 
176     this(bool value) pure nothrow @safe @nogc
177     {
178         this();
179         this.value = value;
180     }
181 
182     mixin Make;
183 
184 }
185 
186 class MetadataRotation : MetadataValue
187 {
188 
189     Vector!(float, "xyz") value;
190 
191     this() pure nothrow @safe @nogc
192     {
193         super(7);
194     }
195 
196     this(Vector!(float, "xyz") value) pure nothrow @safe @nogc
197     {
198         this();
199         this.value = value;
200     }
201 
202     mixin Make;
203 
204 }
205 
206 class MetadataPosition : MetadataValue
207 {
208 
209     ulong value;
210 
211     this() pure nothrow @safe @nogc
212     {
213         super(8);
214     }
215 
216     this(ulong value) pure nothrow @safe @nogc
217     {
218         this();
219         this.value = value;
220     }
221 
222     mixin Make;
223 
224 }
225 
226 class MetadataOptionalPosition : MetadataValue
227 {
228 
229     soupply.java335.types.OptionalPosition value;
230 
231     this() pure nothrow @safe @nogc
232     {
233         super(9);
234     }
235 
236     this(soupply.java335.types.OptionalPosition value) pure nothrow @safe @nogc
237     {
238         this();
239         this.value = value;
240     }
241 
242     mixin Make;
243 
244 }
245 
246 class MetadataDirection : MetadataValue
247 {
248 
249     @Var uint value;
250 
251     this() pure nothrow @safe @nogc
252     {
253         super(10);
254     }
255 
256     this(uint value) pure nothrow @safe @nogc
257     {
258         this();
259         this.value = value;
260     }
261 
262     mixin Make;
263 
264 }
265 
266 class MetadataUuid : MetadataValue
267 {
268 
269     soupply.java335.types.OptionalUuid value;
270 
271     this() pure nothrow @safe @nogc
272     {
273         super(11);
274     }
275 
276     this(soupply.java335.types.OptionalUuid value) pure nothrow @safe @nogc
277     {
278         this();
279         this.value = value;
280     }
281 
282     mixin Make;
283 
284 }
285 
286 class MetadataBlock : MetadataValue
287 {
288 
289     @Var uint value;
290 
291     this() pure nothrow @safe @nogc
292     {
293         super(12);
294     }
295 
296     this(uint value) pure nothrow @safe @nogc
297     {
298         this();
299         this.value = value;
300     }
301 
302     mixin Make;
303 
304 }
305 
306 class MetadataNbt : MetadataValue
307 {
308 
309     @Bytes ubyte[] value;
310 
311     this() pure nothrow @safe @nogc
312     {
313         super(13);
314     }
315 
316     this(ubyte[] value) pure nothrow @safe @nogc
317     {
318         this();
319         this.value = value;
320     }
321 
322     mixin Make;
323 
324 }
325 
326 struct Metadata
327 {
328 
329     MetadataValue[ubyte] values;
330 
331     void encodeBody(Buffer buffer)
332     {
333         foreach(id, value; values)
334         {
335             writeImpl!(EndianType.bigEndian, ubyte)(buffer, id);
336             value.encodeBody(buffer);
337         }
338         buffer.write(ubyte(255));
339     }
340 
341     void decodeBody(Buffer buffer)
342     {
343         ubyte id;
344         while((id = buffer.read!ubyte()) != 255)
345         {
346             switch(readImpl!(EndianType.bigEndian, ubyte)(buffer))
347             {
348                 case 0:
349                     auto value = new MetadataByte();
350                     value.decodeBody(buffer);
351                     this.values[id] = value;
352                     break;
353                 case 1:
354                     auto value = new MetadataInt();
355                     value.decodeBody(buffer);
356                     this.values[id] = value;
357                     break;
358                 case 2:
359                     auto value = new MetadataFloat();
360                     value.decodeBody(buffer);
361                     this.values[id] = value;
362                     break;
363                 case 3:
364                     auto value = new MetadataString();
365                     value.decodeBody(buffer);
366                     this.values[id] = value;
367                     break;
368                 case 4:
369                     auto value = new MetadataChat();
370                     value.decodeBody(buffer);
371                     this.values[id] = value;
372                     break;
373                 case 5:
374                     auto value = new MetadataSlot();
375                     value.decodeBody(buffer);
376                     this.values[id] = value;
377                     break;
378                 case 6:
379                     auto value = new MetadataBool();
380                     value.decodeBody(buffer);
381                     this.values[id] = value;
382                     break;
383                 case 7:
384                     auto value = new MetadataRotation();
385                     value.decodeBody(buffer);
386                     this.values[id] = value;
387                     break;
388                 case 8:
389                     auto value = new MetadataPosition();
390                     value.decodeBody(buffer);
391                     this.values[id] = value;
392                     break;
393                 case 9:
394                     auto value = new MetadataOptionalPosition();
395                     value.decodeBody(buffer);
396                     this.values[id] = value;
397                     break;
398                 case 10:
399                     auto value = new MetadataDirection();
400                     value.decodeBody(buffer);
401                     this.values[id] = value;
402                     break;
403                 case 11:
404                     auto value = new MetadataUuid();
405                     value.decodeBody(buffer);
406                     this.values[id] = value;
407                     break;
408                 case 12:
409                     auto value = new MetadataBlock();
410                     value.decodeBody(buffer);
411                     this.values[id] = value;
412                     break;
413                 case 13:
414                     auto value = new MetadataNbt();
415                     value.decodeBody(buffer);
416                     this.values[id] = value;
417                     break;
418                 default: throw new Exception("Unknown metadata type");
419             }
420         }
421     }
422 
423 }