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 "HugeMushroomFeature.h"
3#include "net.minecraft.world.level.h"
4#include "net.minecraft.world.level.tile.h"
5
6HugeMushroomFeature::HugeMushroomFeature(int forcedType) : Feature(true)
7{
8 this->forcedType = forcedType;
9}
10
11HugeMushroomFeature::HugeMushroomFeature() : Feature(false)
12{
13 this->forcedType = -1;
14}
15
16bool HugeMushroomFeature::place(Level *level, Random *random, int x, int y, int z)
17{
18 int type = random->nextInt(2);
19 if (forcedType >= 0) type = forcedType;
20
21 int treeHeight = random->nextInt(3) + 4;
22
23 bool free = true;
24 if (y < 1 || y + treeHeight + 1 >= Level::maxBuildHeight) return false;
25
26 for (int yy = y; yy <= y + 1 + treeHeight; yy++)
27 {
28 int r = 3;
29 if (yy <= (y + 3) ) r = 0;
30 for (int xx = x - r; xx <= x + r && free; xx++)
31 {
32 for (int zz = z - r; zz <= z + r && free; zz++)
33 {
34 if (yy >= 0 && yy < Level::maxBuildHeight)
35 {
36 int tt = level->getTile(xx, yy, zz);
37 if (tt != 0 && tt != Tile::leaves_Id)
38 {
39 free = false;
40 }
41 }
42 else
43 {
44 free = false;
45 }
46 }
47 }
48 }
49
50 int belowTile = level->getTile(x, y - 1, z);
51 if (belowTile != Tile::dirt_Id && belowTile != Tile::grass_Id && belowTile != Tile::mycel_Id)
52 {
53 return false;
54 }
55
56 if (!free) return false;
57
58 int low = y + treeHeight;
59 if (type == 1) {
60 low = y + treeHeight - 3;
61 }
62 for (int yy = low; yy <= y + treeHeight; yy++)
63 {
64 int offs = 1;
65 if (yy < y + treeHeight) offs += 1;
66 if (type == 0) offs = 3;
67 for (int xx = x - offs; xx <= x + offs; xx++)
68 {
69 for (int zz = z - offs; zz <= z + offs; zz++)
70 {
71 int data = 5;
72 if (xx == x - offs) data--;
73 if (xx == x + offs) data++;
74 if (zz == z - offs) data -= 3;
75 if (zz == z + offs) data += 3;
76
77 if (type == 0 || yy < y + treeHeight)
78 {
79 if ((xx == x - offs || xx == x + offs) && (zz == z - offs || zz == z + offs)) continue;
80 if (xx == x - (offs - 1) && zz == z - offs) data = 1;
81 if (xx == x - offs && zz == z - (offs - 1)) data = 1;
82
83 if (xx == x + (offs - 1) && zz == z - offs) data = 3;
84 if (xx == x + offs && zz == z - (offs - 1)) data = 3;
85
86 if (xx == x - (offs - 1) && zz == z + offs) data = 7;
87 if (xx == x - offs && zz == z + (offs - 1)) data = 7;
88
89 if (xx == x + (offs - 1) && zz == z + offs) data = 9;
90 if (xx == x + offs && zz == z + (offs - 1)) data = 9;
91 }
92
93 if (data == 5 && yy < y + treeHeight) data = 0;
94 if (data != 0 || y >= y + treeHeight - 1)
95 {
96 if (!Tile::solid[level->getTile(xx, yy, zz)]) placeBlock(level, xx, yy, zz, Tile::hugeMushroom_brown_Id + type, data);
97 }
98 }
99 }
100 }
101 for (int hh = 0; hh < treeHeight; hh++)
102 {
103 int t = level->getTile(x, y + hh, z);
104 if (!Tile::solid[t]) placeBlock(level, x, y + hh, z, Tile::hugeMushroom_brown_Id + type, 10);
105 }
106 return true;
107}