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 "HouseFeature.h"
4#include "net.minecraft.world.level.tile.h"
5#include "net.minecraft.world.entity.monster.h"
6#include "net.minecraft.world.item.h"
7
8bool HouseFeature::place(Level *level, Random *random, int x, int y, int z)
9{
10 while (y > 0 && !level->getMaterial(x, y - 1, z)->blocksMotion())
11 y--;
12
13 int w = random->nextInt(7) + 7;
14 int h = 4 + random->nextInt(3) / 2;
15 int d = random->nextInt(7) + 7;
16
17 int x0 = x - w / 2;
18 int y0 = y;
19 int z0 = z - d / 2;
20
21 int doorSide = random->nextInt(4);
22 if (doorSide < 2) d += 2;
23 else w += 2;
24
25 for (int xx = x0; xx < x0 + w; xx++)
26 {
27 for (int zz = z0; zz < z0 + d; zz++)
28 {
29 Material *m = level->getMaterial(xx, y - 1, zz);
30 if (!m->blocksMotion() || m == Material::ice) return false;
31
32 bool ok = false;
33 if (doorSide == 0 && xx < x0 + 2) ok = true;
34 if (doorSide == 1 && xx > x0 + w - 1 - 2) ok = true;
35 if (doorSide == 2 && zz < z0 + 2) ok = true;
36 if (doorSide == 3 && zz > z0 + d - 1 - 2) ok = true;
37 int t = level->getTile(xx, y, zz);
38 if (ok)
39 {
40 if (t != 0) return false;
41 }
42 else
43 {
44 if (t == Tile::cobblestone_Id || t == Tile::mossyCobblestone_Id) return false;
45 }
46
47 }
48 }
49
50 if (doorSide == 0)
51 {
52 x0++;
53 w--;
54 }
55 else if (doorSide == 1)
56 {
57 w--;
58 }
59 else if (doorSide == 2)
60 {
61 z0++;
62 d--;
63 }
64 else if (doorSide == 3)
65 {
66 d--;
67 }
68
69 int xx0 = x0;
70 int xx1 = x0 + w - 1;
71 int zz0 = z0;
72 int zz1 = z0 + d - 1;
73 if (doorSide >= 2)
74 {
75 xx0++;
76 xx1--;
77 }
78 else
79 {
80 zz0++;
81 zz1--;
82 }
83 for (int xx = x0; xx < x0 + w; xx++)
84 {
85 for (int zz = z0; zz < z0 + d; zz++)
86 {
87 int ho = h;
88
89 int d1 = zz - z0;
90 int d2 = (z0 + d - 1) - zz;
91 if (doorSide < 2)
92 {
93 d1 = xx - x0;
94 d2 = (x0 + w - 1) - xx;
95 }
96
97 if (d2 < d1) d1 = d2;
98 h += d1;
99 for (int yy = y0 - 1; yy < y0 + h; yy++)
100 {
101 int material = -1;
102 if (yy == y0 + h - 1)
103 {
104 material = Tile::wood_Id;
105 }
106 else if (xx >= xx0 && xx <= xx1 && zz >= zz0 && zz <= zz1)
107 {
108 material = 0;
109 if (yy == y0 - 1 || yy == y0 + h - 1 || xx == xx0 || zz == zz0 || xx == xx1 || zz == zz1)
110 {
111 if (yy <= y0 + random->nextInt(3)) material = Tile::mossyCobblestone_Id;
112 else material = Tile::cobblestone_Id;
113 }
114 }
115
116 if (material >= 0)
117 {
118 level->setTileAndData(xx, yy, zz, material, 0, Tile::UPDATE_CLIENTS);
119 }
120 }
121 h = ho;
122 }
123 }
124 {
125 int xx = x0 + random->nextInt(w - 4) + 2;
126 int zz = z0 + random->nextInt(d - 4) + 2;
127 if (doorSide == 0) xx = x0;
128 if (doorSide == 1) xx = x0 + w - 1;
129 if (doorSide == 2) zz = z0;
130 if (doorSide == 3) zz = z0 + d - 1;
131 level->setTileAndData(xx, y0, zz, 0, 0, Tile::UPDATE_CLIENTS);
132 level->setTileAndData(xx, y0 + 1, zz, 0, 0, Tile::UPDATE_CLIENTS);
133
134 int dir = 0;
135 if (doorSide == 0) dir = 0;
136 if (doorSide == 2) dir = 1;
137 if (doorSide == 1) dir = 2;
138 if (doorSide == 3) dir = 3;
139
140 DoorItem::place(level, xx, y0, zz, dir, Tile::door_wood);
141 }
142
143 for (int i = 0; i < (w * 2 + d * 2) * 3; i++)
144 {
145 int xx = x0 + random->nextInt(w - 4) + 2;
146 int zz = z0 + random->nextInt(d - 4) + 2;
147 int side = random->nextInt(4);
148
149 if (side == 0) xx = xx0;
150 if (side == 1) xx = xx1;
151 if (side == 2) zz = zz0;
152 if (side == 3) zz = zz1;
153
154 if (level->isSolidBlockingTile(xx, y0 + 1, zz))
155 {
156 int count = 0;
157 if (level->isSolidBlockingTile(xx - 1, y0 + 1, zz) && level->isSolidBlockingTile(xx + 1, y0 + 1, zz)) count++;
158 if (level->isSolidBlockingTile(xx, y0 + 1, zz - 1) && level->isSolidBlockingTile(xx, y0 + 1, zz + 1)) count++;
159 if (count == 1)
160 {
161 level->setTileAndData(xx, y0 + 1, zz, Tile::glass_Id, 0, Tile::UPDATE_CLIENTS);
162 }
163 }
164 }
165
166 int ww = xx1 - xx0;
167 int dd = zz1 - zz0;
168 for (int i = 0; i < (ww * 2 + dd * 2); i++)
169 {
170 int xx = xx0 + random->nextInt(ww - 1) + 1;
171 int zz = zz0 + random->nextInt(dd - 1) + 1;
172 int yy = y0;
173
174 if (level->getTile(xx, yy + 2, zz) == 0)
175 {
176 int count = 0;
177 if (level->isSolidBlockingTile(xx - 1, yy + 2, zz)) count++;
178 if (level->isSolidBlockingTile(xx + 1, yy + 2, zz)) count++;
179 if (level->isSolidBlockingTile(xx, yy + 2, zz - 1)) count++;
180 if (level->isSolidBlockingTile(xx, yy + 2, zz + 1)) count++;
181 if (count == 1)
182 {
183 level->setTileAndData(xx, y0 + 2, zz, Tile::torch_Id, 0, Tile::UPDATE_CLIENTS);
184 }
185 }
186 }
187
188 shared_ptr<PigZombie>(pz) = shared_ptr<PigZombie>(new PigZombie(level));
189 pz->moveTo(x0 + w / 2.0 + 0.5, y0 + 0.5, z0 + d / 2.0 + 0.5, 0, 0);
190 level->addEntity(pz);
191
192 return true;
193
194}