aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/GT_Worldgenerator.java
diff options
context:
space:
mode:
authorTechlone <techlone.mc@gmail.com>2017-06-13 17:44:13 +0500
committerTechlone <techlone.mc@gmail.com>2017-06-13 17:44:13 +0500
commitbfd3ff4b19f79efd7f68aec22998c70e09d024f8 (patch)
treed2c18ed50733042779a8585cb20b4e78453f3816 /src/main/java/gregtech/common/GT_Worldgenerator.java
parent3fa72fd1f110f11f2825e27a81f586f807b82bc4 (diff)
parentd7debfd34ece3435dc0f47c54635946c8f29d6f9 (diff)
downloadGT5-Unofficial-bfd3ff4b19f79efd7f68aec22998c70e09d024f8.tar.gz
GT5-Unofficial-bfd3ff4b19f79efd7f68aec22998c70e09d024f8.tar.bz2
GT5-Unofficial-bfd3ff4b19f79efd7f68aec22998c70e09d024f8.zip
Merge branch 'unstable' of https://github.com/Techlone/GT5-Unofficial into unstable
Diffstat (limited to 'src/main/java/gregtech/common/GT_Worldgenerator.java')
-rw-r--r--src/main/java/gregtech/common/GT_Worldgenerator.java50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/main/java/gregtech/common/GT_Worldgenerator.java b/src/main/java/gregtech/common/GT_Worldgenerator.java
index 73b720ca21..2b63f337c3 100644
--- a/src/main/java/gregtech/common/GT_Worldgenerator.java
+++ b/src/main/java/gregtech/common/GT_Worldgenerator.java
@@ -10,17 +10,15 @@ import gregtech.api.world.GT_Worldgen;
import gregtech.common.blocks.GT_TileEntity_Ores;
import net.minecraft.init.Blocks;
import net.minecraft.util.MathHelper;
+import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
-import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
-import net.minecraft.world.gen.ChunkProviderEnd;
-import net.minecraft.world.gen.ChunkProviderHell;
+import java.util.HashSet;
import java.util.Random;
-public class GT_Worldgenerator
- implements IWorldGenerator {
+public class GT_Worldgenerator implements IWorldGenerator {
private static int mEndAsteroidProbability = 300;
private static int mGCAsteroidProbability = 50;
private static int mSize = 100;
@@ -52,16 +50,16 @@ public class GT_Worldgenerator
new WorldGenContainer(new XSTR(aRandom.nextInt()), aX * 16, aZ * 16, tempDimensionId, aWorld, aChunkGenerator, aChunkProvider, aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8).biomeName).run();
}
- public static class WorldGenContainer
- implements Runnable {
+ public static class WorldGenContainer implements Runnable {
public final Random mRandom;
- public final int mX;
- public final int mZ;
+ public int mX;
+ public int mZ;
public final int mDimensionType;
public final World mWorld;
public final IChunkProvider mChunkGenerator;
public final IChunkProvider mChunkProvider;
public final String mBiome;
+ public static HashSet<ChunkCoordIntPair> mGenerated = new HashSet<>(2000);
public WorldGenContainer(Random aRandom, int aX, int aZ, int aDimensionType, World aWorld, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider, String aBiome) {
this.mRandom = aRandom;
@@ -74,8 +72,22 @@ public class GT_Worldgenerator
this.mBiome = aBiome;
}
+ //returns a coordinate of a center chunk of 3x3 square; the argument belongs to this square
+ public int getVeinCenterCoordinate(int c) {
+ c += c < 0 ? 1 : 3;
+ return c - c % 3 - 2;
+ }
+
+ public boolean surroundingChunksLoaded(int xCenter, int zCenter) {
+ return mWorld.checkChunksExist(xCenter - 16, 0, zCenter - 16, xCenter + 16, 0, zCenter + 16);
+ }
+
public void run() {
- if (((this.mX / 16 - 1) % 3 == 0) && ((this.mZ / 16 - 1) % 3 == 0)) {
+ int xCenter = getVeinCenterCoordinate(mX >> 4) << 4;
+ int zCenter = getVeinCenterCoordinate(mZ >> 4) << 4;
+ ChunkCoordIntPair centerChunk = new ChunkCoordIntPair(xCenter, zCenter);
+ if (surroundingChunksLoaded(xCenter, zCenter) && !mGenerated.contains(centerChunk)) {
+ mGenerated.add(centerChunk);
if ((GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) {
boolean temp = true;
int tRandomWeight;
@@ -85,7 +97,7 @@ public class GT_Worldgenerator
tRandomWeight -= ((GT_Worldgen_GT_Ore_Layer) tWorldGen).mWeight;
if (tRandomWeight <= 0) {
try {
- if (tWorldGen.executeWorldgen(this.mWorld, this.mRandom, this.mBiome, this.mDimensionType, this.mX, this.mZ, this.mChunkGenerator, this.mChunkProvider)) {
+ if (tWorldGen.executeWorldgen(this.mWorld, this.mRandom, this.mBiome, this.mDimensionType, xCenter, zCenter, this.mChunkGenerator, this.mChunkProvider)) {
temp = false;
}
break;
@@ -97,10 +109,9 @@ public class GT_Worldgenerator
}
}
int i = 0;
- for (int tX = this.mX - 16; i < 3; tX += 16) {
+ for (int tX = xCenter - 16; i < 3; tX += 16) {
int j = 0;
- for (int tZ = this.mZ - 16; j < 3; tZ += 16) {
- String tBiome = this.mWorld.getBiomeGenForCoords(tX + 8, tZ + 8).biomeName;
+ for (int tZ = zCenter - 16; j < 3; tZ += 16) {
try {
for (GT_Worldgen tWorldGen : GregTech_API.sWorldgenList) {
tWorldGen.executeWorldgen(this.mWorld, this.mRandom, this.mBiome, this.mDimensionType, tX, tZ, this.mChunkGenerator, this.mChunkProvider);
@@ -118,7 +129,7 @@ public class GT_Worldgenerator
String tDimensionName = this.mWorld.provider.getDimensionName();
Random aRandom = new Random();
if (((tDimensionType == 1) && endAsteroids && ((mEndAsteroidProbability <= 1) || (aRandom.nextInt(mEndAsteroidProbability) == 0))) || ((tDimensionName.equals("Asteroids")) && gcAsteroids && ((mGCAsteroidProbability <= 1) || (aRandom.nextInt(mGCAsteroidProbability) == 0)))) {
- short primaryMeta = 0;
+ short primaryMeta = 0;
short secondaryMeta = 0;
short betweenMeta = 0;
short sporadicMeta = 0;
@@ -146,7 +157,7 @@ public class GT_Worldgenerator
}
}
}
- if(GT_Values.D1)System.out.println("do asteroid gen: "+this.mX+" "+this.mZ);
+ if (GT_Values.D1) System.out.println("do asteroid gen: " + this.mX + " " + this.mZ);
int tX = mX + aRandom.nextInt(16);
int tY = 50 + aRandom.nextInt(200 - 50);
int tZ = mZ + aRandom.nextInt(16);
@@ -198,12 +209,7 @@ public class GT_Worldgenerator
if (tDimensionType == 1) {
mWorld.setBlock(eX, eY, eZ, Blocks.end_stone, 0, 2);
} else if (tDimensionName.equals("Asteroids")) {
- //int asteroidType = aRandom.nextInt(20);
- //if (asteroidType == 19) { //Rare Asteroid?
- //mWorld.setBlock(eX, eY, eZ, GregTech_API.sBlockGranites, 8, 3);
- //} else {
mWorld.setBlock(eX, eY, eZ, GregTech_API.sBlockGranites, 8, 3);
- //}
}
}
}
@@ -214,10 +220,8 @@ public class GT_Worldgenerator
}
}
}
-
}
-
Chunk tChunk = this.mWorld.getChunkFromBlockCoords(this.mX, this.mZ);
if (tChunk != null) {
tChunk.isModified = true;