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