/
BerryBushGen.java
200 lines (177 loc) · 6.04 KB
/
BerryBushGen.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
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.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
public class BerryBushGen extends WorldGenerator
{
private int metadata;
private int spawnHeight;
public BerryBushGen(int meta, int range)
{
metadata = meta;
spawnHeight = range;
}
@Override
public boolean generate (World world, Random random, int x, int y, int z)
{
int height = findGround(world, x, y, z);
if (height != -1)
{
int type = random.nextInt(10);
if (type == 9)
generateLargeNode(world, random, x, height, z);
else if (type >= 7)
generateShrub(world, random, x, height, z);
else if (type >= 3)
generateSmallNode(world, random, x, height, z);
else
generateTinyNode(world, random, x, height, z);
}
return true;
}
int findGround (World world, int x, int y, int z)
{
int returnHeight = -1;
Block blockID = world.getBlock(x, y - 1, z);
if (!world.getBlock(x, y, z).isOpaqueCube() && (blockID == Blocks.dirt || blockID == Blocks.grass))
{
return y;
}
int height = spawnHeight;
do
{
if (height < PHNatura.seaLevel)
{
break;
}
Block j1 = world.getBlock(x, height, z);
if (j1 == Blocks.dirt || j1 == Blocks.grass)
{
if (!world.getBlock(x, height + 1, z).isOpaqueCube())
{
returnHeight = height + 1;
}
break;
}
height--;
} while (height > 0);
return returnHeight;
}
public void generateLargeNode (World world, Random random, int x, int y, int z)
{
for (int iterX = x - 2; iterX <= x + 2; iterX++)
{
for (int iterZ = z - 1; iterZ <= z + 1; iterZ++)
{
for (int iterY = y - 1; iterY <= y; iterY++)
{
generateBerryBlock(world, iterX, iterY, iterZ, random);
}
}
}
for (int iterX = x - 1; iterX <= x + 1; iterX++)
{
for (int iterZ = z - 2; iterZ <= z - 2; iterZ++)
{
for (int iterY = y - 1; iterY <= y; iterY++)
{
generateBerryBlock(world, iterX, iterY, iterZ, random);
}
}
}
for (int iterX = x - 1; iterX <= x + 1; iterX++)
{
for (int iterZ = z + 2; iterZ <= z + 2; iterZ++)
{
for (int iterY = y - 1; iterY <= y; iterY++)
{
generateBerryBlock(world, iterX, iterY, iterZ, random);
}
}
}
for (int iterX = x - 1; iterX <= x + 1; iterX++)
{
for (int iterZ = z - 1; iterZ <= z + 1; iterZ++)
{
int yPos = y + 1;
generateBerryBlock(world, iterX, yPos, iterZ, random);
yPos = y - 2;
generateBerryBlock(world, iterX, yPos, iterZ, random);
}
}
}
public void generateShrub (World world, Random random, int x, int y, int z)
{
int l;
Block block = null;
do
{
block = world.getBlock(x, y, z);
if (block != null && !block.isLeaves(world, x, y, z))
{
break;
}
y--;
} while (y > 0);
Block i1 = world.getBlock(x, y, z);
if (i1 == Blocks.dirt || i1 == Blocks.grass)
{
++y;
for (int yPos = y; yPos <= y + 2; ++yPos)
{
int k1 = yPos - y;
int l1 = 2 - k1;
for (int xPos = x - l1; xPos <= x + l1; ++xPos)
{
int j2 = xPos - x;
for (int zPos = z - l1; zPos <= z + l1; ++zPos)
{
int l2 = zPos - z;
block = world.getBlock(xPos, yPos, zPos);
if ((Math.abs(j2) != l1 || Math.abs(l2) != l1 || random.nextInt(2) != 0) && (block == null || block.canBeReplacedByLeaves(world, xPos, yPos, zPos)))
{
//this.setBlockAndMetadata(world, i2, j1, k2, Block.leaves.blockID, this.field_76527_a);
generateBerryBlock(world, xPos, yPos, zPos, random);
}
}
}
}
}
}
public void generateSmallNode (World world, Random random, int x, int y, int z)
{
generateBerryBlock(world, x, y, z, random);
if (random.nextBoolean())
generateBerryBush(world, x + 1, y, z, random);
if (random.nextBoolean())
generateBerryBush(world, x - 1, y, z, random);
if (random.nextBoolean())
generateBerryBush(world, x, y, z + 1, random);
if (random.nextBoolean())
generateBerryBush(world, x, y, z - 1, random);
}
public void generateTinyNode (World world, Random random, int x, int y, int z)
{
generateBerryBush(world, x, y, z, random);
}
void generateBerryBlock (World world, int x, int y, int z, Random random)
{
if (!world.getBlock(x, y, z).isOpaqueCube())
{
int metaOffset = random.nextInt(5) == 0 ? 1 : 0;
world.setBlock(x, y, z, NContent.berryBush, metadata + 8 + metaOffset * 4, 0);
}
}
void generateBerryBush (World world, int x, int y, int z, Random random)
{
if (!world.getBlock(x, y, z).isOpaqueCube())
{
int metaOffset = random.nextInt(4);
world.setBlock(x, y, z, NContent.berryBush, metadata + metaOffset * 4, 0);
}
}
}