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