the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 158 lines 4.0 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.level.h" 3#include "net.minecraft.world.level.levelgen.h" 4#include "net.minecraft.world.level.levelgen.feature.h" 5#include "net.minecraft.world.level.levelgen.structure.h" 6#include "net.minecraft.world.level.levelgen.synth.h" 7#include "net.minecraft.world.level.tile.h" 8#include "net.minecraft.world.level.storage.h" 9#include "FlatLevelSource.h" 10 11 12//FlatLevelSource::villageFeature = new VillageFeature(1); 13 14FlatLevelSource::FlatLevelSource(Level *level, __int64 seed, bool generateStructures) 15{ 16 m_XZSize = level->getLevelData()->getXZSize(); 17 18 this->level = level; 19 this->generateStructures = generateStructures; 20 this->random = new Random(seed); 21 this->pprandom = new Random(seed); // 4J - added, so that we can have a separate random for doing post-processing in parallel with creation 22 23 villageFeature = new VillageFeature(m_XZSize); 24 25 26} 27 28FlatLevelSource::~FlatLevelSource() 29{ 30 delete random; 31 delete pprandom; 32 delete villageFeature; 33} 34 35void FlatLevelSource::prepareHeights(byteArray blocks) 36{ 37 int height = blocks.length / (16 * 16); 38 39 for (int xc = 0; xc < 16; xc++) 40 { 41 for (int zc = 0; zc < 16; zc++) 42 { 43 for (int yc = 0; yc < height; yc++) 44 { 45 int block = 0; 46 if (yc == 0) 47 { 48 block = Tile::unbreakable_Id; 49 } 50 else if (yc <= 2) 51 { 52 block = Tile::dirt_Id; 53 } 54 else if (yc == 3) 55 { 56 block = Tile::grass_Id; 57 } 58 blocks[xc << 11 | zc << 7 | yc] = (byte) block; 59 } 60 } 61 } 62} 63 64LevelChunk *FlatLevelSource::create(int x, int z) 65{ 66 return getChunk(x, z); 67} 68 69LevelChunk *FlatLevelSource::getChunk(int xOffs, int zOffs) 70{ 71 // 4J - now allocating this with a physical alloc & bypassing general memory management so that it will get cleanly freed 72 int chunksSize = Level::genDepth * 16 * 16; 73 byte *tileData = (byte *)XPhysicalAlloc(chunksSize, MAXULONG_PTR, 4096, PAGE_READWRITE); 74 XMemSet128(tileData,0,chunksSize); 75 byteArray blocks = byteArray(tileData,chunksSize); 76// byteArray blocks = byteArray(16 * level->depth * 16); 77 prepareHeights(blocks); 78 79// LevelChunk *levelChunk = new LevelChunk(level, blocks, xOffs, zOffs); // 4J - moved below 80 // double[] temperatures = level.getBiomeSource().temperatures; 81 82 83 if (generateStructures) 84 { 85 villageFeature->apply(this, level, xOffs, zOffs, blocks); 86 } 87 88 // 4J - this now creates compressed block data from the blocks array passed in, so moved it until after the blocks are actually finalised. We also 89 // now need to free the passed in blocks as the LevelChunk doesn't use the passed in allocation anymore. 90 LevelChunk *levelChunk = new LevelChunk(level, blocks, xOffs, zOffs); 91 XPhysicalFree(tileData); 92 93 levelChunk->recalcHeightmap(); 94 95 return levelChunk; 96} 97 98 99bool FlatLevelSource::hasChunk(int x, int y) 100{ 101 return true; 102} 103 104void FlatLevelSource::postProcess(ChunkSource *parent, int xt, int zt) 105{ 106 // 4J - changed from random to pprandom so we can run in parallel with getChunk etc. 107 pprandom->setSeed(level->getSeed()); 108 __int64 xScale = pprandom->nextLong() / 2 * 2 + 1; 109 __int64 zScale = pprandom->nextLong() / 2 * 2 + 1; 110 pprandom->setSeed(((xt * xScale) + (zt * zScale)) ^ level->getSeed()); 111 112 if (generateStructures) 113 { 114 villageFeature->postProcess(level, pprandom, xt, zt); 115 } 116 117 app.processSchematics(parent->getChunk(xt,zt)); 118} 119 120bool FlatLevelSource::save(bool force, ProgressListener *progressListener) 121{ 122 return true; 123} 124 125bool FlatLevelSource::tick() 126{ 127 return false; 128} 129 130bool FlatLevelSource::shouldSave() 131{ 132 return true; 133} 134 135wstring FlatLevelSource::gatherStats() 136{ 137 return L"FlatLevelSource"; 138} 139 140vector<Biome::MobSpawnerData *> *FlatLevelSource::getMobsAt(MobCategory *mobCategory, int x, int y, int z) 141{ 142 Biome *biome = level->getBiome(x, z); 143 if (biome == NULL) 144 { 145 return NULL; 146 } 147 return biome->getMobs(mobCategory); 148} 149 150TilePos *FlatLevelSource::findNearestMapFeature(Level *level, const wstring& featureName, int x, int y, int z) 151{ 152 return NULL; 153} 154 155void FlatLevelSource::recreateLogicStructuresForChunk(int chunkX, int chunkZ) 156{ 157 // TODO 158}