the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 132 lines 3.7 kB view raw
1#include "stdafx.h" 2#include "SwampTreeFeature.h" 3#include "net.minecraft.world.level.h" 4#include "net.minecraft.world.level.tile.h" 5#include "JavaMath.h" 6 7bool SwampTreeFeature::place(Level *level, Random *random, int x, int y, int z) 8{ 9 int treeHeight = random->nextInt(4) + 5; 10 while (level->getMaterial(x, y - 1, z) == Material::water) 11 y--; 12 13 bool free = true; 14 if (y < 1 || y + treeHeight + 1 > Level::genDepth) return false; 15 16 // 4J Stu Added to stop tree features generating areas previously place by game rule generation 17 if(app.getLevelGenerationOptions() != NULL) 18 { 19 LevelGenerationOptions *levelGenOptions = app.getLevelGenerationOptions(); 20 bool intersects = levelGenOptions->checkIntersects(x - 3, y - 1, z - 3, x + 3, y + treeHeight, z + 3); 21 if(intersects) 22 { 23 //app.DebugPrintf("Skipping reeds feature generation as it overlaps a game rule structure\n"); 24 return false; 25 } 26 } 27 28 for (int yy = y; yy <= y + 1 + treeHeight; yy++) 29 { 30 int r = 1; 31 if (yy == y) r = 0; 32 if (yy >= y + 1 + treeHeight - 2) r = 3; 33 for (int xx = x - r; xx <= x + r && free; xx++) 34 { 35 for (int zz = z - r; zz <= z + r && free; zz++) 36 { 37 if (yy >= 0 && yy < Level::genDepth) 38 { 39 int tt = level->getTile(xx, yy, zz); 40 if (tt != 0 && tt != Tile::leaves_Id) 41 { 42 if (tt == Tile::calmWater_Id || tt == Tile::water_Id) 43 { 44 if (yy > y) free = false; 45 } 46 else 47 { 48 free = false; 49 } 50 } 51 } 52 else 53 { 54 free = false; 55 } 56 } 57 } 58 } 59 60 if (!free) return false; 61 62 int belowTile = level->getTile(x, y - 1, z); 63 if ((belowTile != Tile::grass_Id && belowTile != Tile::dirt_Id) || y >= Level::genDepth - treeHeight - 1) return false; 64 65 placeBlock(level, x, y - 1, z, Tile::dirt_Id); 66 67 for (int yy = y - 3 + treeHeight; yy <= y + treeHeight; yy++) 68 { 69 int yo = yy - (y + treeHeight); 70 int offs = 2 - yo / 2; 71 for (int xx = x - offs; xx <= x + offs; xx++) 72 { 73 int xo = xx - (x); 74 for (int zz = z - offs; zz <= z + offs; zz++) 75 { 76 int zo = zz - (z); 77 if (abs(xo) == offs && abs(zo) == offs && (random->nextInt(2) == 0 || yo == 0)) continue; 78 if (!Tile::solid[level->getTile(xx, yy, zz)]) placeBlock(level, xx, yy, zz, Tile::leaves_Id); 79 } 80 } 81 } 82 83 for (int hh = 0; hh < treeHeight; hh++) 84 { 85 int t = level->getTile(x, y + hh, z); 86 if (t == 0 || t == Tile::leaves_Id || t == Tile::water_Id || t == Tile::calmWater_Id) placeBlock(level, x, y + hh, z, Tile::treeTrunk_Id); 87 } 88 89 for (int yy = y - 3 + treeHeight; yy <= y + treeHeight; yy++) 90 { 91 int yo = yy - (y + treeHeight); 92 int offs = 2 - yo / 2; 93 for (int xx = x - offs; xx <= x + offs; xx++) 94 { 95 for (int zz = z - offs; zz <= z + offs; zz++) 96 { 97 if (level->getTile(xx, yy, zz) == Tile::leaves_Id) 98 { 99 if (random->nextInt(4) == 0 && level->getTile(xx - 1, yy, zz) == 0) 100 { 101 addVine(level, xx - 1, yy, zz, VineTile::VINE_EAST); 102 } 103 if (random->nextInt(4) == 0 && level->getTile(xx + 1, yy, zz) == 0) 104 { 105 addVine(level, xx + 1, yy, zz, VineTile::VINE_WEST); 106 } 107 if (random->nextInt(4) == 0 && level->getTile(xx, yy, zz - 1) == 0) 108 { 109 addVine(level, xx, yy, zz - 1, VineTile::VINE_SOUTH); 110 } 111 if (random->nextInt(4) == 0 && level->getTile(xx, yy, zz + 1) == 0) 112 { 113 addVine(level, xx, yy, zz + 1, VineTile::VINE_NORTH); 114 } 115 } 116 } 117 } 118 } 119 return true; 120 121} 122 123void SwampTreeFeature::addVine(Level *level, int xx, int yy, int zz, int dir) 124{ 125 placeBlock(level, xx, yy, zz, Tile::vine_Id, dir); 126 int maxDir = 4; 127 while (level->getTile(xx, --yy, zz) == 0 && maxDir > 0) 128 { 129 placeBlock(level, xx, yy, zz, Tile::vine_Id, dir); 130 maxDir--; 131 } 132}