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