/
DarkwoodGen.java
171 lines (144 loc) · 5.44 KB
/
DarkwoodGen.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
package mods.natura.worldgen;
import java.util.Random;
import mods.natura.blocks.trees.NSaplingBlock;
import mods.natura.common.NContent;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.common.util.ForgeDirection;
public class DarkwoodGen extends WorldGenerator
{
/** The minimum height of a generated tree. */
private final int minTreeHeight;
/** The metadata value of the wood to use in tree generation. */
private final int metaWood;
private final boolean seekGround;
public DarkwoodGen(boolean par1)
{
this(par1, 4, 0);
}
public DarkwoodGen(boolean par1, int par2, int par3)
{
super(par1);
this.minTreeHeight = par2;
this.metaWood = par3;
seekGround = !par1;
}
int findGround (World world, int x, int y, int z)
{
boolean foundGround = false;
int height = y;
do
{
height--;
Block underID = world.getBlock(x, height, z);
if (underID == Blocks.netherrack || underID == Blocks.soul_sand || underID == NContent.taintedSoil || height < 0)
foundGround = true;
} while (!foundGround);
return height + 1;
}
public boolean generate (World world, Random random, int xPos, int yPos, int zPos)
{
int treeHeight = random.nextInt(3) + this.minTreeHeight;
if (treeHeight < 4)
treeHeight = 4;
boolean flag = true;
if (this.seekGround)
yPos = findGround(world, xPos, yPos, zPos);
if (yPos >= 1 && yPos + treeHeight + 1 <= 256)
{
int i1;
byte b0;
int j1;
int k1;
for (i1 = yPos; i1 <= yPos + 1 + treeHeight; ++i1)
{
b0 = 1;
if (i1 == yPos)
{
b0 = 0;
}
if (i1 >= yPos + 1 + treeHeight - 2)
{
b0 = 2;
}
for (int l1 = xPos - b0; l1 <= xPos + b0 && flag; ++l1)
{
for (j1 = zPos - b0; j1 <= zPos + b0 && flag; ++j1)
{
if (i1 >= 0 && i1 < 256)
{
Block block = world.getBlock(l1, i1, j1);
if (block != null && !block.isLeaves(world, l1, i1, j1) && block != Blocks.netherrack && block != Blocks.soul_sand && block != NContent.taintedSoil
&& !block.isWood(world, l1, i1, j1))
{
flag = false;
}
}
else
{
flag = false;
}
}
}
}
if (!flag)
{
return false;
}
else
{
Block soil = world.getBlock(xPos, yPos - 1, zPos);
boolean isSoil = (soil != null && soil.canSustainPlant(world, xPos, yPos - 1, zPos, ForgeDirection.UP, (NSaplingBlock) NContent.floraSapling)) || soil == Blocks.netherrack;
if (isSoil && yPos < 256 - treeHeight - 1)
{
soil.onPlantGrow(world, xPos, yPos - 1, zPos, xPos, yPos, zPos);
b0 = 3;
byte b1 = 0;
int i2;
int j2;
int k2;
for (j1 = yPos - b0 + treeHeight; j1 <= yPos + treeHeight; ++j1)
{
k1 = j1 - (yPos + treeHeight);
i2 = b1 + 1 - k1 / 2;
for (j2 = xPos - i2; j2 <= xPos + i2; ++j2)
{
k2 = j2 - xPos;
for (int l2 = zPos - i2; l2 <= zPos + i2; ++l2)
{
int i3 = l2 - zPos;
if (Math.abs(k2) != i2 || Math.abs(i3) != i2 || random.nextInt(2) != 0 && k1 != 0)
{
Block block = world.getBlock(j2, j1, l2);
if (block == null || block.canBeReplacedByLeaves(world, j2, j1, l2))
{
this.setBlockAndMetadata(world, j2, j1, l2, NContent.darkLeaves, random.nextInt(25) == 0 ? 2 : random.nextInt(15) == 0 ? 1 : 0);
}
}
}
}
}
for (j1 = 0; j1 < treeHeight; ++j1)
{
Block block = world.getBlock(xPos, yPos + j1, zPos);
if (block == null || block.isLeaves(world, xPos, yPos + j1, zPos))
{
this.setBlockAndMetadata(world, xPos, yPos + j1, zPos, NContent.darkTree, this.metaWood);
}
}
return true;
}
else
{
return false;
}
}
}
else
{
return false;
}
}
}