-
Notifications
You must be signed in to change notification settings - Fork 497
/
SpringPopulate.java
65 lines (51 loc) · 1.87 KB
/
SpringPopulate.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
package buildcraft.core;
import java.util.Random;
import buildcraft.BuildCraftCore;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.common.IWorldGenerator;
public class SpringPopulate implements IWorldGenerator {
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
// shift to world coordinates
int x = chunkX << 4;
int z = chunkZ << 4;
// A spring will be generated every 40th chunk.
if(random.nextFloat() > 0.025f)
return;
// Do not generate water in the End or the Nether
BiomeGenBase biomegenbase = world.getWorldChunkManager().getBiomeGenAt(x, z);
if (biomegenbase.biomeID == BiomeGenBase.sky.biomeID || biomegenbase.biomeID == BiomeGenBase.hell.biomeID)
return;
int posX = x + random.nextInt(16);
int posZ = z + random.nextInt(16);
for(int i = 0; i < 5; i++) {
int candidate = world.getBlockId(posX, i, posZ);
if(candidate != Block.bedrock.blockID)
continue;
world.setBlock(posX, i + 1, posZ, BuildCraftCore.springBlock.blockID);
for(int j = i + 2; j < world.getActualHeight() - 10; j++) {
if(!boreToSurface(world, posX, j, posZ)) {
if(world.isAirBlock(posX, j, posZ))
world.setBlockWithNotify(posX, j, posZ, Block.waterStill.blockID);
break;
}
}
break;
}
}
private boolean boreToSurface(World world, int x, int y, int z) {
if(world.isAirBlock(x, y, z))
return false;
int existing = world.getBlockId(x, y, z);
if(existing != Block.stone.blockID
&& existing != Block.dirt.blockID
&& existing != Block.gravel.blockID
&& existing != Block.grass.blockID)
return false;
world.setBlockWithNotify(x, y, z, Block.waterStill.blockID);
return true;
}
}