1 /* 2 * This file was automatically generated by sel-utils and 3 * released under the MIT License. 4 * 5 * License: https://github.com/sel-project/sel-utils/blob/master/LICENSE 6 * Repository: https://github.com/sel-project/sel-utils 7 * Generated from https://github.com/sel-project/sel-utils/blob/master/xml/protocol/java340.xml 8 */ 9 module sul.protocol.java340.types; 10 11 import std.bitmanip : write, peek; 12 static import std.conv; 13 import std.system : Endian; 14 import std.typecons : Tuple; 15 import std.uuid : UUID; 16 17 import sul.utils.buffer; 18 import sul.utils.var; 19 20 static if(__traits(compiles, { import sul.metadata.java340; })) import sul.metadata.java340; 21 22 struct Statistic { 23 24 public enum string[] FIELDS = ["name", "value"]; 25 26 public string name; 27 public uint value; 28 29 public pure nothrow @safe void encode(Buffer buffer) { 30 with(buffer) { 31 writeBytes(varuint.encode(cast(uint)name.length)); writeString(name); 32 writeBytes(varuint.encode(value)); 33 } 34 } 35 36 public pure nothrow @safe void decode(Buffer buffer) { 37 with(buffer) { 38 uint bfz=varuint.decode(_buffer, &_index); name=readString(bfz); 39 value=varuint.decode(_buffer, &_index); 40 } 41 } 42 43 public string toString() { 44 return "Statistic(name: " ~ std.conv.to!string(this.name) ~ ", value: " ~ std.conv.to!string(this.value) ~ ")"; 45 } 46 47 } 48 49 struct BlockChange { 50 51 public enum string[] FIELDS = ["xz", "y", "block"]; 52 53 public ubyte xz; 54 public ubyte y; 55 public uint block; 56 57 public pure nothrow @safe void encode(Buffer buffer) { 58 with(buffer) { 59 writeBigEndianUbyte(xz); 60 writeBigEndianUbyte(y); 61 writeBytes(varuint.encode(block)); 62 } 63 } 64 65 public pure nothrow @safe void decode(Buffer buffer) { 66 with(buffer) { 67 xz=readBigEndianUbyte(); 68 y=readBigEndianUbyte(); 69 block=varuint.decode(_buffer, &_index); 70 } 71 } 72 73 public string toString() { 74 return "BlockChange(xz: " ~ std.conv.to!string(this.xz) ~ ", y: " ~ std.conv.to!string(this.y) ~ ", block: " ~ std.conv.to!string(this.block) ~ ")"; 75 } 76 77 } 78 79 struct Slot { 80 81 public enum string[] FIELDS = ["id", "count", "damage", "nbt"]; 82 83 public short id; 84 public ubyte count; 85 public ushort damage; 86 public ubyte[] nbt; 87 88 public pure nothrow @safe void encode(Buffer buffer) { 89 with(buffer) { 90 writeBigEndianShort(id); 91 if(id>0){ writeBigEndianUbyte(count); } 92 if(id>0){ writeBigEndianUshort(damage); } 93 if(id>0){ writeBytes(nbt); } 94 } 95 } 96 97 public pure nothrow @safe void decode(Buffer buffer) { 98 with(buffer) { 99 id=readBigEndianShort(); 100 if(id>0){ count=readBigEndianUbyte(); } 101 if(id>0){ damage=readBigEndianUshort(); } 102 if(id>0){ nbt=_buffer[_index..$].dup; _index=_buffer.length; } 103 } 104 } 105 106 public string toString() { 107 return "Slot(id: " ~ std.conv.to!string(this.id) ~ ", count: " ~ std.conv.to!string(this.count) ~ ", damage: " ~ std.conv.to!string(this.damage) ~ ", nbt: " ~ std.conv.to!string(this.nbt) ~ ")"; 108 } 109 110 } 111 112 struct Icon { 113 114 // direction and type 115 public enum ubyte WHITE_ARROW = 0; 116 public enum ubyte GREEN_ARROW = 1; 117 public enum ubyte RED_ARROW = 2; 118 public enum ubyte BLUE_ARROW = 3; 119 public enum ubyte WHITE_CROSS = 4; 120 public enum ubyte RED_POINTER = 5; 121 public enum ubyte WHITE_CIRCLE = 6; 122 public enum ubyte SMALL_WHITE_CIRCLE = 7; 123 public enum ubyte MANSION = 8; 124 public enum ubyte TEMPLE = 9; 125 126 public enum string[] FIELDS = ["directionAndType", "position"]; 127 128 public ubyte directionAndType; 129 public Tuple!(ubyte, "x", ubyte, "z") position; 130 131 public pure nothrow @safe void encode(Buffer buffer) { 132 with(buffer) { 133 writeBigEndianUbyte(directionAndType); 134 writeBigEndianUbyte(position.x); writeBigEndianUbyte(position.z); 135 } 136 } 137 138 public pure nothrow @safe void decode(Buffer buffer) { 139 with(buffer) { 140 directionAndType=readBigEndianUbyte(); 141 position.x=readBigEndianUbyte(); position.z=readBigEndianUbyte(); 142 } 143 } 144 145 public string toString() { 146 return "Icon(directionAndType: " ~ std.conv.to!string(this.directionAndType) ~ ", position: " ~ std.conv.to!string(this.position) ~ ")"; 147 } 148 149 } 150 151 struct Property { 152 153 public enum string[] FIELDS = ["name", "value", "signed", "signature"]; 154 155 public string name; 156 public string value; 157 public bool signed; 158 public string signature; 159 160 public pure nothrow @safe void encode(Buffer buffer) { 161 with(buffer) { 162 writeBytes(varuint.encode(cast(uint)name.length)); writeString(name); 163 writeBytes(varuint.encode(cast(uint)value.length)); writeString(value); 164 writeBigEndianBool(signed); 165 if(signed==true){ writeBytes(varuint.encode(cast(uint)signature.length)); writeString(signature); } 166 } 167 } 168 169 public pure nothrow @safe void decode(Buffer buffer) { 170 with(buffer) { 171 uint bfz=varuint.decode(_buffer, &_index); name=readString(bfz); 172 uint dfdu=varuint.decode(_buffer, &_index); value=readString(dfdu); 173 signed=readBigEndianBool(); 174 if(signed==true){ uint clbfdj=varuint.decode(_buffer, &_index); signature=readString(clbfdj); } 175 } 176 } 177 178 public string toString() { 179 return "Property(name: " ~ std.conv.to!string(this.name) ~ ", value: " ~ std.conv.to!string(this.value) ~ ", signed: " ~ std.conv.to!string(this.signed) ~ ", signature: " ~ std.conv.to!string(this.signature) ~ ")"; 180 } 181 182 } 183 184 struct ListAddPlayer { 185 186 // gamemode 187 public enum uint SURVIVAL = 0; 188 public enum uint CREATIVE = 1; 189 public enum uint ADVENTURE = 2; 190 public enum uint SPECTATOR = 3; 191 192 public enum string[] FIELDS = ["uuid", "name", "properties", "gamemode", "latency", "hasDisplayName", "displayName"]; 193 194 public UUID uuid; 195 public string name; 196 public sul.protocol.java340.types.Property[] properties; 197 public uint gamemode; 198 public uint latency; 199 public bool hasDisplayName; 200 public string displayName; 201 202 public pure nothrow @safe void encode(Buffer buffer) { 203 with(buffer) { 204 writeBytes(uuid.data); 205 writeBytes(varuint.encode(cast(uint)name.length)); writeString(name); 206 writeBytes(varuint.encode(cast(uint)properties.length)); foreach(cjcvdlc;properties){ cjcvdlc.encode(bufferInstance); } 207 writeBytes(varuint.encode(gamemode)); 208 writeBytes(varuint.encode(latency)); 209 writeBigEndianBool(hasDisplayName); 210 if(hasDisplayName==true){ writeBytes(varuint.encode(cast(uint)displayName.length)); writeString(displayName); } 211 } 212 } 213 214 public pure nothrow @safe void decode(Buffer buffer) { 215 with(buffer) { 216 if(_buffer.length>=_index+16){ ubyte[16] dvz=_buffer[_index.._index+16].dup; _index+=16; uuid=UUID(dvz); } 217 uint bfz=varuint.decode(_buffer, &_index); name=readString(bfz); 218 properties.length=varuint.decode(_buffer, &_index); foreach(ref cjcvdlc;properties){ cjcvdlc.decode(bufferInstance); } 219 gamemode=varuint.decode(_buffer, &_index); 220 latency=varuint.decode(_buffer, &_index); 221 hasDisplayName=readBigEndianBool(); 222 if(hasDisplayName==true){ uint zlcxe5bu=varuint.decode(_buffer, &_index); displayName=readString(zlcxe5bu); } 223 } 224 } 225 226 public string toString() { 227 return "ListAddPlayer(uuid: " ~ std.conv.to!string(this.uuid) ~ ", name: " ~ std.conv.to!string(this.name) ~ ", properties: " ~ std.conv.to!string(this.properties) ~ ", gamemode: " ~ std.conv.to!string(this.gamemode) ~ ", latency: " ~ std.conv.to!string(this.latency) ~ ", hasDisplayName: " ~ std.conv.to!string(this.hasDisplayName) ~ ", displayName: " ~ std.conv.to!string(this.displayName) ~ ")"; 228 } 229 230 } 231 232 struct ListUpdateGamemode { 233 234 // gamemode 235 public enum uint SURVIVAL = 0; 236 public enum uint CREATIVE = 1; 237 public enum uint ADVENTURE = 2; 238 public enum uint SPECTATOR = 3; 239 240 public enum string[] FIELDS = ["uuid", "gamemode"]; 241 242 public UUID uuid; 243 public uint gamemode; 244 245 public pure nothrow @safe void encode(Buffer buffer) { 246 with(buffer) { 247 writeBytes(uuid.data); 248 writeBytes(varuint.encode(gamemode)); 249 } 250 } 251 252 public pure nothrow @safe void decode(Buffer buffer) { 253 with(buffer) { 254 if(_buffer.length>=_index+16){ ubyte[16] dvz=_buffer[_index.._index+16].dup; _index+=16; uuid=UUID(dvz); } 255 gamemode=varuint.decode(_buffer, &_index); 256 } 257 } 258 259 public string toString() { 260 return "ListUpdateGamemode(uuid: " ~ std.conv.to!string(this.uuid) ~ ", gamemode: " ~ std.conv.to!string(this.gamemode) ~ ")"; 261 } 262 263 } 264 265 struct ListUpdateLatency { 266 267 public enum string[] FIELDS = ["uuid", "latency"]; 268 269 public UUID uuid; 270 public uint latency; 271 272 public pure nothrow @safe void encode(Buffer buffer) { 273 with(buffer) { 274 writeBytes(uuid.data); 275 writeBytes(varuint.encode(latency)); 276 } 277 } 278 279 public pure nothrow @safe void decode(Buffer buffer) { 280 with(buffer) { 281 if(_buffer.length>=_index+16){ ubyte[16] dvz=_buffer[_index.._index+16].dup; _index+=16; uuid=UUID(dvz); } 282 latency=varuint.decode(_buffer, &_index); 283 } 284 } 285 286 public string toString() { 287 return "ListUpdateLatency(uuid: " ~ std.conv.to!string(this.uuid) ~ ", latency: " ~ std.conv.to!string(this.latency) ~ ")"; 288 } 289 290 } 291 292 struct ListUpdateDisplayName { 293 294 public enum string[] FIELDS = ["uuid", "hasDisplayName", "displayName"]; 295 296 public UUID uuid; 297 public bool hasDisplayName; 298 public string displayName; 299 300 public pure nothrow @safe void encode(Buffer buffer) { 301 with(buffer) { 302 writeBytes(uuid.data); 303 writeBigEndianBool(hasDisplayName); 304 if(hasDisplayName==true){ writeBytes(varuint.encode(cast(uint)displayName.length)); writeString(displayName); } 305 } 306 } 307 308 public pure nothrow @safe void decode(Buffer buffer) { 309 with(buffer) { 310 if(_buffer.length>=_index+16){ ubyte[16] dvz=_buffer[_index.._index+16].dup; _index+=16; uuid=UUID(dvz); } 311 hasDisplayName=readBigEndianBool(); 312 if(hasDisplayName==true){ uint zlcxe5bu=varuint.decode(_buffer, &_index); displayName=readString(zlcxe5bu); } 313 } 314 } 315 316 public string toString() { 317 return "ListUpdateDisplayName(uuid: " ~ std.conv.to!string(this.uuid) ~ ", hasDisplayName: " ~ std.conv.to!string(this.hasDisplayName) ~ ", displayName: " ~ std.conv.to!string(this.displayName) ~ ")"; 318 } 319 320 } 321 322 struct Modifier { 323 324 // operation 325 public enum ubyte ADD_SUBSTRACT_AMOUNT = 0; 326 public enum ubyte ADD_SUBSTRACT_AMOUNT_PERCENTAGE = 1; 327 public enum ubyte MULTIPLY_AMOUNT_PERCENTAGE = 2; 328 329 public enum string[] FIELDS = ["uuid", "amount", "operation"]; 330 331 public UUID uuid; 332 public double amount; 333 public ubyte operation; 334 335 public pure nothrow @safe void encode(Buffer buffer) { 336 with(buffer) { 337 writeBytes(uuid.data); 338 writeBigEndianDouble(amount); 339 writeBigEndianUbyte(operation); 340 } 341 } 342 343 public pure nothrow @safe void decode(Buffer buffer) { 344 with(buffer) { 345 if(_buffer.length>=_index+16){ ubyte[16] dvz=_buffer[_index.._index+16].dup; _index+=16; uuid=UUID(dvz); } 346 amount=readBigEndianDouble(); 347 operation=readBigEndianUbyte(); 348 } 349 } 350 351 public string toString() { 352 return "Modifier(uuid: " ~ std.conv.to!string(this.uuid) ~ ", amount: " ~ std.conv.to!string(this.amount) ~ ", operation: " ~ std.conv.to!string(this.operation) ~ ")"; 353 } 354 355 } 356 357 struct Attribute { 358 359 public enum string[] FIELDS = ["key", "value", "modifiers"]; 360 361 public string key; 362 public double value; 363 public sul.protocol.java340.types.Modifier[] modifiers; 364 365 public pure nothrow @safe void encode(Buffer buffer) { 366 with(buffer) { 367 writeBytes(varuint.encode(cast(uint)key.length)); writeString(key); 368 writeBigEndianDouble(value); 369 writeBytes(varuint.encode(cast(uint)modifiers.length)); foreach(b9azzj;modifiers){ b9azzj.encode(bufferInstance); } 370 } 371 } 372 373 public pure nothrow @safe void decode(Buffer buffer) { 374 with(buffer) { 375 uint av=varuint.decode(_buffer, &_index); key=readString(av); 376 value=readBigEndianDouble(); 377 modifiers.length=varuint.decode(_buffer, &_index); foreach(ref b9azzj;modifiers){ b9azzj.decode(bufferInstance); } 378 } 379 } 380 381 public string toString() { 382 return "Attribute(key: " ~ std.conv.to!string(this.key) ~ ", value: " ~ std.conv.to!string(this.value) ~ ", modifiers: " ~ std.conv.to!string(this.modifiers) ~ ")"; 383 } 384 385 } 386 387 struct Entry { 388 389 public enum string[] FIELDS = ["item", "craftingSlot", "playerSlot"]; 390 391 public sul.protocol.java340.types.Slot item; 392 public ubyte craftingSlot; 393 public ubyte playerSlot; 394 395 public pure nothrow @safe void encode(Buffer buffer) { 396 with(buffer) { 397 item.encode(bufferInstance); 398 writeBigEndianUbyte(craftingSlot); 399 writeBigEndianUbyte(playerSlot); 400 } 401 } 402 403 public pure nothrow @safe void decode(Buffer buffer) { 404 with(buffer) { 405 item.decode(bufferInstance); 406 craftingSlot=readBigEndianUbyte(); 407 playerSlot=readBigEndianUbyte(); 408 } 409 } 410 411 public string toString() { 412 return "Entry(item: " ~ std.conv.to!string(this.item) ~ ", craftingSlot: " ~ std.conv.to!string(this.craftingSlot) ~ ", playerSlot: " ~ std.conv.to!string(this.playerSlot) ~ ")"; 413 } 414 415 } 416 417 struct OptionalPosition { 418 419 public enum string[] FIELDS = ["hasPosition", "position"]; 420 421 public bool hasPosition; 422 public ulong position; 423 424 public pure nothrow @safe void encode(Buffer buffer) { 425 with(buffer) { 426 writeBigEndianBool(hasPosition); 427 if(hasPosition==true){ writeBigEndianUlong(position); } 428 } 429 } 430 431 public pure nothrow @safe void decode(Buffer buffer) { 432 with(buffer) { 433 hasPosition=readBigEndianBool(); 434 if(hasPosition==true){ position=readBigEndianUlong(); } 435 } 436 } 437 438 public string toString() { 439 return "OptionalPosition(hasPosition: " ~ std.conv.to!string(this.hasPosition) ~ ", position: " ~ std.conv.to!string(this.position) ~ ")"; 440 } 441 442 } 443 444 struct OptionalUuid { 445 446 public enum string[] FIELDS = ["hasUuid", "uuid"]; 447 448 public bool hasUuid; 449 public UUID uuid; 450 451 public pure nothrow @safe void encode(Buffer buffer) { 452 with(buffer) { 453 writeBigEndianBool(hasUuid); 454 writeBytes(uuid.data); 455 } 456 } 457 458 public pure nothrow @safe void decode(Buffer buffer) { 459 with(buffer) { 460 hasUuid=readBigEndianBool(); 461 if(_buffer.length>=_index+16){ ubyte[16] dvz=_buffer[_index.._index+16].dup; _index+=16; uuid=UUID(dvz); } 462 } 463 } 464 465 public string toString() { 466 return "OptionalUuid(hasUuid: " ~ std.conv.to!string(this.hasUuid) ~ ", uuid: " ~ std.conv.to!string(this.uuid) ~ ")"; 467 } 468 469 } 470