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 "net.minecraft.world.level.levelgen.feature.h"
4#include "net.minecraft.world.h"
5#include "Mushroom.h"
6
7Mushroom::Mushroom(int id) : Bush(id)
8{
9 this->updateDefaultShape();
10 this->setTicking(true);
11}
12
13// 4J Added override
14void Mushroom::updateDefaultShape()
15{
16 float ss = 0.2f;
17 this->setShape(0.5f - ss, 0, 0.5f - ss, 0.5f + ss, ss * 2, 0.5f + ss);
18}
19
20void Mushroom::tick(Level *level, int x, int y, int z, Random *random)
21{
22 if (random->nextInt(25) == 0)
23 {
24 int r = 4;
25 int max = 5;
26 for (int xx = x - r; xx <= x + r; xx++)
27 for (int zz = z - r; zz <= z + r; zz++)
28 for (int yy = y - 1; yy <= y + 1; yy++)
29 {
30 if (level->getTile(xx, yy, zz) == id && --max <= 0) return;
31 }
32
33 int x2 = x + random->nextInt(3) - 1;
34 int y2 = y + random->nextInt(2) - random->nextInt(2);
35 int z2 = z + random->nextInt(3) - 1;
36 for (int i = 0; i < 4; i++)
37 {
38 if (level->isEmptyTile(x2, y2, z2) && canSurvive(level, x2, y2, z2))
39 {
40 x = x2;
41 y = y2;
42 z = z2;
43 }
44 x2 = x + random->nextInt(3) - 1;
45 y2 = y + random->nextInt(2) - random->nextInt(2);
46 z2 = z + random->nextInt(3) - 1;
47 }
48
49 if (level->isEmptyTile(x2, y2, z2) && canSurvive(level, x2, y2, z2))
50 {
51 level->setTileAndData(x2, y2, z2, id, 0, UPDATE_CLIENTS);
52 }
53 }
54}
55
56bool Mushroom::mayPlace(Level *level, int x, int y, int z)
57{
58 return Bush::mayPlace(level, x, y, z) && canSurvive(level, x, y, z);
59}
60
61bool Mushroom::mayPlaceOn(int tile)
62{
63 return Tile::solid[tile];
64}
65
66bool Mushroom::canSurvive(Level *level, int x, int y, int z)
67{
68 if (y < 0 || y >= Level::maxBuildHeight) return false;
69
70 int below = level->getTile(x, y - 1, z);
71
72 return below == Tile::mycel_Id || (level->getDaytimeRawBrightness(x, y, z) < 13 && mayPlaceOn(below));
73}
74
75bool Mushroom::growTree(Level *level, int x, int y, int z, Random *random)
76{
77 int data = level->getData(x, y, z);
78
79 level->removeTile(x, y, z);
80 Feature *f = NULL;
81
82 if (id == Tile::mushroom_brown_Id)
83 {
84 f = new HugeMushroomFeature(0);
85 }
86 else if (id == Tile::mushroom_red_Id)
87 {
88 f = new HugeMushroomFeature(1);
89 }
90
91 if (f == NULL || !f->place(level, random, x, y, z))
92 {
93 level->setTileAndData(x, y, z, id, data, Tile::UPDATE_ALL);
94 if( f != NULL )
95 delete f;
96 return false;
97 }
98 if( f != NULL )
99 delete f;
100 return true;
101}