Skip to content

Commit f7e35ef

Browse files
committed
fixed #20
1 parent ee59c9e commit f7e35ef

File tree

4 files changed

+62
-55
lines changed

4 files changed

+62
-55
lines changed

src/main/java/unstudio/chinacraft/world/gen/WorldGenBambooShoot.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
public class WorldGenBambooShoot extends WorldGenerator{
1414
@Override
1515
public boolean generate(World world, Random random, int x, int y, int z) {
16+
if (!world.blockExists(x, y, z)) return false;
17+
1618
int x1 = x + random.nextInt(16);
1719
int z1 = z + random.nextInt(16);
1820
int y1 = world.getHeightValue(x1,z1)+1;
1921
int id = world.getBiomeGenForCoords(x1, z1).biomeID;
20-
if ((id == 3 || id == 4 || id == 18 || id == 20 || id == 34 || id == 27 || id == 28 || id == 29)
21-
&& random.nextInt(16) == 0) try {
22+
if ((id == 3 || id == 4 || id == 18 || id == 20 || id == 34 || id == 27 || id == 28 || id == 29)) {
23+
if (!world.blockExists(x1, y1, z1)) return false;
2224
new WorldGenFlowers(ChinaCraft.blockBambooShoot).generate(world, random, x1, y1, z1);
23-
} catch (RuntimeException e) {
24-
//TODO: unknown exception
25-
e.printStackTrace();
2625
}
2726
return true;
2827
}

src/main/java/unstudio/chinacraft/world/gen/WorldGenCCFlower.java

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ private void gen(Random random, int blockX, int blockZ, World world, Block block
1515
int z = blockZ + random.nextInt(16);
1616
int y = world.getHeightValue(x, z) +1;
1717

18+
if (!world.blockExists(x, y, z)) return;
19+
1820
if (world.isAirBlock(x, y, z) && (!world.provider.hasNoSky || y < 255) && block.canBlockStay(world, x, y, z))
1921
world.setBlock(x, y, z, block, 0, 3);
2022
}

src/main/java/unstudio/chinacraft/world/gen/WorldGenCCOre.java

+15-13
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@ public class WorldGenCCOre extends WorldGenerator {
1717
private final Set<Integer> dimensionID = new HashSet();
1818
private final Set<Integer> biomeID = new HashSet();
1919
private final int frequency;
20-
private final int highest,lowest;
20+
private final int highest, lowest;
2121
private final WorldGenMinable gen;
2222

23-
public WorldGenCCOre(int dimensions[], int biomes[], int frequency, int highest, int lowest, int size, Block oreBlock){
24-
this(dimensions,biomes,frequency, highest,lowest,size,oreBlock,null);
23+
public WorldGenCCOre(int dimensions[], int biomes[], int frequency, int highest, int lowest, int size, Block oreBlock) {
24+
this(dimensions, biomes, frequency, highest, lowest, size, oreBlock, null);
2525
}
2626

27-
public WorldGenCCOre(int dimensions[], int frequency, int highest, int lowest, int size, Block oreBlock){
28-
this(dimensions,frequency, highest,lowest,size,oreBlock,null);
27+
public WorldGenCCOre(int dimensions[], int frequency, int highest, int lowest, int size, Block oreBlock) {
28+
this(dimensions, frequency, highest, lowest, size, oreBlock, null);
2929
}
3030

31-
public WorldGenCCOre(int dimensions[], int frequency, int highest, int lowest, int size, Block oreBlock, Block predicate){
32-
this(dimensions,new int[0],frequency, highest,lowest,size,oreBlock,predicate);
31+
public WorldGenCCOre(int dimensions[], int frequency, int highest, int lowest, int size, Block oreBlock, Block predicate) {
32+
this(dimensions, new int[0], frequency, highest, lowest, size, oreBlock, predicate);
3333
}
3434

35-
public WorldGenCCOre(int dimensions[], int biomes[], int frequency, int highest, int lowest, int size, Block oreBlock, Block predicate){
36-
for(int i:dimensions) dimensionID.add(i);
37-
for(int i:biomes) biomeID.add(i);
35+
public WorldGenCCOre(int dimensions[], int biomes[], int frequency, int highest, int lowest, int size, Block oreBlock, Block predicate) {
36+
for (int i : dimensions) dimensionID.add(i);
37+
for (int i : biomes) biomeID.add(i);
3838
this.frequency = frequency;
3939
this.highest = highest;
4040
this.lowest = lowest;
41-
if(predicate==null) gen = new WorldGenMinable(oreBlock, size);
41+
if (predicate == null) gen = new WorldGenMinable(oreBlock, size);
4242
else gen = new WorldGenMinable(oreBlock, size, predicate);
4343
}
4444

@@ -51,9 +51,11 @@ public boolean generate(World worldIn, Random rand, int x, int y, int z) {
5151
int ty = rand.nextInt(highest - lowest) + lowest;
5252
int tz = z + rand.nextInt(16);
5353

54-
if(!biomeID.isEmpty() && !biomeID.contains(worldIn.getBiomeGenForCoords(tx,tz).biomeID)) return true;
54+
if (!biomeID.isEmpty() && !biomeID.contains(worldIn.getBiomeGenForCoords(tx, tz).biomeID)) return true;
5555

56-
gen.generate(worldIn, rand, tx,ty,tz);
56+
if (!worldIn.blockExists(tx, ty, tz)) continue;
57+
58+
gen.generate(worldIn, rand, tx, ty, tz);
5759
}
5860
return true;
5961
}

src/main/java/unstudio/chinacraft/world/gen/WorldGenMulberryTree.java

+41-37
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,32 @@ public WorldGenMulberryTree(boolean p_i45448_1_, int minTreeHeight, int maxTreeH
3636
}
3737

3838
@Override
39-
public boolean generate(World p_76484_1_, Random p_76484_2_, int p_76484_3_, int p_76484_4_, int p_76484_5_) {
40-
int l = p_76484_2_.nextInt(this.maxTreeHeight - this.minTreeHeight) + this.minTreeHeight;
39+
public boolean generate(World world, Random rand, int x, int y, int z) {
40+
int l = rand.nextInt(this.maxTreeHeight - this.minTreeHeight) + this.minTreeHeight;
4141
boolean flag = true;
4242

43-
if (p_76484_4_ >= 1 && p_76484_4_ + l + 1 <= 256) {
43+
if (y >= 1 && y + l + 1 <= 256) {
4444
byte b0;
4545
int k1;
4646
Block block;
4747

48-
for (int i1 = p_76484_4_; i1 <= p_76484_4_ + 1 + l; ++i1) {
48+
for (int i1 = y; i1 <= y + 1 + l; ++i1) {
4949
b0 = 1;
5050

51-
if (i1 == p_76484_4_) {
51+
if (i1 == y) {
5252
b0 = 0;
5353
}
5454

55-
if (i1 >= p_76484_4_ + 1 + l - 2) {
55+
if (i1 >= y + 1 + l - 2) {
5656
b0 = 2;
5757
}
5858

59-
for (int j1 = p_76484_3_ - b0; j1 <= p_76484_3_ + b0 && flag; ++j1) {
60-
for (k1 = p_76484_5_ - b0; k1 <= p_76484_5_ + b0 && flag; ++k1) {
59+
for (int j1 = x - b0; j1 <= x + b0 && flag; ++j1) {
60+
for (k1 = z - b0; k1 <= z + b0 && flag; ++k1) {
6161
if (i1 >= 0 && i1 < 256) {
62-
block = p_76484_1_.getBlock(j1, i1, k1);
62+
block = world.getBlock(j1, i1, k1);
6363

64-
if (!this.isReplaceable(p_76484_1_, j1, i1, k1)) {
64+
if (!this.isReplaceable(world, j1, i1, k1)) {
6565
flag = false;
6666
}
6767
} else {
@@ -74,48 +74,48 @@ public boolean generate(World p_76484_1_, Random p_76484_2_, int p_76484_3_, int
7474
if (!flag) {
7575
return false;
7676
} else {
77-
Block block2 = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ - 1, p_76484_5_);
77+
Block block2 = world.getBlock(x, y - 1, z);
7878

79-
boolean isSoil = block2.canSustainPlant(p_76484_1_, p_76484_3_, p_76484_4_ - 1, p_76484_5_,
79+
boolean isSoil = block2.canSustainPlant(world, x, y - 1, z,
8080
ForgeDirection.UP, (IPlantable) treeSapling);
81-
if (isSoil && p_76484_4_ < 256 - l - 1) {
82-
block2.onPlantGrow(p_76484_1_, p_76484_3_, p_76484_4_ - 1, p_76484_5_, p_76484_3_, p_76484_4_,
83-
p_76484_5_);
81+
if (isSoil && y < 256 - l - 1) {
82+
block2.onPlantGrow(world, x, y - 1, z, x, y,
83+
z);
8484
b0 = 3;
8585
byte b1 = 0;
8686
int l1;
8787
int i2;
8888
int j2;
8989
int i3;
9090

91-
for (k1 = p_76484_4_ - b0 + l; k1 <= p_76484_4_ + l; ++k1) {
92-
i3 = k1 - (p_76484_4_ + l);
91+
for (k1 = y - b0 + l; k1 <= y + l; ++k1) {
92+
i3 = k1 - (y + l);
9393
l1 = b1 + 1 - i3 / 2;
9494

95-
for (i2 = p_76484_3_ - l1; i2 <= p_76484_3_ + l1; ++i2) {
96-
j2 = i2 - p_76484_3_;
95+
for (i2 = x - l1; i2 <= x + l1; ++i2) {
96+
j2 = i2 - x;
9797

98-
for (int k2 = p_76484_5_ - l1; k2 <= p_76484_5_ + l1; ++k2) {
99-
int l2 = k2 - p_76484_5_;
98+
for (int k2 = z - l1; k2 <= z + l1; ++k2) {
99+
int l2 = k2 - z;
100100

101-
if (Math.abs(j2) != l1 || Math.abs(l2) != l1 || p_76484_2_.nextInt(2) != 0 && i3 != 0) {
102-
Block block1 = p_76484_1_.getBlock(i2, k1, k2);
101+
if (Math.abs(j2) != l1 || Math.abs(l2) != l1 || rand.nextInt(2) != 0 && i3 != 0) {
102+
Block block1 = world.getBlock(i2, k1, k2);
103103

104-
if (block1.isAir(p_76484_1_, i2, k1, k2)
105-
|| block1.isLeaves(p_76484_1_, i2, k1, k2)) {
106-
this.setBlockAndNotifyAdequately(p_76484_1_, i2, k1, k2, treeLeaf, 0);
104+
if (block1.isAir(world, i2, k1, k2)
105+
|| block1.isLeaves(world, i2, k1, k2)) {
106+
this.setBlockAndNotifyAdequately(world, i2, k1, k2, treeLeaf, 0);
107107
}
108108
}
109109
}
110110
}
111111
}
112112

113113
for (k1 = 0; k1 < l; ++k1) {
114-
block = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ + k1, p_76484_5_);
114+
block = world.getBlock(x, y + k1, z);
115115

116-
if (block.isAir(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_)
117-
|| block.isLeaves(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_)) {
118-
this.setBlockAndNotifyAdequately(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_,
116+
if (block.isAir(world, x, y + k1, z)
117+
|| block.isLeaves(world, x, y + k1, z)) {
118+
this.setBlockAndNotifyAdequately(world, x, y + k1, z,
119119
treeBlock, 0);
120120
}
121121
}
@@ -132,14 +132,18 @@ public boolean generate(World p_76484_1_, Random p_76484_2_, int p_76484_3_, int
132132
@Override
133133
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator,
134134
IChunkProvider chunkProvider) {
135-
int x = chunkX * 16 + random.nextInt(16);
136-
int z = chunkZ * 16 + random.nextInt(16);
137-
int biomeID = world.getBiomeGenForCoords(x, z).biomeID;
138-
if (biomeID == 4) {
139-
Block topBlock = world.getTopBlock(x, z);
140-
if (topBlock == Blocks.grass) {
141-
this.generate(world, random, x, world.getTopSolidOrLiquidBlock(x, z), z);
135+
try {
136+
int x = chunkX * 16 + random.nextInt(16);
137+
int z = chunkZ * 16 + random.nextInt(16);
138+
int biomeID = world.getBiomeGenForCoords(x, z).biomeID;
139+
if (biomeID == 4) {
140+
Block topBlock = world.getTopBlock(x, z);
141+
if (topBlock == Blocks.grass) {
142+
this.generate(world, random, x, world.getTopSolidOrLiquidBlock(x, z), z);
143+
}
142144
}
145+
} catch (Exception e) {
146+
e.printStackTrace();
143147
}
144148
}
145149

0 commit comments

Comments
 (0)