-
Notifications
You must be signed in to change notification settings - Fork 497
/
SpringPopulate.java
84 lines (66 loc) · 2.47 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
* 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
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.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.terraingen.PopulateChunkEvent;
import net.minecraftforge.event.terraingen.TerrainGen;
public class SpringPopulate {
@ForgeSubscribe
public void populate(PopulateChunkEvent.Post event) {
boolean doGen = TerrainGen.populate(event.chunkProvider, event.world, event.rand, event.chunkX, event.chunkX, event.hasVillageGenerated, PopulateChunkEvent.Populate.EventType.CUSTOM);
if (!doGen) {
return;
}
// shift to world coordinates
int worldX = event.chunkX << 4;
int worldZ = event.chunkZ << 4;
doPopulate(event.world, event.rand, worldX, worldZ);
}
private void doPopulate(World world, Random random, int x, int z) {
// 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;
}
}