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