the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.world.level.h"
3#include "BirchFeature.h"
4#include "net.minecraft.world.level.tile.h"
5
6BirchFeature::BirchFeature(bool doUpdate) : Feature(doUpdate)
7{
8}
9
10bool BirchFeature::place(Level *level, Random *random, int x, int y, int z)
11{
12 int treeHeight = random->nextInt(3) + 5;
13
14 bool free = true;
15 if (y < 1 || y + treeHeight + 1 > Level::maxBuildHeight) return false;
16
17 for (int yy = y; yy <= y + 1 + treeHeight; yy++)
18 {
19 int r = 1;
20 if (yy == y) r = 0;
21 if (yy >= y + 1 + treeHeight - 2) r = 2;
22 for (int xx = x - r; xx <= x + r && free; xx++)
23 {
24 for (int zz = z - r; zz <= z + r && free; zz++)
25 {
26 if (yy >= 0 && yy < Level::maxBuildHeight)
27 {
28 int tt = level->getTile(xx, yy, zz);
29 if (tt != 0 && tt != Tile::leaves_Id) free = false;
30 }
31 else
32 {
33 free = false;
34 }
35 }
36 }
37 }
38
39 if (!free) return false;
40
41 int belowTile = level->getTile(x, y - 1, z);
42 if ((belowTile != Tile::grass_Id && belowTile != Tile::dirt_Id) || y >= Level::maxBuildHeight - treeHeight - 1) return false;
43
44 // 4J Stu Added to stop tree features generating areas previously place by game rule generation
45 if(app.getLevelGenerationOptions() != NULL)
46 {
47 LevelGenerationOptions *levelGenOptions = app.getLevelGenerationOptions();
48 int radius = 3;
49 bool intersects = levelGenOptions->checkIntersects(x - radius, y - 1, z - radius, x + radius, y + treeHeight, z + radius);
50 if(intersects)
51 {
52 //app.DebugPrintf("Skipping reeds feature generation as it overlaps a game rule structure\n");
53 return false;
54 }
55 }
56
57 placeBlock(level, x, y - 1, z, Tile::dirt_Id);
58
59 for (int yy = y - 3 + treeHeight; yy <= y + treeHeight; yy++)
60 {
61 int yo = yy - (y + treeHeight);
62 int offs = 1 - yo / 2;
63 for (int xx = x - offs; xx <= x + offs; xx++)
64 {
65 int xo = xx - (x);
66 for (int zz = z - offs; zz <= z + offs; zz++)
67 {
68 int zo = zz - (z);
69 if (abs(xo) == offs && abs(zo) == offs && (random->nextInt(2) == 0 || yo == 0)) continue;
70 int t = level->getTile(xx, yy, zz);
71 if (t == 0 || t == Tile::leaves_Id) placeBlock(level, xx, yy, zz, Tile::leaves_Id, LeafTile::BIRCH_LEAF);
72 }
73 }
74 }
75 for (int hh = 0; hh < treeHeight; hh++)
76 {
77 int t = level->getTile(x, y + hh, z);
78 if (t == 0 || t == Tile::leaves_Id) placeBlock(level, x, y + hh, z, Tile::treeTrunk_Id, TreeTile::BIRCH_TRUNK);
79 }
80 return true;
81
82}