the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 228 lines 6.5 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.level.h" 3#include "net.minecraft.world.level.tile.h" 4#include "net.minecraft.world.level.storage.h" 5#include "HellFlatLevelSource.h" 6 7HellFlatLevelSource::HellFlatLevelSource(Level *level, __int64 seed) 8{ 9 int xzSize = level->getLevelData()->getXZSize(); 10 int hellScale = level->getLevelData()->getHellScale(); 11 m_XZSize = ceil((float)xzSize / hellScale); 12 13 this->level = level; 14 15 random = new Random(seed); 16 pprandom = new Random(seed); 17} 18 19HellFlatLevelSource::~HellFlatLevelSource() 20{ 21 delete random; 22 delete pprandom; 23} 24 25void HellFlatLevelSource::prepareHeights(int xOffs, int zOffs, byteArray blocks) 26{ 27 int height = blocks.length / (16 * 16); 28 29 for (int xc = 0; xc < 16; xc++) 30 { 31 for (int zc = 0; zc < 16; zc++) 32 { 33 for (int yc = 0; yc < height; yc++) 34 { 35 int block = 0; 36 if ( (yc <= 6) || ( yc >= 121 ) ) 37 { 38 block = Tile::netherRack_Id; 39 } 40 41 blocks[xc << 11 | zc << 7 | yc] = (byte) block; 42 } 43 } 44 } 45} 46 47void HellFlatLevelSource::buildSurfaces(int xOffs, int zOffs, byteArray blocks) 48{ 49 for (int x = 0; x < 16; x++) 50 { 51 for (int z = 0; z < 16; z++) 52 { 53 for (int y = Level::genDepthMinusOne; y >= 0; y--) 54 { 55 int offs = (z * 16 + x) * Level::genDepth + y; 56 57 // 4J Build walls around the level 58 bool blockSet = false; 59 if(xOffs <= -(m_XZSize/2)) 60 { 61 if( z - random->nextInt( 4 ) <= 0 || xOffs < -(m_XZSize/2) ) 62 { 63 blocks[offs] = (byte) Tile::unbreakable_Id; 64 blockSet = true; 65 } 66 } 67 if(zOffs <= -(m_XZSize/2)) 68 { 69 if( x - random->nextInt( 4 ) <= 0 || zOffs < -(m_XZSize/2)) 70 { 71 blocks[offs] = (byte) Tile::unbreakable_Id; 72 blockSet = true; 73 } 74 } 75 if(xOffs >= (m_XZSize/2)-1) 76 { 77 if( z + random->nextInt(4) >= 15 || xOffs > (m_XZSize/2)) 78 { 79 blocks[offs] = (byte) Tile::unbreakable_Id; 80 blockSet = true; 81 } 82 } 83 if(zOffs >= (m_XZSize/2)-1) 84 { 85 if( x + random->nextInt(4) >= 15 || zOffs > (m_XZSize/2) ) 86 { 87 blocks[offs] = (byte) Tile::unbreakable_Id; 88 blockSet = true; 89 } 90 } 91 if( blockSet ) continue; 92 // End 4J Extra to build walls around the level 93 94 if (y >= Level::genDepthMinusOne - random->nextInt(5)) 95 { 96 blocks[offs] = (byte) Tile::unbreakable_Id; 97 } 98 else if (y <= 0 + random->nextInt(5)) 99 { 100 blocks[offs] = (byte) Tile::unbreakable_Id; 101 } 102 } 103 } 104 } 105} 106 107LevelChunk *HellFlatLevelSource::create(int x, int z) 108{ 109 return getChunk(x,z); 110} 111 112LevelChunk *HellFlatLevelSource::getChunk(int xOffs, int zOffs) 113{ 114 random->setSeed(xOffs * 341873128712l + zOffs * 132897987541l); 115 116 // 4J - now allocating this with a physical alloc & bypassing general memory management so that it will get cleanly freed 117 int chunksSize = Level::genDepth * 16 * 16; 118 byte *tileData = (byte *)XPhysicalAlloc(chunksSize, MAXULONG_PTR, 4096, PAGE_READWRITE); 119 XMemSet128(tileData,0,chunksSize); 120 byteArray blocks = byteArray(tileData,chunksSize); 121 // byteArray blocks = byteArray(16 * level->depth * 16); 122 123 prepareHeights(xOffs, zOffs, blocks); 124 buildSurfaces(xOffs, zOffs, blocks); 125 126 // caveFeature->apply(this, level, xOffs, zOffs, blocks); 127 // townFeature.apply(this, level, xOffs, zOffs, blocks); 128 // addCaves(xOffs, zOffs, blocks); 129 // addTowns(xOffs, zOffs, blocks); 130 131 // 4J - this now creates compressed block data from the blocks array passed in, so needs to be after data is finalised. 132 // Also now need to free the passed in blocks as the LevelChunk doesn't use the passed in allocation anymore. 133 LevelChunk *levelChunk = new LevelChunk(level, blocks, xOffs, zOffs); 134 XPhysicalFree(tileData); 135 return levelChunk; 136} 137 138// 4J - removed & moved into its own method from getChunk, so we can call recalcHeightmap after the chunk is added into the cache. Without 139// doing this, then loads of the lightgaps() calls will fail to add any lights, because adding a light checks if the cache has this chunk in. 140// lightgaps also does light 1 block into the neighbouring chunks, and maybe that is somehow enough to get lighting to propagate round the world, 141// but this just doesn't seem right - this isn't a new fault in the 360 version, have checked that java does the same. 142void HellFlatLevelSource::lightChunk(LevelChunk *lc) 143{ 144 lc->recalcHeightmap(); 145} 146 147bool HellFlatLevelSource::hasChunk(int x, int y) 148{ 149 return true; 150} 151 152void HellFlatLevelSource::postProcess(ChunkSource *parent, int xt, int zt) 153{ 154 HeavyTile::instaFall = true; 155 int xo = xt * 16; 156 int zo = zt * 16; 157 158 // 4J - added. The original java didn't do any setting of the random seed here. We'll be running our postProcess in parallel with getChunk etc. so 159 // we need to use a separate random - have used the same initialisation code as used in RandomLevelSource::postProcess to make sure this random value 160 // is consistent for each world generation. Also changed all uses of random here to pprandom. 161 pprandom->setSeed(level->getSeed()); 162 __int64 xScale = pprandom->nextLong() / 2 * 2 + 1; 163 __int64 zScale = pprandom->nextLong() / 2 * 2 + 1; 164 pprandom->setSeed(((xt * xScale) + (zt * zScale)) ^ level->getSeed()); 165 166 int count = pprandom->nextInt(pprandom->nextInt(10) + 1) + 1; 167 168 for (int i = 0; i < count; i++) 169 { 170 int x = xo + pprandom->nextInt(16) + 8; 171 int y = pprandom->nextInt(Level::genDepth - 8) + 4; 172 int z = zo + pprandom->nextInt(16) + 8; 173 HellFireFeature().place(level, pprandom, x, y, z); 174 } 175 176 count = pprandom->nextInt(pprandom->nextInt(10) + 1); 177 for (int i = 0; i < count; i++) 178 { 179 int x = xo + pprandom->nextInt(16) + 8; 180 int y = pprandom->nextInt(Level::genDepth - 8) + 4; 181 int z = zo + pprandom->nextInt(16) + 8; 182 LightGemFeature().place(level, pprandom, x, y, z); 183 } 184 185 HeavyTile::instaFall = false; 186 187 app.processSchematics(parent->getChunk(xt,zt)); 188 189} 190 191bool HellFlatLevelSource::save(bool force, ProgressListener *progressListener) 192{ 193 return true; 194} 195 196bool HellFlatLevelSource::tick() 197{ 198 return false; 199} 200 201bool HellFlatLevelSource::shouldSave() 202{ 203 return true; 204} 205 206wstring HellFlatLevelSource::gatherStats() 207{ 208 return L"HellFlatLevelSource"; 209} 210 211vector<Biome::MobSpawnerData *> *HellFlatLevelSource::getMobsAt(MobCategory *mobCategory, int x, int y, int z) 212{ 213 Biome *biome = level->getBiome(x, z); 214 if (biome == NULL) 215 { 216 return NULL; 217 } 218 return biome->getMobs(mobCategory); 219} 220 221TilePos *HellFlatLevelSource::findNearestMapFeature(Level *level, const wstring& featureName, int x, int y, int z) 222{ 223 return NULL; 224} 225 226void HellFlatLevelSource::recreateLogicStructuresForChunk(int chunkX, int chunkZ) 227{ 228}