-
Notifications
You must be signed in to change notification settings - Fork 754
/
OreberryBushGen.java
111 lines (97 loc) · 3.79 KB
/
OreberryBushGen.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
package tconstruct.worldgen;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
public class OreberryBushGen extends WorldGenerator
{
private int blockID;
private int metadata;
int chance;
private int[] replaceBlocks;
public OreberryBushGen(Block block, int meta, int chance)
{
this(meta, chance, Blocks.stone, Blocks.grass, Blocks.dirt, Blocks.water, Blocks.sand, Blocks.gravel, Blocks.snow);
}
public OreberryBushGen(int blockID, int meta, int chance, int... target)
{
this.blockID = blockID;
metadata = meta;
this.chance = chance;
this.replaceBlocks = target;
}
public boolean generate (World world, Random random, int x, int y, int z)
{
int type = random.nextInt(chance);
if (type == 11)
generateMediumNode(world, random, x, y, z);
else if (type >= 5)
generateSmallNode(world, random, x, y, z);
else
generateTinyNode(world, random, x, y, z);
return true;
}
public void generateMediumNode (World world, Random random, int x, int y, int z)
{
for (int xPos = -1; xPos <= 1; xPos++)
for (int yPos = -1; yPos <= 1; yPos++)
for (int zPos = -1; zPos <= 1; zPos++)
if (random.nextInt(4) == 0)
generateBerryBlock(world, x + xPos, y + yPos, z + zPos, random);
generateSmallNode(world, random, x, y, z);
}
public void generateSmallNode (World world, Random random, int x, int y, int z)
{
generateBerryBlock(world, x, y, z, random);
if (random.nextBoolean())
generateBerryBlock(world, x + 1, y, z, random);
if (random.nextBoolean())
generateBerryBlock(world, x - 1, y, z, random);
if (random.nextBoolean())
generateBerryBlock(world, x, y, z + 1, random);
if (random.nextBoolean())
generateBerryBlock(world, x, y, z - 1, random);
if (random.nextBoolean())
generateBerryBlock(world, x, y + 1, z, random);
if (random.nextBoolean())
generateBerryBlock(world, x, y + 1, z, random);
}
public void generateTinyNode (World world, Random random, int x, int y, int z)
{
generateBerryBlock(world, x, y, z, random);
if (random.nextInt(4) == 0)
generateBerryBlock(world, x + 1, y, z, random);
if (random.nextInt(4) == 0)
generateBerryBlock(world, x - 1, y, z, random);
if (random.nextInt(4) == 0)
generateBerryBlock(world, x, y, z + 1, random);
if (random.nextInt(4) == 0)
generateBerryBlock(world, x, y, z - 1, random);
if (random.nextInt(4) == 0)
generateBerryBlock(world, x, y + 1, z, random);
if (random.nextInt(4) == 0)
generateBerryBlock(world, x, y + 1, z, random);
}
void generateBerryBlock (World world, int x, int y, int z, Random random)
{
/*if (!Block.opaqueCubeLookup[world.getBlockId(x, y, z)])
{
setBlockAndMetadata(world, x, y, z, blockID, metadata);
}*/
Block block = Block.blocksList[world.getBlockId(x, y, z)];
if (block == null || (block != Block.endPortalFrame && !Block.opaqueCubeLookup[world.getBlockId(x, y, z)]))
world.setBlock(x, y, z, this, metadata, 2);
else
{
for (int iter = 0; iter < replaceBlocks.length; iter++)
{
if (block.isGenMineableReplaceable(world, x, y, z, replaceBlocks[iter]))
{
world.setBlock(x, y, z, this, metadata, 2);
break;
}
}
}
}
}