the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 116 lines 3.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 "SpruceFeature.h" 5 6SpruceFeature::SpruceFeature(bool doUpdate) : Feature(doUpdate) 7{ 8} 9 10bool SpruceFeature::place(Level *level, Random *random, int x, int y, int z) 11{ 12 // pines can be quite tall 13 int treeHeight = random->nextInt(4) + 6; 14 int trunkHeight = 1 + random->nextInt(2); 15 int topHeight = treeHeight - trunkHeight; 16 int leafRadius = 2 + random->nextInt(2); 17 18 bool free = true; 19 // may not be outside of y boundaries 20 if (y < 1 || y + treeHeight + 1 > Level::maxBuildHeight) 21 { 22 return false; 23 } 24 25 // 4J Stu Added to stop tree features generating areas previously place by game rule generation 26 if(app.getLevelGenerationOptions() != NULL) 27 { 28 LevelGenerationOptions *levelGenOptions = app.getLevelGenerationOptions(); 29 bool intersects = levelGenOptions->checkIntersects(x - leafRadius, y - 1, z - leafRadius, x + leafRadius, y + treeHeight, z + leafRadius); 30 if(intersects) 31 { 32 //app.DebugPrintf("Skipping reeds feature generation as it overlaps a game rule structure\n"); 33 return false; 34 } 35 } 36 37 // make sure there is enough space 38 for (int yy = y; yy <= y + 1 + treeHeight && free; yy++) 39 { 40 int r = 1; 41 if ((yy - y) < trunkHeight) 42 { 43 r = 0; 44 } 45 else 46 { 47 r = leafRadius; 48 } 49 for (int xx = x - r; xx <= x + r && free; xx++) 50 { 51 for (int zz = z - r; zz <= z + r && free; zz++) 52 { 53 if (yy >= 0 && yy < Level::maxBuildHeight) 54 { 55 int tt = level->getTile(xx, yy, zz); 56 if (tt != 0 && tt != Tile::leaves_Id) free = false; 57 } 58 else 59 { 60 free = false; 61 } 62 } 63 } 64 } 65 66 if (!free) return false; 67 68 // must stand on ground 69 int belowTile = level->getTile(x, y - 1, z); 70 if ((belowTile != Tile::grass_Id && belowTile != Tile::dirt_Id) || y >= Level::maxBuildHeight - treeHeight - 1) return false; 71 72 placeBlock(level, x, y - 1, z, Tile::dirt_Id); 73 74 // place leaf top 75 int currentRadius = random->nextInt(2); 76 int maxRadius = 1; 77 int minRadius = 0; 78 for (int heightPos = 0; heightPos <= topHeight; heightPos++) 79 { 80 81 const int yy = y + treeHeight - heightPos; 82 83 for (int xx = x - currentRadius; xx <= x + currentRadius; xx++) 84 { 85 int xo = xx - (x); 86 for (int zz = z - currentRadius; zz <= z + currentRadius; zz++) 87 { 88 int zo = zz - (z); 89 if (abs(xo) == currentRadius && abs(zo) == currentRadius && currentRadius > 0) continue; 90 if (!Tile::solid[level->getTile(xx, yy, zz)]) placeBlock(level, xx, yy, zz, Tile::leaves_Id, LeafTile::EVERGREEN_LEAF); 91 } 92 } 93 94 if (currentRadius >= maxRadius) 95 { 96 currentRadius = minRadius; 97 minRadius = 1; 98 maxRadius += 1; 99 if (maxRadius > leafRadius) 100 { 101 maxRadius = leafRadius; 102 } 103 } 104 else 105 { 106 currentRadius = currentRadius + 1; 107 } 108 } 109 int topOffset = random->nextInt(3); 110 for (int hh = 0; hh < treeHeight - topOffset; hh++) 111 { 112 int t = level->getTile(x, y + hh, z); 113 if (t == 0 || t == Tile::leaves_Id) placeBlock(level, x, y + hh, z, Tile::treeTrunk_Id, TreeTile::DARK_TRUNK); 114 } 115 return true; 116}