/
WillowGen.java
224 lines (191 loc) · 7.06 KB
/
WillowGen.java
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package mods.natura.worldgen;
import java.util.Random;
import mods.natura.common.NContent;
import mods.natura.common.PHNatura;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
public class WillowGen extends WorldGenerator
{
public final boolean seekHeight;
public WillowGen(boolean notify)
{
super(notify);
seekHeight = !notify;
}
int findGround (World world, int x, int y, int z)
{
int ret = -1;
int height = y;
do
{
Block heightID = world.getBlock(x, height, z);
if ((heightID == Blocks.dirt || heightID == Blocks.grass || heightID == Blocks.sand) && !world.getBlock(x, height + 1, z).isOpaqueCube())
{
ret = height + 1;
break;
}
height--;
} while (height > PHNatura.seaLevel);
return ret;
}
public boolean generate (World world, Random par2Random, int x, int y, int z)
{
if (seekHeight)
{
y = findGround(world, x, y, z);
if (y == -1)
return false;
}
int l;
for (l = par2Random.nextInt(4) + 5; world.getBlock(x, y - 1, z).getMaterial() == Material.water; --y)
{
;
}
boolean flag = true;
if (y >= 1 && y + l + 1 <= 128)
{
int i1;
int j1;
int k1;
Block l1;
for (i1 = y; i1 <= y + 1 + l; ++i1)
{
byte b0 = 1;
if (i1 == y)
{
b0 = 0;
}
if (i1 >= y + 1 + l - 2)
{
b0 = 3;
}
for (j1 = x - b0; j1 <= x + b0 && flag; ++j1)
{
for (k1 = z - b0; k1 <= z + b0 && flag; ++k1)
{
if (i1 >= 0 && i1 < 128)
{
l1 = world.getBlock(j1, i1, k1);
if (l1 != null && !l1.isLeaves(world, j1, i1, k1))
{
if (l1 != Blocks.water)
{
flag = false;
}
else if (i1 > y)
{
flag = false;
}
}
}
else
{
flag = false;
}
}
}
}
if (!flag)
{
return false;
}
else
{
i1 = world.getBlock(x, y - 1, z);
if ((i1 == Blocks.grass || i1 == Blocks.dirt) && y < 128 - l - 1)
{
this.setBlock(world, x, y - 1, z, Blocks.dirt);
int i2;
int j2;
for (j2 = y - 3 + l; j2 <= y + l; ++j2)
{
j1 = j2 - (y + l);
k1 = 2 - j1 / 2;
for (l1 = x - k1; l1 <= x + k1; ++l1)
{
i2 = l1 - x;
for (int k2 = z - k1; k2 <= z + k1; ++k2)
{
int l2 = k2 - z;
Block block = world.getBlock(l1, j2, k2);
if ((Math.abs(i2) != k1 || Math.abs(l2) != k1 || par2Random.nextInt(2) != 0 && j1 != 0) && (block == null || block.canBeReplacedByLeaves(world, l1, j2, k2)))
{
this.setBlockAndMetadata(world, l1, j2, k2, NContent.floraLeavesNoColor, 3);
}
}
}
}
for (j2 = 0; j2 < l; ++j2)
{
Block block = world.getBlock(x, y + j2, z);
if (j1 == 0 || (block != null && block.isLeaves(world, x, y + j2, z)) || block == Blocks.water)
{
world.setBlock(x, y + j2, z, NContent.willow);
}
}
for (j2 = y - 3 + l; j2 <= y + l; ++j2)
{
j1 = j2 - (y + l);
k1 = 2 - j1 / 2;
for (l1 = x - k1; l1 <= x + k1; ++l1)
{
for (i2 = z - k1; i2 <= z + k1; ++i2)
{
Block block = world.getBlock(l1, j2, i2);
if (block != null && block.isLeaves(world, l1, j2, i2))
{
if (par2Random.nextInt(4) == 0 && world.getBlock(l1 - 1, j2, i2) == 0)
{
this.generateVines(world, l1 - 1, j2, i2, 3);
}
if (par2Random.nextInt(4) == 0 && world.getBlock(l1 + 1, j2, i2) == 0)
{
this.generateVines(world, l1 + 1, j2, i2, 3);
}
if (par2Random.nextInt(4) == 0 && world.getBlock(l1, j2, i2 - 1) == 0)
{
this.generateVines(world, l1, j2, i2 - 1, 3);
}
if (par2Random.nextInt(4) == 0 && world.getBlock(l1, j2, i2 + 1) == 0)
{
this.generateVines(world, l1, j2, i2 + 1, 3);
}
}
}
}
}
return true;
}
else
{
return false;
}
}
}
else
{
return false;
}
}
/**
* Generates vines at the given position until it hits a block.
*/
private void generateVines (World par1World, int par2, int par3, int par4, int par5)
{
this.setBlockAndMetadata(par1World, par2, par3, par4, NContent.floraLeavesNoColor, par5);
int i1 = 4;
while (true)
{
--par3;
if (par1World.getBlock(par2, par3, par4) != Blocks.air || i1 <= 0)
{
return;
}
this.setBlockAndMetadata(par1World, par2, par3, par4, NContent.floraLeavesNoColor, par5);
--i1;
}
}
}