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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
package net.minecraft.server;
import java.util.Random;
// CraftBukkit start
import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.material.MaterialData;
// CraftBukkit end
public class WorldGenHugeMushroom extends WorldGenerator {
private int a = -1;
public WorldGenHugeMushroom(int i) {
this.a = i;
}
public WorldGenHugeMushroom() {}
// CraftBukkit start - delegate to grow()
public boolean a(World world, Random random, int i, int j, int k) {
return grow(world, random, i, j, k, null, null, null);
}
public boolean grow(World world, Random random, int i, int j, int k, StructureGrowEvent event, ItemStack itemstack, CraftWorld bukkitWorld) {
// CraftBukkit end
int l = random.nextInt(2);
if (this.a >= 0) {
l = this.a;
}
int i1 = random.nextInt(3) + 4;
boolean flag = true;
if (j >= 1 && j + i1 + 1 <= world.height) {
int j1;
int k1;
int l1;
int i2;
for (j1 = j; j1 <= j + 1 + i1; ++j1) {
byte b0 = 3;
if (j1 == j) {
b0 = 0;
}
for (k1 = i - b0; k1 <= i + b0 && flag; ++k1) {
for (l1 = k - b0; l1 <= k + b0 && flag; ++l1) {
if (j1 >= 0 && j1 < world.height) {
i2 = world.getTypeId(k1, j1, l1);
if (i2 != 0 && i2 != Block.LEAVES.id) {
flag = false;
}
} else {
flag = false;
}
}
}
}
if (!flag) {
return false;
} else {
j1 = world.getTypeId(i, j - 1, k);
if (j1 != Block.DIRT.id && j1 != Block.GRASS.id && j1 != Block.MYCEL.id) {
return false;
} else if (!Block.BROWN_MUSHROOM.canPlace(world, i, j, k)) {
return false;
} else {
// CraftBukkit start
if (event == null) {
world.setRawTypeId(i, j - 1, k, Block.DIRT.id);
} else {
BlockState dirtState = bukkitWorld.getBlockAt(i, j - 1, k).getState();
dirtState.setTypeId(Block.DIRT.id);
event.getBlocks().add(dirtState);
}
// CraftBukkit end
int j2 = j + i1;
if (l == 1) {
j2 = j + i1 - 3;
}
for (k1 = j2; k1 <= j + i1; ++k1) {
l1 = 1;
if (k1 < j + i1) {
++l1;
}
if (l == 0) {
l1 = 3;
}
for (i2 = i - l1; i2 <= i + l1; ++i2) {
for (int k2 = k - l1; k2 <= k + l1; ++k2) {
int l2 = 5;
if (i2 == i - l1) {
--l2;
}
if (i2 == i + l1) {
++l2;
}
if (k2 == k - l1) {
l2 -= 3;
}
if (k2 == k + l1) {
l2 += 3;
}
if (l == 0 || k1 < j + i1) {
if ((i2 == i - l1 || i2 == i + l1) && (k2 == k - l1 || k2 == k + l1)) {
continue;
}
if (i2 == i - (l1 - 1) && k2 == k - l1) {
l2 = 1;
}
if (i2 == i - l1 && k2 == k - (l1 - 1)) {
l2 = 1;
}
if (i2 == i + (l1 - 1) && k2 == k - l1) {
l2 = 3;
}
if (i2 == i + l1 && k2 == k - (l1 - 1)) {
l2 = 3;
}
if (i2 == i - (l1 - 1) && k2 == k + l1) {
l2 = 7;
}
if (i2 == i - l1 && k2 == k + (l1 - 1)) {
l2 = 7;
}
if (i2 == i + (l1 - 1) && k2 == k + l1) {
l2 = 9;
}
if (i2 == i + l1 && k2 == k + (l1 - 1)) {
l2 = 9;
}
}
if (l2 == 5 && k1 < j + i1) {
l2 = 0;
}
if ((l2 != 0 || j >= j + i1 - 1) && !Block.o[world.getTypeId(i2, k1, k2)]) {
// CraftBukkit start
if (event == null) {
world.setRawTypeIdAndData(i2, k1, k2, Block.BIG_MUSHROOM_1.id + l, l2);
} else {
BlockState state = bukkitWorld.getBlockAt(i2, k1, k2).getState();
state.setTypeId(Block.BIG_MUSHROOM_1.id + l);
state.setData(new MaterialData(Block.BIG_MUSHROOM_1.id + l, (byte) l2));
event.getBlocks().add(state);
}
// CraftBukkit end
}
}
}
}
for (k1 = 0; k1 < i1; ++k1) {
l1 = world.getTypeId(i, j + k1, k);
if (!Block.o[l1]) {
// CraftBukkit start
if (event == null) {
world.setRawTypeIdAndData(i, j + k1, k, Block.BIG_MUSHROOM_1.id + l, 10);
} else {
BlockState state = bukkitWorld.getBlockAt(i, j + k1, k).getState();
state.setTypeId(Block.BIG_MUSHROOM_1.id + l);
state.setData(new MaterialData(Block.BIG_MUSHROOM_1.id + l, (byte) 10));
event.getBlocks().add(state);
}
// CraftBukkit end
}
}
// CraftBukkit start
if (event != null) {
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
for (BlockState state : event.getBlocks()) {
state.update(true);
}
}
}
// CraftBukkit end
return true;
}
}
} else {
return false;
}
}
}
|