2015-06-23 22:29:05 +00:00
|
|
|
package gregtech.common;
|
|
|
|
|
2016-08-18 13:45:25 +00:00
|
|
|
import net.minecraft.init.Biomes;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
import net.minecraft.world.biome.Biome;
|
|
|
|
import net.minecraft.world.chunk.IChunkGenerator;
|
2016-08-07 08:41:30 +00:00
|
|
|
import net.minecraftforge.fml.common.IWorldGenerator;
|
|
|
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
2015-06-23 22:29:05 +00:00
|
|
|
import gregtech.api.GregTech_API;
|
|
|
|
import gregtech.api.util.GT_Log;
|
|
|
|
import gregtech.api.world.GT_Worldgen;
|
2015-10-22 00:47:13 +00:00
|
|
|
import gregtech.common.blocks.GT_TileEntity_Ores;
|
|
|
|
import net.minecraft.init.Blocks;
|
2015-06-23 22:29:05 +00:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.chunk.Chunk;
|
|
|
|
import net.minecraft.world.chunk.IChunkProvider;
|
|
|
|
import net.minecraft.world.gen.ChunkProviderEnd;
|
|
|
|
import net.minecraft.world.gen.ChunkProviderHell;
|
|
|
|
|
2015-10-22 02:06:25 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
2016-09-12 11:07:17 +00:00
|
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
2015-10-22 02:06:25 +00:00
|
|
|
|
2016-08-18 13:45:25 +00:00
|
|
|
public class GT_Worldgenerator implements IWorldGenerator {
|
|
|
|
|
2015-10-22 02:06:25 +00:00
|
|
|
private static int mEndAsteroidProbability = 300;
|
|
|
|
private static int mSize = 100;
|
|
|
|
private static int endMinSize = 50;
|
|
|
|
private static int endMaxSize = 200;
|
|
|
|
private static boolean endAsteroids = true;
|
2016-09-12 11:07:17 +00:00
|
|
|
public List<Runnable> mList = new CopyOnWriteArrayList<>();
|
2015-10-22 02:06:25 +00:00
|
|
|
public boolean mIsGenerating = false;
|
|
|
|
|
|
|
|
|
|
|
|
public GT_Worldgenerator() {
|
|
|
|
endAsteroids = GregTech_API.sWorldgenFile.get("endasteroids", "GenerateAsteroids", true);
|
|
|
|
endMinSize = GregTech_API.sWorldgenFile.get("endasteroids", "AsteroidMinSize", 50);
|
|
|
|
endMaxSize = GregTech_API.sWorldgenFile.get("endasteroids", "AsteroidMaxSize", 200);
|
|
|
|
mEndAsteroidProbability = GregTech_API.sWorldgenFile.get("endasteroids", "AsteroidProbability", 300);
|
|
|
|
GameRegistry.registerWorldGenerator(this, 1073741823);
|
2015-06-23 22:29:05 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
|
2016-08-18 13:45:25 +00:00
|
|
|
@Override
|
|
|
|
public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkGenerator aChunkGenerator, IChunkProvider aChunkProvider) {
|
2016-09-12 11:07:17 +00:00
|
|
|
if(aRandom.nextInt(4) == 0) {
|
|
|
|
//TODO less lag on ore gen
|
|
|
|
Biome biome = aWorld.getBiomeGenForCoords(new BlockPos(aX * 16 + 8, 16, aZ * 16 + 8));
|
|
|
|
new WorldGenContainer(new Random(aRandom.nextInt()), aX * 16, aZ * 16,
|
|
|
|
(aChunkGenerator instanceof ChunkProviderEnd || biome == Biomes.SKY) ? 1 :
|
|
|
|
(aChunkGenerator instanceof ChunkProviderHell || biome == Biomes.HELL) ? -1 : 0,
|
|
|
|
aWorld, aChunkGenerator, aChunkProvider, biome.getBiomeName()).run();
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
2015-06-23 22:29:05 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
|
|
|
|
public static class WorldGenContainer
|
|
|
|
implements Runnable {
|
|
|
|
public final Random mRandom;
|
|
|
|
public final int mX;
|
|
|
|
public final int mZ;
|
|
|
|
public final int mDimensionType;
|
|
|
|
public final World mWorld;
|
2016-08-18 13:45:25 +00:00
|
|
|
public final IChunkGenerator mChunkGenerator;
|
2015-10-22 02:06:25 +00:00
|
|
|
public final IChunkProvider mChunkProvider;
|
|
|
|
public final String mBiome;
|
|
|
|
|
2016-08-18 13:45:25 +00:00
|
|
|
public WorldGenContainer(Random aRandom, int aX, int aZ, int aDimensionType, World aWorld, IChunkGenerator aChunkGenerator, IChunkProvider aChunkProvider, String aBiome) {
|
2015-10-22 02:06:25 +00:00
|
|
|
this.mRandom = aRandom;
|
|
|
|
this.mX = aX;
|
|
|
|
this.mZ = aZ;
|
|
|
|
this.mDimensionType = aDimensionType;
|
|
|
|
this.mWorld = aWorld;
|
|
|
|
this.mChunkGenerator = aChunkGenerator;
|
|
|
|
this.mChunkProvider = aChunkProvider;
|
|
|
|
this.mBiome = aBiome;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
if ((Math.abs(this.mX / 16) % 3 == 1) && (Math.abs(this.mZ / 16) % 3 == 1)) {
|
|
|
|
if ((GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) {
|
|
|
|
boolean temp = true;
|
|
|
|
int tRandomWeight;
|
|
|
|
for (int i = 0; (i < 256) && (temp); i++) {
|
|
|
|
tRandomWeight = this.mRandom.nextInt(GT_Worldgen_GT_Ore_Layer.sWeight);
|
|
|
|
for (GT_Worldgen tWorldGen : GT_Worldgen_GT_Ore_Layer.sList) {
|
|
|
|
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)) {
|
|
|
|
temp = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace(GT_Log.err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-23 22:29:05 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
int i = 0;
|
|
|
|
for (int tX = this.mX - 16; i < 3; tX += 16) {
|
|
|
|
int j = 0;
|
|
|
|
for (int tZ = this.mZ - 16; j < 3; tZ += 16) {
|
2016-08-18 13:45:25 +00:00
|
|
|
String tBiome = this.mWorld.getBiomeGenForCoords(new BlockPos(tX + 8, 0, tZ + 8)).getBiomeName();
|
2015-10-22 02:06:25 +00:00
|
|
|
if (tBiome == null) {
|
2016-08-18 13:45:25 +00:00
|
|
|
tBiome = Biomes.PLAINS.getBiomeName();
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
|
|
|
for (GT_Worldgen tWorldGen : GregTech_API.sWorldgenList) {
|
|
|
|
try {
|
|
|
|
tWorldGen.executeWorldgen(this.mWorld, this.mRandom, this.mBiome, this.mDimensionType, tX, tZ, this.mChunkGenerator, this.mChunkProvider);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace(GT_Log.err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
i++;
|
2015-06-23 22:29:05 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
//Asteroid Worldgen
|
2016-08-18 13:45:25 +00:00
|
|
|
int tDimensionType = this.mWorld.provider.getDimension();
|
2015-10-22 02:06:25 +00:00
|
|
|
Random aRandom = new Random();
|
|
|
|
if (((tDimensionType == 1) && endAsteroids && ((mEndAsteroidProbability <= 1) || (aRandom.nextInt(mEndAsteroidProbability) == 0)))) {
|
2015-12-13 16:24:34 +00:00
|
|
|
short primaryMeta = 0;
|
2015-10-22 02:06:25 +00:00
|
|
|
short secondaryMeta = 0;
|
|
|
|
short betweenMeta = 0;
|
|
|
|
short sporadicMeta = 0;
|
|
|
|
if ((GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) {
|
|
|
|
boolean temp = true;
|
|
|
|
int tRandomWeight;
|
|
|
|
for (int i = 0; (i < 256) && (temp); i++) {
|
|
|
|
tRandomWeight = aRandom.nextInt(GT_Worldgen_GT_Ore_Layer.sWeight);
|
|
|
|
for (GT_Worldgen_GT_Ore_Layer tWorldGen : GT_Worldgen_GT_Ore_Layer.sList) {
|
2016-08-18 13:45:25 +00:00
|
|
|
tRandomWeight -= tWorldGen.mWeight;
|
2015-10-22 02:06:25 +00:00
|
|
|
if (tRandomWeight <= 0) {
|
|
|
|
try {
|
|
|
|
if (tWorldGen.mEndAsteroid && tDimensionType == 1) {
|
|
|
|
primaryMeta = tWorldGen.mPrimaryMeta;
|
|
|
|
secondaryMeta = tWorldGen.mSecondaryMeta;
|
|
|
|
betweenMeta = tWorldGen.mBetweenMeta;
|
|
|
|
sporadicMeta = tWorldGen.mSporadicMeta;
|
|
|
|
temp = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace(GT_Log.err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int tX = mX + aRandom.nextInt(16);
|
|
|
|
int tY = 50 + aRandom.nextInt(200 - 50);
|
|
|
|
int tZ = mZ + aRandom.nextInt(16);
|
|
|
|
if (tDimensionType == 1) {
|
2016-08-18 13:45:25 +00:00
|
|
|
mSize = aRandom.nextInt(endMaxSize - endMinSize);
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
2016-08-18 13:45:25 +00:00
|
|
|
if ((mWorld.isAirBlock(new BlockPos(tX, tY, tZ)))) {
|
2015-10-22 02:06:25 +00:00
|
|
|
float var6 = aRandom.nextFloat() * 3.141593F;
|
|
|
|
double var7 = tX + 8 + MathHelper.sin(var6) * mSize / 8.0F;
|
|
|
|
double var9 = tX + 8 - MathHelper.sin(var6) * mSize / 8.0F;
|
|
|
|
double var11 = tZ + 8 + MathHelper.cos(var6) * mSize / 8.0F;
|
|
|
|
double var13 = tZ + 8 - MathHelper.cos(var6) * mSize / 8.0F;
|
|
|
|
double var15 = tY + aRandom.nextInt(3) - 2;
|
|
|
|
double var17 = tY + aRandom.nextInt(3) - 2;
|
|
|
|
for (int var19 = 0; var19 <= mSize; var19++) {
|
|
|
|
double var20 = var7 + (var9 - var7) * var19 / mSize;
|
|
|
|
double var22 = var15 + (var17 - var15) * var19 / mSize;
|
|
|
|
double var24 = var11 + (var13 - var11) * var19 / mSize;
|
|
|
|
double var26 = aRandom.nextDouble() * mSize / 16.0D;
|
|
|
|
double var28 = (MathHelper.sin(var19 * 3.141593F / mSize) + 1.0F) * var26 + 1.0D;
|
|
|
|
double var30 = (MathHelper.sin(var19 * 3.141593F / mSize) + 1.0F) * var26 + 1.0D;
|
|
|
|
int tMinX = MathHelper.floor_double(var20 - var28 / 2.0D);
|
|
|
|
int tMinY = MathHelper.floor_double(var22 - var30 / 2.0D);
|
|
|
|
int tMinZ = MathHelper.floor_double(var24 - var28 / 2.0D);
|
|
|
|
int tMaxX = MathHelper.floor_double(var20 + var28 / 2.0D);
|
|
|
|
int tMaxY = MathHelper.floor_double(var22 + var30 / 2.0D);
|
|
|
|
int tMaxZ = MathHelper.floor_double(var24 + var28 / 2.0D);
|
|
|
|
for (int eX = tMinX; eX <= tMaxX; eX++) {
|
|
|
|
double var39 = (eX + 0.5D - var20) / (var28 / 2.0D);
|
|
|
|
if (var39 * var39 < 1.0D) {
|
|
|
|
for (int eY = tMinY; eY <= tMaxY; eY++) {
|
|
|
|
double var42 = (eY + 0.5D - var22) / (var30 / 2.0D);
|
|
|
|
if (var39 * var39 + var42 * var42 < 1.0D) {
|
|
|
|
for (int eZ = tMinZ; eZ <= tMaxZ; eZ++) {
|
|
|
|
double var45 = (eZ + 0.5D - var24) / (var28 / 2.0D);
|
2016-08-18 13:45:25 +00:00
|
|
|
BlockPos randPos = new BlockPos(eX, eY, eZ);
|
|
|
|
if ((var39 * var39 + var42 * var42 + var45 * var45 < 1.0D) && mWorld.isAirBlock(randPos)) {
|
2015-10-22 02:06:25 +00:00
|
|
|
int ranOre = aRandom.nextInt(50);
|
|
|
|
if (ranOre < 3) {
|
2016-09-12 11:07:17 +00:00
|
|
|
GT_TileEntity_Ores.setOreBlock(mWorld, randPos, primaryMeta , true);
|
2015-10-22 02:06:25 +00:00
|
|
|
} else if (ranOre < 6) {
|
2016-09-12 11:07:17 +00:00
|
|
|
GT_TileEntity_Ores.setOreBlock(mWorld, randPos, secondaryMeta , true);
|
2015-10-22 02:06:25 +00:00
|
|
|
} else if (ranOre < 8) {
|
2016-09-12 11:07:17 +00:00
|
|
|
GT_TileEntity_Ores.setOreBlock(mWorld, randPos, betweenMeta , true);
|
2015-10-22 02:06:25 +00:00
|
|
|
} else if (ranOre < 10) {
|
2016-09-12 11:07:17 +00:00
|
|
|
GT_TileEntity_Ores.setOreBlock(mWorld, randPos, sporadicMeta , true);
|
|
|
|
} else {
|
|
|
|
mWorld.setBlockState(randPos, Blocks.END_STONE.getDefaultState());
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 22:29:05 +00:00
|
|
|
}
|
2016-08-18 13:45:25 +00:00
|
|
|
Chunk tChunk = this.mWorld.getChunkFromBlockCoords(new BlockPos(this.mX, 0, this.mZ));
|
|
|
|
if (tChunk != null) tChunk.setModified(true);
|
2015-06-23 22:29:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|