/
BushTreeGen.java
213 lines (174 loc) · 7.58 KB
/
BushTreeGen.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
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.init.Blocks;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
public class BushTreeGen extends WorldGenerator
{
/** The base height of the tree */
private final int baseHeight;
/** Sets the metadata for the wood blocks used */
private final int woodMetadata;
/** Sets the metadata for the leaves used in huge trees */
private final int leavesMetadata;
public BushTreeGen(boolean par1, int height, int mdwood, int mdleaves)
{
super(par1);
this.baseHeight = height;
this.woodMetadata = mdwood;
this.leavesMetadata = mdleaves;
}
int findGround (World world, int x, int y, int z)
{
boolean foundGround = false;
int height = PHNatura.seaLevel + 64;
do
{
height--;
Block underID = world.getBlock(x, height, z);
if (underID == Blocks.dirt || underID == Blocks.grass || height < PHNatura.seaLevel)
foundGround = true;
} while (!foundGround);
return height + 1;
}
@Override
public boolean generate (World world, Random random, int x, int y, int z)
{
int var6 = random.nextInt(3) + this.baseHeight;
boolean var7 = true;
y = findGround(world, x, y, z);
if (y >= 1 && y + var6 + 1 <= 256)
{
int var8;
int var10;
int var11;
int var12;
for (var8 = y; var8 <= y + 1 + var6; ++var8)
{
byte var9 = 2;
if (var8 == y)
{
var9 = 1;
}
if (var8 >= y + 1 + var6 - 2)
{
var9 = 2;
}
for (var10 = x - var9; var10 <= x + var9 && var7; ++var10)
{
for (var11 = z - var9; var11 <= z + var9 && var7; ++var11)
{
if (var8 >= 0 && var8 < 256)
{
Block block12 = world.getBlock(var10, var8, var11);
if (!this.isReplaceable(world, var10, var8, var11))
{
var7 = true;
}
}
else
{
var7 = false;
}
}
}
}
if (!var7)
{
return false;
}
else
{
Block b8 = world.getBlock(x, y - 1, z);
if ((b8 == Blocks.grass || b8 == Blocks.dirt) && y < 256 - var6 - 1)
{
setBlockAndNotifyAdequately(world, x, y - 1, z, Blocks.dirt, 0);
setBlockAndNotifyAdequately(world, x + 1, y - 1, z, Blocks.dirt, 0);
setBlockAndNotifyAdequately(world, x, y - 1, z + 1, Blocks.dirt, 0);
setBlockAndNotifyAdequately(world, x + 1, y - 1, z + 1, Blocks.dirt, 0);
this.growLogs(world, x, y, z);
this.growLeaves(world, x, z, y + var6, 2, random);
for (var10 = 0; var10 < var6; ++var10)
{
b8 = world.getBlock(x, y + var10, z);
if (b8 == Blocks.air || b8 == null || b8.isLeaves(world, x, y + var10, z))
{
world.setBlock(x, y + var10, z, NContent.tree, this.woodMetadata, 0);
}
if (var10 < var6 - 1)
{
b8 = world.getBlock(x + 1, y + var10, z);
if (b8 == Blocks.air || b8 == null || b8.isLeaves(world, x + 1, y + var10, z))
{
world.setBlock(x + 1, y + var10, z, NContent.tree, this.woodMetadata, 0);
}
b8 = world.getBlock(x + 1, y + var10, z + 1);
if (b8 == Blocks.air || b8 == null || b8.isLeaves(world, x + 1, y + var10, z + 1))
{
world.setBlock(x + 1, y + var10, z + 1, NContent.tree, this.woodMetadata, 0);
}
b8 = world.getBlock(x, y + var10, z + 1);
if (b8 == Blocks.air || b8 == null || b8.isLeaves(world, x, y + var10, z + 1))
{
world.setBlock(x, y + var10, z + 1, NContent.tree, this.woodMetadata, 0);
}
}
}
return true;
}
else
{
return false;
}
}
}
else
{
return false;
}
}
private void growLeaves (World par1World, int par2, int par3, int par4, int par5, Random par6Random)
{
byte var7 = 2;
for (int var8 = par4 - var7; var8 <= par4; ++var8)
{
int var9 = var8 - par4;
int var10 = par5 + 1 - var9;
for (int var11 = par2 - var10; var11 <= par2 + var10 + 1; ++var11)
{
int var12 = var11 - par2;
for (int var13 = par3 - var10; var13 <= par3 + var10 + 1; ++var13)
{
int var14 = var13 - par3;
Block block = par1World.getBlock(var11, var8, var13);
if ((var12 >= 0 || var14 >= 0 || var12 * var12 + var14 * var14 <= var10 * var10) && (var12 <= 0 && var14 <= 0 || var12 * var12 + var14 * var14 <= (var10 + 1) * (var10 + 1))
&& (par6Random.nextInt(4) != 0 || var12 * var12 + var14 * var14 <= (var10 - 1) * (var10 - 1))
&& (block == null || block.canBeReplacedByLeaves(par1World, var11, var8, var13)))
{
this.setBlockAndNotifyAdequately(par1World, var11, var8, var13, NContent.floraLeaves, this.leavesMetadata);
}
}
}
}
}
private void growLogs (World world, int x, int y, int z)
{
setBlockAndNotifyAdequately(world, x, y, z, NContent.tree, this.woodMetadata);
setBlockAndNotifyAdequately(world, x + 1, y, z, NContent.tree, this.woodMetadata);
setBlockAndNotifyAdequately(world, x, y, z + 1, NContent.tree, this.woodMetadata);
setBlockAndNotifyAdequately(world, x + 1, y, z + 1, NContent.tree, this.woodMetadata);
setBlockAndNotifyAdequately(world, x, y + 1, z, NContent.tree, this.woodMetadata);
setBlockAndNotifyAdequately(world, x + 1, y + 1, z, NContent.tree, this.woodMetadata);
setBlockAndNotifyAdequately(world, x, y + 1, z + 1, NContent.tree, this.woodMetadata);
setBlockAndNotifyAdequately(world, x + 1, y + 1, z + 1, NContent.tree, this.woodMetadata);
}
protected boolean isReplaceable(World world, int x, int y, int z)
{
Block block = world.getBlock(x, y, z);
return block.isAir(world, x, y, z) || block.isLeaves(world, x, y, z) || block.isWood(world, x, y, z);
}
}