the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "System.h"
3#include "net.minecraft.world.entity.player.h"
4#include "com.mojang.nbt.h"
5#include "LevelData.h"
6#include "LevelType.h"
7#include "LevelSettings.h"
8
9LevelData::LevelData()
10{
11}
12
13LevelData::LevelData(CompoundTag *tag)
14{
15 seed = tag->getLong(L"RandomSeed");
16 m_pGenerator = LevelType::lvl_normal;
17 if (tag->contains(L"generatorName"))
18 {
19 wstring generatorName = tag->getString(L"generatorName");
20 m_pGenerator = LevelType::getLevelType(generatorName);
21 if (m_pGenerator == NULL)
22 {
23 m_pGenerator = LevelType::lvl_normal;
24 }
25 else if (m_pGenerator->hasReplacement())
26 {
27 int generatorVersion = 0;
28 if (tag->contains(L"generatorVersion"))
29 {
30 generatorVersion = tag->getInt(L"generatorVersion");
31 }
32 m_pGenerator = m_pGenerator->getReplacementForVersion(generatorVersion);
33 }
34
35 if (tag->contains(L"generatorOptions")) generatorOptions = tag->getString(L"generatorOptions");
36 }
37
38 gameType = GameType::byId(tag->getInt(L"GameType"));
39 if (tag->contains(L"MapFeatures"))
40 {
41 generateMapFeatures = tag->getBoolean(L"MapFeatures");
42 }
43 else
44 {
45 generateMapFeatures = true;
46 }
47 spawnBonusChest = tag->getBoolean(L"spawnBonusChest");
48
49 xSpawn = tag->getInt(L"SpawnX");
50 ySpawn = tag->getInt(L"SpawnY");
51 zSpawn = tag->getInt(L"SpawnZ");
52 gameTime = tag->getLong(L"Time");
53 if (tag->contains(L"DayTime"))
54 {
55 dayTime = tag->getLong(L"DayTime");
56 }
57 else
58 {
59 dayTime = gameTime;
60 }
61 lastPlayed = tag->getLong(L"LastPlayed");
62 sizeOnDisk = tag->getLong(L"SizeOnDisk");
63 levelName = tag->getString(L"LevelName");
64 version = tag->getInt(L"version");
65 rainTime = tag->getInt(L"rainTime");
66 raining = tag->getBoolean(L"raining");
67 thunderTime = tag->getInt(L"thunderTime");
68 thundering = tag->getBoolean(L"thundering");
69 hardcore = tag->getBoolean(L"hardcore");
70
71 if (tag->contains(L"initialized"))
72 {
73 initialized = tag->getBoolean(L"initialized");
74 }
75 else
76 {
77 initialized = true;
78 }
79
80 if (tag->contains(L"allowCommands"))
81 {
82 allowCommands = tag->getBoolean(L"allowCommands");
83 }
84 else
85 {
86 allowCommands = gameType == GameType::CREATIVE;
87 }
88
89 // 4J: Game rules are now stored with app game host options
90 /*if (tag->contains(L"GameRules"))
91 {
92 gameRules.loadFromTag(tag->getCompound(L"GameRules"));
93 }*/
94
95 newSeaLevel = tag->getBoolean(L"newSeaLevel"); // 4J added - only use new sea level for newly created maps. This read defaults to false. (sea level changes in 1.8.2)
96 hasBeenInCreative = tag->getBoolean(L"hasBeenInCreative"); // 4J added so we can not award achievements to levels modified in creative
97
98 // 4J added - for stronghold position
99 bStronghold = tag->getBoolean(L"hasStronghold");
100
101 if(bStronghold==false)
102 {
103 // we need to generate the position
104 xStronghold=yStronghold=zStronghold=0;
105 }
106 else
107 {
108 xStronghold = tag->getInt(L"StrongholdX");
109 yStronghold = tag->getInt(L"StrongholdY");
110 zStronghold = tag->getInt(L"StrongholdZ");
111 }
112
113 // 4J added - for stronghold end portal position
114 bStrongholdEndPortal = tag->getBoolean(L"hasStrongholdEndPortal");
115
116 if(bStrongholdEndPortal==false)
117 {
118 // we need to generate the position
119 xStrongholdEndPortal=zStrongholdEndPortal=0;
120 }
121 else
122 {
123 xStrongholdEndPortal = tag->getInt(L"StrongholdEndPortalX");
124 zStrongholdEndPortal = tag->getInt(L"StrongholdEndPortalZ");
125 }
126
127 // 4J Added
128 m_xzSize = tag->getInt(L"XZSize");
129 m_hellScale = tag->getInt(L"HellScale");
130
131#ifdef _LARGE_WORLDS
132 m_classicEdgeMoat = tag->getInt(L"ClassicMoat");
133 m_smallEdgeMoat = tag->getInt(L"SmallMoat");
134 m_mediumEdgeMoat = tag->getInt(L"MediumMoat");
135
136 int newWorldSize = app.GetGameNewWorldSize();
137 int newHellScale = app.GetGameNewHellScale();
138 m_hellScaleOld = m_hellScale;
139 m_xzSizeOld = m_xzSize;
140 if(newWorldSize > m_xzSize)
141 {
142 bool bUseMoat = app.GetGameNewWorldSizeUseMoat();
143 switch (m_xzSize)
144 {
145 case LEVEL_WIDTH_CLASSIC: m_classicEdgeMoat = bUseMoat; break;
146 case LEVEL_WIDTH_SMALL: m_smallEdgeMoat = bUseMoat; break;
147 case LEVEL_WIDTH_MEDIUM: m_mediumEdgeMoat = bUseMoat; break;
148 default: assert(0); break;
149 }
150 assert(newWorldSize > m_xzSize);
151 m_xzSize = newWorldSize;
152 m_hellScale = newHellScale;
153 }
154#endif
155
156
157 m_xzSize = min(m_xzSize,LEVEL_MAX_WIDTH);
158 m_xzSize = max(m_xzSize,LEVEL_MIN_WIDTH);
159
160 m_hellScale = min(m_hellScale,HELL_LEVEL_MAX_SCALE);
161 m_hellScale = max(m_hellScale,HELL_LEVEL_MIN_SCALE);
162
163 int hellXZSize = m_xzSize / m_hellScale;
164 while(hellXZSize > HELL_LEVEL_MAX_WIDTH && m_hellScale < HELL_LEVEL_MAX_SCALE)
165 {
166 ++m_hellScale;
167 hellXZSize = m_xzSize / m_hellScale;
168 }
169
170#ifdef _LARGE_WORLDS
171 // set the host option, in case it wasn't setup already
172 EGameHostOptionWorldSize hostOptionworldSize = e_worldSize_Unknown;
173 switch(m_xzSize)
174 {
175 case LEVEL_WIDTH_CLASSIC: hostOptionworldSize = e_worldSize_Classic; break;
176 case LEVEL_WIDTH_SMALL: hostOptionworldSize = e_worldSize_Small; break;
177 case LEVEL_WIDTH_MEDIUM: hostOptionworldSize = e_worldSize_Medium; break;
178 case LEVEL_WIDTH_LARGE: hostOptionworldSize = e_worldSize_Large; break;
179 default: assert(0); break;
180 }
181 app.SetGameHostOption(eGameHostOption_WorldSize, hostOptionworldSize );
182#endif
183
184 /* 4J - we don't store this anymore
185 if (tag->contains(L"Player"))
186 {
187 loadedPlayerTag = tag->getCompound(L"Player");
188 dimension = loadedPlayerTag->getInt(L"Dimension");
189 }
190 else
191 {
192 this->loadedPlayerTag = NULL;
193 }
194 */
195 dimension = 0;
196}
197
198LevelData::LevelData(LevelSettings *levelSettings, const wstring& levelName)
199{
200 seed = levelSettings->getSeed();
201 gameType = levelSettings->getGameType();
202 generateMapFeatures = levelSettings->isGenerateMapFeatures();
203 spawnBonusChest = levelSettings->hasStartingBonusItems();
204 this->levelName = levelName;
205 m_pGenerator = levelSettings->getLevelType();
206 hardcore = levelSettings->isHardcore();
207 generatorOptions = levelSettings->getLevelTypeOptions();
208 allowCommands = levelSettings->getAllowCommands();
209
210 // 4J Stu - Default initers
211 xSpawn = 0;
212 ySpawn = 0;
213 zSpawn = 0;
214 dayTime = -1; // 4J-JEV: Edited: To know when this is uninitialized.
215 gameTime = -1;
216 lastPlayed = 0;
217 sizeOnDisk = 0;
218 // this->loadedPlayerTag = NULL; // 4J - we don't store this anymore
219 dimension = 0;
220 version = 0;
221 rainTime = 0;
222 raining = false;
223 thunderTime = 0;
224 thundering = false;
225 initialized = false;
226 newSeaLevel = levelSettings->useNewSeaLevel(); // 4J added - only use new sea level for newly created maps (sea level changes in 1.8.2)
227 hasBeenInCreative = levelSettings->getGameType() == GameType::CREATIVE; // 4J added
228
229 // 4J-PB for the stronghold position
230 bStronghold=false;
231 xStronghold = 0;
232 yStronghold = 0;
233 zStronghold = 0;
234
235 xStrongholdEndPortal = 0;
236 zStrongholdEndPortal = 0;
237 bStrongholdEndPortal = false;
238 m_xzSize = levelSettings->getXZSize();
239 m_hellScale = levelSettings->getHellScale();
240
241 m_xzSize = min(m_xzSize,LEVEL_MAX_WIDTH);
242 m_xzSize = max(m_xzSize,LEVEL_MIN_WIDTH);
243
244 m_hellScale = min(m_hellScale,HELL_LEVEL_MAX_SCALE);
245 m_hellScale = max(m_hellScale,HELL_LEVEL_MIN_SCALE);
246
247 int hellXZSize = m_xzSize / m_hellScale;
248 while(hellXZSize > HELL_LEVEL_MAX_WIDTH && m_hellScale < HELL_LEVEL_MAX_SCALE)
249 {
250 ++m_hellScale;
251 hellXZSize = m_xzSize / m_hellScale;
252 }
253#ifdef _LARGE_WORLDS
254 m_hellScaleOld = m_hellScale;
255 m_xzSizeOld = m_xzSize;
256 m_classicEdgeMoat = false;
257 m_smallEdgeMoat = false;
258 m_mediumEdgeMoat = false;
259#endif
260
261}
262
263LevelData::LevelData(LevelData *copy)
264{
265 seed = copy->seed;
266 m_pGenerator = copy->m_pGenerator;
267 generatorOptions = copy->generatorOptions;
268 gameType = copy->gameType;
269 generateMapFeatures = copy->generateMapFeatures;
270 spawnBonusChest = copy->spawnBonusChest;
271 xSpawn = copy->xSpawn;
272 ySpawn = copy->ySpawn;
273 zSpawn = copy->zSpawn;
274 gameTime = copy->gameTime;
275 dayTime = copy->dayTime;
276 lastPlayed = copy->lastPlayed;
277 sizeOnDisk = copy->sizeOnDisk;
278 // this->loadedPlayerTag = copy->loadedPlayerTag; // 4J - we don't store this anymore
279 dimension = copy->dimension;
280 levelName = copy->levelName;
281 version = copy->version;
282 rainTime = copy->rainTime;
283 raining = copy->raining;
284 thunderTime = copy->thunderTime;
285 thundering = copy->thundering;
286 hardcore = copy->hardcore;
287 allowCommands = copy->allowCommands;
288 initialized = copy->initialized;
289 newSeaLevel = copy->newSeaLevel;
290 hasBeenInCreative = copy->hasBeenInCreative;
291 gameRules = copy->gameRules;
292
293 // 4J-PB for the stronghold position
294 bStronghold=copy->bStronghold;
295 xStronghold = copy->xStronghold;
296 yStronghold = copy->yStronghold;
297 zStronghold = copy->zStronghold;
298
299 xStrongholdEndPortal = copy->xStrongholdEndPortal;
300 zStrongholdEndPortal = copy->zStrongholdEndPortal;
301 bStrongholdEndPortal = copy->bStrongholdEndPortal;
302 m_xzSize = copy->m_xzSize;
303 m_hellScale = copy->m_hellScale;
304#ifdef _LARGE_WORLDS
305 m_classicEdgeMoat = copy->m_classicEdgeMoat;
306 m_smallEdgeMoat = copy->m_smallEdgeMoat;
307 m_mediumEdgeMoat = copy->m_mediumEdgeMoat;
308 m_xzSizeOld = copy->m_xzSizeOld;
309 m_hellScaleOld = copy->m_hellScaleOld;
310#endif
311}
312
313CompoundTag *LevelData::createTag()
314{
315 CompoundTag *tag = new CompoundTag();
316
317 setTagData(tag);
318
319 return tag;
320}
321
322CompoundTag *LevelData::createTag(vector<shared_ptr<Player> > *players)
323{
324 // 4J - removed all code for storing tags for players
325 return createTag();
326}
327
328void LevelData::setTagData(CompoundTag *tag)
329{
330 tag->putLong(L"RandomSeed", seed);
331 tag->putString(L"generatorName", m_pGenerator->getGeneratorName());
332 tag->putInt(L"generatorVersion", m_pGenerator->getVersion());
333 tag->putString(L"generatorOptions", generatorOptions);
334 tag->putInt(L"GameType", gameType->getId());
335 tag->putBoolean(L"MapFeatures", generateMapFeatures);
336 tag->putBoolean(L"spawnBonusChest",spawnBonusChest);
337 tag->putInt(L"SpawnX", xSpawn);
338 tag->putInt(L"SpawnY", ySpawn);
339 tag->putInt(L"SpawnZ", zSpawn);
340 tag->putLong(L"Time", gameTime);
341 tag->putLong(L"DayTime", dayTime);
342 tag->putLong(L"SizeOnDisk", sizeOnDisk);
343 tag->putLong(L"LastPlayed", System::currentTimeMillis());
344 tag->putString(L"LevelName", levelName);
345 tag->putInt(L"version", version);
346 tag->putInt(L"rainTime", rainTime);
347 tag->putBoolean(L"raining", raining);
348 tag->putInt(L"thunderTime", thunderTime);
349 tag->putBoolean(L"thundering", thundering);
350 tag->putBoolean(L"hardcore", hardcore);
351 tag->putBoolean(L"allowCommands", allowCommands);
352 tag->putBoolean(L"initialized", initialized);
353 // 4J: Game rules are now stored with app game host options
354 //tag->putCompound(L"GameRules", gameRules.createTag());
355 tag->putBoolean(L"newSeaLevel", newSeaLevel);
356 tag->putBoolean(L"hasBeenInCreative", hasBeenInCreative);
357 // store the stronghold position
358 tag->putBoolean(L"hasStronghold", bStronghold);
359 tag->putInt(L"StrongholdX", xStronghold);
360 tag->putInt(L"StrongholdY", yStronghold);
361 tag->putInt(L"StrongholdZ", zStronghold);
362 // store the stronghold end portal position
363 tag->putBoolean(L"hasStrongholdEndPortal", bStrongholdEndPortal);
364 tag->putInt(L"StrongholdEndPortalX", xStrongholdEndPortal);
365 tag->putInt(L"StrongholdEndPortalZ", zStrongholdEndPortal);
366 tag->putInt(L"XZSize", m_xzSize);
367#ifdef _LARGE_WORLDS
368 tag->putInt(L"ClassicMoat", m_classicEdgeMoat);
369 tag->putInt(L"SmallMoat", m_smallEdgeMoat);
370 tag->putInt(L"MediumMoat", m_mediumEdgeMoat);
371#endif
372
373 tag->putInt(L"HellScale", m_hellScale);
374}
375
376__int64 LevelData::getSeed()
377{
378 return seed;
379}
380
381int LevelData::getXSpawn()
382{
383 return xSpawn;
384}
385
386int LevelData::getYSpawn()
387{
388 return ySpawn;
389}
390
391int LevelData::getZSpawn()
392{
393 return zSpawn;
394}
395
396int LevelData::getXStronghold()
397{
398 return xStronghold;
399}
400
401
402int LevelData::getZStronghold()
403{
404 return zStronghold;
405}
406
407int LevelData::getXStrongholdEndPortal()
408{
409 return xStrongholdEndPortal;
410}
411
412
413int LevelData::getZStrongholdEndPortal()
414{
415 return zStrongholdEndPortal;
416}
417
418__int64 LevelData::getGameTime()
419{
420 return gameTime;
421}
422
423__int64 LevelData::getDayTime()
424{
425 return dayTime;
426}
427
428__int64 LevelData::getSizeOnDisk()
429{
430 return sizeOnDisk;
431}
432
433CompoundTag *LevelData::getLoadedPlayerTag()
434{
435 return NULL; // 4J - we don't store this anymore
436}
437
438// 4J Removed TU9 as it's never accurate due to the dimension never being set
439//int LevelData::getDimension()
440//{
441// return dimension;
442//}
443
444void LevelData::setSeed(__int64 seed)
445{
446 this->seed = seed;
447}
448
449void LevelData::setXSpawn(int xSpawn)
450{
451 this->xSpawn = xSpawn;
452}
453
454void LevelData::setYSpawn(int ySpawn)
455{
456 this->ySpawn = ySpawn;
457}
458
459void LevelData::setZSpawn(int zSpawn)
460{
461 this->zSpawn = zSpawn;
462}
463
464void LevelData::setHasStronghold()
465{
466 this->bStronghold = true;
467}
468
469bool LevelData::getHasStronghold()
470{
471 return this->bStronghold;
472}
473
474
475void LevelData::setXStronghold(int xStronghold)
476{
477 this->xStronghold = xStronghold;
478}
479
480void LevelData::setZStronghold(int zStronghold)
481{
482 this->zStronghold = zStronghold;
483}
484
485void LevelData::setHasStrongholdEndPortal()
486{
487 this->bStrongholdEndPortal = true;
488}
489
490bool LevelData::getHasStrongholdEndPortal()
491{
492 return this->bStrongholdEndPortal;
493}
494
495void LevelData::setXStrongholdEndPortal(int xStrongholdEndPortal)
496{
497 this->xStrongholdEndPortal = xStrongholdEndPortal;
498}
499
500void LevelData::setZStrongholdEndPortal(int zStrongholdEndPortal)
501{
502 this->zStrongholdEndPortal = zStrongholdEndPortal;
503}
504
505void LevelData::setGameTime(__int64 time)
506{
507 gameTime = time;
508}
509
510void LevelData::setDayTime(__int64 time)
511{
512 dayTime = time;
513}
514
515void LevelData::setSizeOnDisk(__int64 sizeOnDisk)
516{
517 this->sizeOnDisk = sizeOnDisk;
518}
519
520void LevelData::setLoadedPlayerTag(CompoundTag *loadedPlayerTag)
521{
522 // 4J - we don't store this anymore
523 // this->loadedPlayerTag = loadedPlayerTag;
524}
525
526// 4J Remove TU9 as it's never used
527//void LevelData::setDimension(int dimension)
528//{
529// this->dimension = dimension;
530//}
531
532void LevelData::setSpawn(int xSpawn, int ySpawn, int zSpawn)
533{
534 this->xSpawn = xSpawn;
535 this->ySpawn = ySpawn;
536 this->zSpawn = zSpawn;
537}
538
539wstring LevelData::getLevelName()
540{
541 return levelName;
542}
543
544void LevelData::setLevelName(const wstring& levelName)
545{
546 this->levelName = levelName;
547}
548
549int LevelData::getVersion()
550{
551 return version;
552}
553
554void LevelData::setVersion(int version)
555{
556 this->version = version;
557}
558
559__int64 LevelData::getLastPlayed()
560{
561 return lastPlayed;
562}
563
564bool LevelData::isThundering()
565{
566 return thundering;
567}
568
569void LevelData::setThundering(bool thundering)
570{
571 this->thundering = thundering;
572}
573
574int LevelData::getThunderTime()
575{
576 return thunderTime;
577}
578
579void LevelData::setThunderTime(int thunderTime)
580{
581 this->thunderTime = thunderTime;
582}
583
584bool LevelData::isRaining()
585{
586 return raining;
587}
588
589void LevelData::setRaining(bool raining)
590{
591 this->raining = raining;
592}
593
594int LevelData::getRainTime()
595{
596 return rainTime;
597}
598
599void LevelData::setRainTime(int rainTime)
600{
601 this->rainTime = rainTime;
602}
603
604GameType *LevelData::getGameType()
605{
606 return gameType;
607}
608
609bool LevelData::isGenerateMapFeatures()
610{
611 return generateMapFeatures;
612}
613
614bool LevelData::getSpawnBonusChest()
615{
616 return spawnBonusChest;
617}
618
619void LevelData::setGameType(GameType *gameType)
620{
621 this->gameType = gameType;
622
623 // 4J Added
624 hasBeenInCreative = hasBeenInCreative ||
625 (gameType == GameType::CREATIVE) ||
626 (app.GetGameHostOption(eGameHostOption_CheatsEnabled) > 0);
627}
628
629bool LevelData::useNewSeaLevel()
630{
631 return newSeaLevel;
632}
633
634bool LevelData::getHasBeenInCreative()
635{
636 return hasBeenInCreative;
637}
638
639void LevelData::setHasBeenInCreative(bool value)
640{
641 hasBeenInCreative = value;
642}
643
644LevelType *LevelData::getGenerator()
645{
646 return m_pGenerator;
647}
648
649void LevelData::setGenerator(LevelType *generator)
650{
651 m_pGenerator = generator;
652}
653
654wstring LevelData::getGeneratorOptions()
655{
656 return generatorOptions;
657}
658
659void LevelData::setGeneratorOptions(const wstring &options)
660{
661 generatorOptions = options;
662}
663
664bool LevelData::isHardcore()
665{
666 return hardcore;
667}
668
669bool LevelData::getAllowCommands()
670{
671 return allowCommands;
672}
673
674void LevelData::setAllowCommands(bool allowCommands)
675{
676 this->allowCommands = allowCommands;
677}
678
679bool LevelData::isInitialized()
680{
681 return initialized;
682}
683
684void LevelData::setInitialized(bool initialized)
685{
686 this->initialized = initialized;
687}
688
689GameRules *LevelData::getGameRules()
690{
691 return &gameRules;
692}
693
694int LevelData::getXZSize()
695{
696 return m_xzSize;
697}
698
699#ifdef _LARGE_WORLDS
700int LevelData::getXZSizeOld()
701{
702 return m_xzSizeOld;
703}
704
705void LevelData::getMoatFlags(bool* bClassicEdgeMoat, bool* bSmallEdgeMoat, bool* bMediumEdgeMoat)
706{
707 *bClassicEdgeMoat = m_classicEdgeMoat;
708 *bSmallEdgeMoat = m_smallEdgeMoat;
709 *bMediumEdgeMoat = m_mediumEdgeMoat;
710
711}
712
713int LevelData::getXZHellSizeOld()
714{
715 int hellXZSizeOld = ceil((float)m_xzSizeOld / m_hellScaleOld);
716
717 while(hellXZSizeOld > HELL_LEVEL_MAX_WIDTH && m_hellScaleOld < HELL_LEVEL_MAX_SCALE)
718 {
719 assert(0); // should never get in here?
720 ++m_hellScaleOld;
721 hellXZSizeOld = m_xzSize / m_hellScale;
722 }
723
724 return hellXZSizeOld;
725}
726
727
728#endif
729
730int LevelData::getHellScale()
731{
732 return m_hellScale;
733}