-
Notifications
You must be signed in to change notification settings - Fork 755
/
SurfaceOreGen.java
143 lines (128 loc) · 5.78 KB
/
SurfaceOreGen.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
package tconstruct.worldgen;
import java.util.Random;
import tconstruct.util.config.PHConstruct;
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 SurfaceOreGen extends WorldGenerator
{
/** The block of the ore to be placed using this generator. */
private Block minableBlock;
private int minableBlockMeta = 0;
/** The number of blocks to generate. */
private int numberOfBlocks;
private Block[] replaceBlocks;
private boolean alterSize;
public SurfaceOreGen(Block b, int meta, int number, boolean changeSize)
{
this(b, meta, number, changeSize, Blocks.stone, (Block) Blocks.grass, Blocks.dirt, Blocks.water, Blocks.sand, Blocks.gravel, Blocks.snow);
}
public SurfaceOreGen(Block b, int meta, int number, boolean changeSize, Block... target)
{
this.minableBlock = b;
this.numberOfBlocks = number;
this.replaceBlocks = target;
this.alterSize = changeSize;
minableBlockMeta = meta;
}
int findGround (World world, int x, int y, int z)
{
int returnHeight = -1;
Block block = world.func_147439_a(x, y - 1, z);
if (!world.func_147439_a(x, y, z).func_149662_c() && (block == Blocks.dirt || block == Blocks.grass))
{
return y;
}
int height = PHConstruct.seaLevel + 64;
do
{
if (height < PHConstruct.seaLevel - 30)
{
break;
}
Block b = world.func_147439_a(x, height, z);
if (b == Blocks.dirt || b == Blocks.grass)
{
if (!world.func_147439_a(x, height + 1, z).func_149662_c())
{
returnHeight = height + 1;
}
break;
}
height--;
} while (height > 0);
return returnHeight;
}
public boolean generate (World world, Random random, int startX, int startY, int startZ)
{
if (alterSize)
{
startY = findGround(world, startX, startY, startZ);
if (startY == -1)
return false;
}
float f = random.nextFloat() * (float) Math.PI;
int blockNumber = numberOfBlocks;
if (alterSize)
blockNumber = numberOfBlocks * 2 / 5 + random.nextInt(numberOfBlocks * 3 / 5);
double d0 = (double) ((float) (startX + 8) + MathHelper.sin(f) * (float) blockNumber / 8.0F);
double d1 = (double) ((float) (startX + 8) - MathHelper.sin(f) * (float) blockNumber / 8.0F);
double d2 = (double) ((float) (startZ + 8) + MathHelper.cos(f) * (float) blockNumber / 8.0F);
double d3 = (double) ((float) (startZ + 8) - MathHelper.cos(f) * (float) blockNumber / 8.0F);
double d4 = (double) (startY + random.nextInt(3) - 2);
double d5 = (double) (startY + random.nextInt(3) - 2);
for (int l = 0; l <= blockNumber; ++l)
{
double d6 = d0 + (d1 - d0) * (double) l / (double) blockNumber;
double d7 = d4 + (d5 - d4) * (double) l / (double) blockNumber;
double d8 = d2 + (d3 - d2) * (double) l / (double) blockNumber;
double d9 = random.nextDouble() * (double) blockNumber / 16.0D;
double d10 = (double) (MathHelper.sin((float) l * (float) Math.PI / (float) blockNumber) + 1.0F) * d9 + 1.0D;
double d11 = (double) (MathHelper.sin((float) l * (float) Math.PI / (float) blockNumber) + 1.0F) * d9 + 1.0D;
int i1 = MathHelper.floor_double(d6 - d10 / 2.0D);
int j1 = MathHelper.floor_double(d7 - d11 / 2.0D);
int k1 = MathHelper.floor_double(d8 - d10 / 2.0D);
int l1 = MathHelper.floor_double(d6 + d10 / 2.0D);
int i2 = MathHelper.floor_double(d7 + d11 / 2.0D);
int j2 = MathHelper.floor_double(d8 + d10 / 2.0D);
for (int k2 = i1; k2 <= l1; ++k2)
{
double d12 = ((double) k2 + 0.5D - d6) / (d10 / 2.0D);
if (d12 * d12 < 1.0D)
{
for (int l2 = j1; l2 <= i2; ++l2)
{
double d13 = ((double) l2 + 0.5D - d7) / (d11 / 2.0D);
if (d12 * d12 + d13 * d13 < 1.0D)
{
for (int i3 = k1; i3 <= j2; ++i3)
{
double d14 = ((double) i3 + 0.5D - d8) / (d10 / 2.0D);
Block block = world.func_147439_a(k2, l2, i3);
if (d12 * d12 + d13 * d13 + d14 * d14 < 1.0D)
{
if (block == null || !world.func_147439_a(k2, l2, i3).func_149662_c())
world.func_147465_d(k2, l2, i3, this.minableBlock, minableBlockMeta, 2);
else
{
for (int iter = 0; iter < replaceBlocks.length; iter++)
{
if (block.isGenMineableReplaceable(world, k2, l2, i3, replaceBlocks[iter]))
{
world.func_147465_d(k2, l2, i3, this.minableBlock, minableBlockMeta, 2);
break;
}
}
}
}
}
}
}
}
}
}
return true;
}
}