the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 328 lines 9.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.levelgen.feature.h" 5#include "net.minecraft.world.level.biome.h" 6 7BiomeDecorator::BiomeDecorator(Biome *biome) 8{ 9 _init(); 10 11 // 4J inits 12 level = NULL; 13 random = NULL; 14 xo = 0; 15 zo = 0; 16 17 this->biome = biome; 18} 19 20void BiomeDecorator::decorate(Level *level, Random *random, int xo, int zo) 21{ 22 if (this->level != NULL) 23 { 24 app.DebugPrintf("BiomeDecorator::decorate - Already decorating!!\n"); 25#ifndef _CONTENT_PACKAGE 26 __debugbreak(); 27 //throw new RuntimeException("Already decorating!!"); 28#endif 29 } 30 this->level = level; 31 this->random = random; 32 this->xo = xo; 33 this->zo = zo; 34 35 decorate(); 36 37 this->level = NULL; 38 this->random = NULL; 39} 40 41 42 43void BiomeDecorator::_init() 44{ 45 clayFeature = new ClayFeature(4); 46 sandFeature = new SandFeature(7, Tile::sand_Id); 47 gravelFeature = new SandFeature(6, Tile::gravel_Id); 48 dirtOreFeature = new OreFeature(Tile::dirt_Id, 32); 49 gravelOreFeature = new OreFeature(Tile::gravel_Id, 32); 50 coalOreFeature = new OreFeature(Tile::coalOre_Id, 16); 51 ironOreFeature = new OreFeature(Tile::ironOre_Id, 8); 52 goldOreFeature = new OreFeature(Tile::goldOre_Id, 8); 53 redStoneOreFeature = new OreFeature(Tile::redStoneOre_Id, 7); 54 diamondOreFeature = new OreFeature(Tile::diamondOre_Id, 7); 55 lapisOreFeature = new OreFeature(Tile::lapisOre_Id, 6); 56 yellowFlowerFeature = new FlowerFeature(Tile::flower_Id); 57 roseFlowerFeature = new FlowerFeature(Tile::rose_Id); 58 brownMushroomFeature = new FlowerFeature(Tile::mushroom_brown_Id); 59 redMushroomFeature = new FlowerFeature(Tile::mushroom_red_Id); 60 hugeMushroomFeature = new HugeMushroomFeature(); 61 reedsFeature = new ReedsFeature(); 62 cactusFeature = new CactusFeature(); 63 waterlilyFeature = new WaterlilyFeature(); 64 65 waterlilyCount = 0; 66 treeCount = 0; 67 flowerCount = 2; 68 grassCount = 1; 69 deadBushCount = 0; 70 mushroomCount = 0; 71 reedsCount = 0; 72 cactusCount = 0; 73 gravelCount = 1; 74 sandCount = 3; 75 clayCount = 1; 76 hugeMushrooms = 0; 77 liquids = true; 78} 79 80 81void BiomeDecorator::decorate() 82{ 83 PIXBeginNamedEvent(0,"Decorate ores"); 84 decorateOres(); 85 PIXEndNamedEvent(); 86 87 PIXBeginNamedEvent(0,"Decorate sand/clay/gravel"); 88 for (int i = 0; i < sandCount; i++) 89 { 90 int x = xo + random->nextInt(16) + 8; 91 int z = zo + random->nextInt(16) + 8; 92 sandFeature->place(level, random, x, level->getTopSolidBlock(x, z), z); 93 } 94 95 for (int i = 0; i < clayCount; i++) 96 { 97 int x = xo + random->nextInt(16) + 8; 98 int z = zo + random->nextInt(16) + 8; 99 clayFeature->place(level, random, x, level->getTopSolidBlock(x, z), z); 100 } 101 102 for (int i = 0; i < gravelCount; i++) 103 { 104 int x = xo + random->nextInt(16) + 8; 105 int z = zo + random->nextInt(16) + 8; 106 sandFeature->place(level, random, x, level->getTopSolidBlock(x, z), z); 107 } 108 PIXEndNamedEvent(); 109 110 PIXBeginNamedEvent(0, "Decorate forests"); 111 int forests = treeCount; 112 if (random->nextInt(10) == 0) forests += 1; 113 114 for (int i = 0; i < forests; i++) 115 { 116 int x = xo + random->nextInt(16) + 8; 117 int z = zo + random->nextInt(16) + 8; 118 Feature *tree = biome->getTreeFeature(random); 119 tree->init(1, 1, 1); 120 tree->place(level, random, x, level->getHeightmap(x, z), z); 121 delete tree; 122 } 123 PIXEndNamedEvent(); 124 125 PIXBeginNamedEvent(0,"Decorate mushrooms/flowers/grass"); 126 for (int i = 0; i < hugeMushrooms; i++) 127 { 128 int x = xo + random->nextInt(16) + 8; 129 int z = zo + random->nextInt(16) + 8; 130 hugeMushroomFeature->place(level, random, x, level->getHeightmap(x, z), z); 131 } 132 133 for (int i = 0; i < flowerCount; i++) 134 { 135 int x = xo + random->nextInt(16) + 8; 136 int y = random->nextInt(Level::genDepth); 137 int z = zo + random->nextInt(16) + 8; 138 yellowFlowerFeature->place(level, random, x, y, z); 139 140 if (random->nextInt(4) == 0) 141 { 142 x = xo + random->nextInt(16) + 8; 143 y = random->nextInt(Level::genDepth); 144 z = zo + random->nextInt(16) + 8; 145 roseFlowerFeature->place(level, random, x, y, z); 146 } 147 } 148 149 for (int i = 0; i < grassCount; i++) 150 { 151 //int grassType = TallGrass::TALL_GRASS; 152 153 int x = xo + random->nextInt(16) + 8; 154 int y = random->nextInt(Level::genDepth); 155 int z = zo + random->nextInt(16) + 8; 156 MemSect(50); 157 Feature *grassFeature = biome->getGrassFeature(random); 158 MemSect(0); 159 grassFeature->place(level, random, x, y, z); 160 delete grassFeature; 161 } 162 PIXEndNamedEvent(); 163 PIXBeginNamedEvent(0,"Decorate bush/waterlily/mushroom/reeds/pumpkins/cactuses"); 164 165 // 4J Stu - For some reason this was created each time round in the loop 166 // I assume there is a case where deadBushCount could be 0 167 DeadBushFeature *deadBushFeature = NULL; 168 if(deadBushCount > 0) deadBushFeature = new DeadBushFeature(Tile::deadBush_Id); 169 for (int i = 0; i < deadBushCount; i++) 170 { 171 int x = xo + random->nextInt(16) + 8; 172 int y = random->nextInt(Level::genDepth); 173 int z = zo + random->nextInt(16) + 8; 174 //new DeadBushFeature(Tile::deadBush_Id)->place(level, random, x, y, z); 175 deadBushFeature->place(level, random, x, y, z); 176 } 177 if(deadBushFeature != NULL)delete deadBushFeature; 178 179 for (int i = 0; i < waterlilyCount; i++) 180 { 181 int x = xo + random->nextInt(16) + 8; 182 int z = zo + random->nextInt(16) + 8; 183 int y = random->nextInt(Level::genDepth); 184 while (y > 0 && level->getTile(x, y - 1, z) == 0) 185 y--; 186 waterlilyFeature->place(level, random, x, y, z); 187 } 188 189 for (int i = 0; i < mushroomCount; i++) 190 { 191 if (random->nextInt(4) == 0) 192 { 193 int x = xo + random->nextInt(16) + 8; 194 int z = zo + random->nextInt(16) + 8; 195 int y = level->getHeightmap(x, z); 196 brownMushroomFeature->place(level, random, x, y, z); 197 } 198 199 if (random->nextInt(8) == 0) 200 { 201 int x = xo + random->nextInt(16) + 8; 202 int z = zo + random->nextInt(16) + 8; 203 int y = random->nextInt(Level::genDepth); 204 redMushroomFeature->place(level, random, x, y, z); 205 } 206 } 207 208 if (random->nextInt(4) == 0) 209 { 210 int x = xo + random->nextInt(16) + 8; 211 int y = random->nextInt(Level::genDepth); 212 int z = zo + random->nextInt(16) + 8; 213 brownMushroomFeature->place(level, random, x, y, z); 214 } 215 216 if (random->nextInt(8) == 0) 217 { 218 int x = xo + random->nextInt(16) + 8; 219 int y = random->nextInt(Level::genDepth); 220 int z = zo + random->nextInt(16) + 8; 221 redMushroomFeature->place(level, random, x, y, z); 222 } 223 224 for (int i = 0; i < reedsCount; i++) 225 { 226 int x = xo + random->nextInt(16) + 8; 227 int z = zo + random->nextInt(16) + 8; 228 int y = random->nextInt(Level::genDepth); 229 reedsFeature->place(level, random, x, y, z); 230 } 231 232 for (int i = 0; i < 10; i++) 233 { 234 int x = xo + random->nextInt(16) + 8; 235 int y = random->nextInt(Level::genDepth); 236 int z = zo + random->nextInt(16) + 8; 237 reedsFeature->place(level, random, x, y, z); 238 } 239 240 if (random->nextInt(32) == 0) 241 { 242 int x = xo + random->nextInt(16) + 8; 243 int y = random->nextInt(Level::genDepth); 244 int z = zo + random->nextInt(16) + 8; 245 PumpkinFeature *pumpkinFeature = new PumpkinFeature(); 246 pumpkinFeature->place(level, random, x, y, z); 247 delete pumpkinFeature; 248 } 249 250 for (int i = 0; i < cactusCount; i++) 251 { 252 int x = xo + random->nextInt(16) + 8; 253 int y = random->nextInt(Level::genDepth); 254 int z = zo + random->nextInt(16) + 8; 255 cactusFeature->place(level, random, x, y, z); 256 } 257 258 259 PIXEndNamedEvent(); 260 PIXBeginNamedEvent(0,"Decorate liquids"); 261 262 if( liquids ) 263 { 264 // 4J Stu - For some reason this was created each time round in the loop 265 SpringFeature *waterSpringFeature = new SpringFeature(Tile::water_Id); 266 for (int i = 0; i < 50; i++) 267 { 268 int x = xo + random->nextInt(16) + 8; 269 int y = random->nextInt(random->nextInt(Level::genDepth - 8) + 8); 270 int z = zo + random->nextInt(16) + 8; 271 waterSpringFeature->place(level, random, x, y, z); 272 } 273 delete waterSpringFeature; 274 275 // 4J Stu - For some reason this was created each time round in the loop 276 SpringFeature *lavaSpringFeature = new SpringFeature(Tile::lava_Id); 277 for (int i = 0; i < 20; i++) 278 { 279 int x = xo + random->nextInt(16) + 8; 280 int y = random->nextInt(random->nextInt(random->nextInt(Level::genDepth - 16) + 8) + 8); 281 int z = zo + random->nextInt(16) + 8; 282 lavaSpringFeature->place(level, random, x, y, z); 283 } 284 delete lavaSpringFeature; 285 } 286 PIXEndNamedEvent(); 287} 288 289void BiomeDecorator::decorate(int count, Feature *feature) 290{ 291 decorateDepthSpan(count, feature, 0, Level::genDepth); 292} 293 294void BiomeDecorator::decorateDepthSpan(int count, Feature *feature, int y0, int y1) 295{ 296 for (int i = 0; i < count; i++) 297 { 298 int x = xo + random->nextInt(16); 299 int y = random->nextInt(y1 - y0) + y0; 300 int z = zo + random->nextInt(16); 301 feature->place(level, random, x, y, z); 302 } 303} 304 305void BiomeDecorator::decorateDepthAverage(int count, Feature *feature, int yMid, int ySpan) 306{ 307 for (int i = 0; i < count; i++) 308 { 309 int x = xo + random->nextInt(16); 310 int y = random->nextInt(ySpan) + random->nextInt(ySpan) + (yMid - ySpan); 311 int z = zo + random->nextInt(16); 312 feature->place(level, random, x, y, z); 313 } 314} 315 316void BiomeDecorator::decorateOres() 317{ 318 level->setInstaTick(true); // 4J - optimisation 319 decorateDepthSpan(20, dirtOreFeature, 0, Level::genDepth); 320 decorateDepthSpan(10, gravelOreFeature, 0, Level::genDepth); 321 decorateDepthSpan(20, coalOreFeature, 0, Level::genDepth); 322 decorateDepthSpan(20, ironOreFeature, 0, Level::genDepth / 2); 323 decorateDepthSpan(2, goldOreFeature, 0, Level::genDepth / 4); 324 decorateDepthSpan(8, redStoneOreFeature, 0, Level::genDepth / 8); 325 decorateDepthSpan(1, diamondOreFeature, 0, Level::genDepth / 8); 326 decorateDepthAverage(1, lapisOreFeature, Level::genDepth / 8, Level::genDepth / 8); 327 level->setInstaTick(false); 328}