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/hncom2.xml
8  */
9 module sul.protocol.hncom2.world;
10 
11 import std.bitmanip : write, peek;
12 static import std.conv;
13 import std.system : Endian;
14 import std.typetuple : TypeTuple;
15 import std.typecons : Tuple;
16 import std.uuid : UUID;
17 
18 import sul.utils.buffer;
19 import sul.utils.var;
20 
21 static import sul.protocol.hncom2.types;
22 
23 static if(__traits(compiles, { import sul.metadata.hncom2; })) import sul.metadata.hncom2;
24 
25 alias Packets = TypeTuple!(Add, Remove, UpdateDifficulty, UpdateGamemode, RequestCreation);
26 
27 class Add : Buffer {
28 
29 	public enum ubyte ID = 31;
30 
31 	public enum bool CLIENTBOUND = false;
32 	public enum bool SERVERBOUND = true;
33 
34 	// dimension
35 	public enum ubyte OVERWORLD = 0;
36 	public enum ubyte NETHER = 1;
37 	public enum ubyte END = 2;
38 
39 	// generator
40 	public enum ubyte DEFAULT = 0;
41 	public enum ubyte FLAT = 1;
42 
43 	// difficulty
44 	public enum ubyte PEACEFUL = 0;
45 	public enum ubyte EASY = 1;
46 	public enum ubyte NORMAL = 2;
47 	public enum ubyte HARD = 3;
48 	public enum ubyte HARDCORE = 4;
49 
50 	// gamemode
51 	public enum ubyte SURVIVAL = 0;
52 	public enum ubyte CREATIVE = 1;
53 	public enum ubyte ADVENTURE = 2;
54 	public enum ubyte SPECTATOR = 3;
55 
56 	public enum string[] FIELDS = ["worldId", "name", "dimension", "generator", "difficulty", "gamemode", "spawnPoint", "time", "seed", "parent"];
57 
58 	public uint worldId;
59 	public string name;
60 	public ubyte dimension;
61 	public ubyte generator;
62 	public ubyte difficulty;
63 	public ubyte gamemode;
64 	public Tuple!(int, "x", int, "z") spawnPoint;
65 	public short time;
66 	public int seed;
67 	public int parent = -1;
68 
69 	public pure nothrow @safe @nogc this() {}
70 
71 	public pure nothrow @safe @nogc this(uint worldId, string name=string.init, ubyte dimension=ubyte.init, ubyte generator=ubyte.init, ubyte difficulty=ubyte.init, ubyte gamemode=ubyte.init, Tuple!(int, "x", int, "z") spawnPoint=Tuple!(int, "x", int, "z").init, short time=short.init, int seed=int.init, int parent=-1) {
72 		this.worldId = worldId;
73 		this.name = name;
74 		this.dimension = dimension;
75 		this.generator = generator;
76 		this.difficulty = difficulty;
77 		this.gamemode = gamemode;
78 		this.spawnPoint = spawnPoint;
79 		this.time = time;
80 		this.seed = seed;
81 		this.parent = parent;
82 	}
83 
84 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
85 		_buffer.length = 0;
86 		static if(writeId){ writeBigEndianUbyte(ID); }
87 		writeBytes(varuint.encode(worldId));
88 		writeBytes(varuint.encode(cast(uint)name.length)); writeString(name);
89 		writeBigEndianUbyte(dimension);
90 		writeBigEndianUbyte(generator);
91 		writeBigEndianUbyte(difficulty);
92 		writeBigEndianUbyte(gamemode);
93 		writeBytes(varint.encode(spawnPoint.x)); writeBytes(varint.encode(spawnPoint.z));
94 		writeBigEndianShort(time);
95 		writeBytes(varint.encode(seed));
96 		writeBytes(varint.encode(parent));
97 		return _buffer;
98 	}
99 
100 	public pure nothrow @safe void decode(bool readId=true)() {
101 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
102 		worldId=varuint.decode(_buffer, &_index);
103 		uint bfz=varuint.decode(_buffer, &_index); name=readString(bfz);
104 		dimension=readBigEndianUbyte();
105 		generator=readBigEndianUbyte();
106 		difficulty=readBigEndianUbyte();
107 		gamemode=readBigEndianUbyte();
108 		spawnPoint.x=varint.decode(_buffer, &_index); spawnPoint.z=varint.decode(_buffer, &_index);
109 		time=readBigEndianShort();
110 		seed=varint.decode(_buffer, &_index);
111 		parent=varint.decode(_buffer, &_index);
112 	}
113 
114 	public static pure nothrow @safe Add fromBuffer(bool readId=true)(ubyte[] buffer) {
115 		Add ret = new Add();
116 		ret._buffer = buffer;
117 		ret.decode!readId();
118 		return ret;
119 	}
120 
121 	public override string toString() {
122 		return "Add(worldId: " ~ std.conv.to!string(this.worldId) ~ ", name: " ~ std.conv.to!string(this.name) ~ ", dimension: " ~ std.conv.to!string(this.dimension) ~ ", generator: " ~ std.conv.to!string(this.generator) ~ ", difficulty: " ~ std.conv.to!string(this.difficulty) ~ ", gamemode: " ~ std.conv.to!string(this.gamemode) ~ ", spawnPoint: " ~ std.conv.to!string(this.spawnPoint) ~ ", time: " ~ std.conv.to!string(this.time) ~ ", seed: " ~ std.conv.to!string(this.seed) ~ ", parent: " ~ std.conv.to!string(this.parent) ~ ")";
123 	}
124 
125 }
126 
127 class Remove : Buffer {
128 
129 	public enum ubyte ID = 32;
130 
131 	public enum bool CLIENTBOUND = false;
132 	public enum bool SERVERBOUND = true;
133 
134 	public enum string[] FIELDS = ["worldId"];
135 
136 	public uint worldId;
137 
138 	public pure nothrow @safe @nogc this() {}
139 
140 	public pure nothrow @safe @nogc this(uint worldId) {
141 		this.worldId = worldId;
142 	}
143 
144 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
145 		_buffer.length = 0;
146 		static if(writeId){ writeBigEndianUbyte(ID); }
147 		writeBytes(varuint.encode(worldId));
148 		return _buffer;
149 	}
150 
151 	public pure nothrow @safe void decode(bool readId=true)() {
152 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
153 		worldId=varuint.decode(_buffer, &_index);
154 	}
155 
156 	public static pure nothrow @safe Remove fromBuffer(bool readId=true)(ubyte[] buffer) {
157 		Remove ret = new Remove();
158 		ret._buffer = buffer;
159 		ret.decode!readId();
160 		return ret;
161 	}
162 
163 	public override string toString() {
164 		return "Remove(worldId: " ~ std.conv.to!string(this.worldId) ~ ")";
165 	}
166 
167 }
168 
169 class UpdateDifficulty : Buffer {
170 
171 	public enum ubyte ID = 33;
172 
173 	public enum bool CLIENTBOUND = false;
174 	public enum bool SERVERBOUND = true;
175 
176 	public enum string[] FIELDS = ["worldId", "difficulty"];
177 
178 	public uint worldId;
179 	public ubyte difficulty;
180 
181 	public pure nothrow @safe @nogc this() {}
182 
183 	public pure nothrow @safe @nogc this(uint worldId, ubyte difficulty=ubyte.init) {
184 		this.worldId = worldId;
185 		this.difficulty = difficulty;
186 	}
187 
188 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
189 		_buffer.length = 0;
190 		static if(writeId){ writeBigEndianUbyte(ID); }
191 		writeBytes(varuint.encode(worldId));
192 		writeBigEndianUbyte(difficulty);
193 		return _buffer;
194 	}
195 
196 	public pure nothrow @safe void decode(bool readId=true)() {
197 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
198 		worldId=varuint.decode(_buffer, &_index);
199 		difficulty=readBigEndianUbyte();
200 	}
201 
202 	public static pure nothrow @safe UpdateDifficulty fromBuffer(bool readId=true)(ubyte[] buffer) {
203 		UpdateDifficulty ret = new UpdateDifficulty();
204 		ret._buffer = buffer;
205 		ret.decode!readId();
206 		return ret;
207 	}
208 
209 	public override string toString() {
210 		return "UpdateDifficulty(worldId: " ~ std.conv.to!string(this.worldId) ~ ", difficulty: " ~ std.conv.to!string(this.difficulty) ~ ")";
211 	}
212 
213 }
214 
215 class UpdateGamemode : Buffer {
216 
217 	public enum ubyte ID = 34;
218 
219 	public enum bool CLIENTBOUND = false;
220 	public enum bool SERVERBOUND = true;
221 
222 	public enum string[] FIELDS = ["worldId", "gamemode"];
223 
224 	public uint worldId;
225 	public ubyte gamemode;
226 
227 	public pure nothrow @safe @nogc this() {}
228 
229 	public pure nothrow @safe @nogc this(uint worldId, ubyte gamemode=ubyte.init) {
230 		this.worldId = worldId;
231 		this.gamemode = gamemode;
232 	}
233 
234 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
235 		_buffer.length = 0;
236 		static if(writeId){ writeBigEndianUbyte(ID); }
237 		writeBytes(varuint.encode(worldId));
238 		writeBigEndianUbyte(gamemode);
239 		return _buffer;
240 	}
241 
242 	public pure nothrow @safe void decode(bool readId=true)() {
243 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
244 		worldId=varuint.decode(_buffer, &_index);
245 		gamemode=readBigEndianUbyte();
246 	}
247 
248 	public static pure nothrow @safe UpdateGamemode fromBuffer(bool readId=true)(ubyte[] buffer) {
249 		UpdateGamemode ret = new UpdateGamemode();
250 		ret._buffer = buffer;
251 		ret.decode!readId();
252 		return ret;
253 	}
254 
255 	public override string toString() {
256 		return "UpdateGamemode(worldId: " ~ std.conv.to!string(this.worldId) ~ ", gamemode: " ~ std.conv.to!string(this.gamemode) ~ ")";
257 	}
258 
259 }
260 
261 class RequestCreation : Buffer {
262 
263 	public enum ubyte ID = 35;
264 
265 	public enum bool CLIENTBOUND = true;
266 	public enum bool SERVERBOUND = false;
267 
268 	public enum string[] FIELDS = ["name", "dimension", "generator", "difficulty", "gamemode", "seed", "parent"];
269 
270 	public string name;
271 	public ubyte dimension;
272 	public ubyte generator;
273 	public ubyte difficulty;
274 	public ubyte gamemode;
275 	public int seed;
276 	public int parent = -1;
277 
278 	public pure nothrow @safe @nogc this() {}
279 
280 	public pure nothrow @safe @nogc this(string name, ubyte dimension=ubyte.init, ubyte generator=ubyte.init, ubyte difficulty=ubyte.init, ubyte gamemode=ubyte.init, int seed=int.init, int parent=-1) {
281 		this.name = name;
282 		this.dimension = dimension;
283 		this.generator = generator;
284 		this.difficulty = difficulty;
285 		this.gamemode = gamemode;
286 		this.seed = seed;
287 		this.parent = parent;
288 	}
289 
290 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
291 		_buffer.length = 0;
292 		static if(writeId){ writeBigEndianUbyte(ID); }
293 		writeBytes(varuint.encode(cast(uint)name.length)); writeString(name);
294 		writeBigEndianUbyte(dimension);
295 		writeBigEndianUbyte(generator);
296 		writeBigEndianUbyte(difficulty);
297 		writeBigEndianUbyte(gamemode);
298 		writeBytes(varint.encode(seed));
299 		writeBytes(varint.encode(parent));
300 		return _buffer;
301 	}
302 
303 	public pure nothrow @safe void decode(bool readId=true)() {
304 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
305 		uint bfz=varuint.decode(_buffer, &_index); name=readString(bfz);
306 		dimension=readBigEndianUbyte();
307 		generator=readBigEndianUbyte();
308 		difficulty=readBigEndianUbyte();
309 		gamemode=readBigEndianUbyte();
310 		seed=varint.decode(_buffer, &_index);
311 		parent=varint.decode(_buffer, &_index);
312 	}
313 
314 	public static pure nothrow @safe RequestCreation fromBuffer(bool readId=true)(ubyte[] buffer) {
315 		RequestCreation ret = new RequestCreation();
316 		ret._buffer = buffer;
317 		ret.decode!readId();
318 		return ret;
319 	}
320 
321 	public override string toString() {
322 		return "RequestCreation(name: " ~ std.conv.to!string(this.name) ~ ", dimension: " ~ std.conv.to!string(this.dimension) ~ ", generator: " ~ std.conv.to!string(this.generator) ~ ", difficulty: " ~ std.conv.to!string(this.difficulty) ~ ", gamemode: " ~ std.conv.to!string(this.gamemode) ~ ", seed: " ~ std.conv.to!string(this.seed) ~ ", parent: " ~ std.conv.to!string(this.parent) ~ ")";
323 	}
324 
325 }
326