2015-06-23 22:29:05 +00:00
|
|
|
package gregtech.common;
|
|
|
|
|
2016-12-15 14:58:15 +00:00
|
|
|
import gregtech.api.GregTech_API;
|
2016-09-22 15:00:27 +00:00
|
|
|
import gregtech.api.objects.XSTR;
|
2016-12-15 14:58:15 +00:00
|
|
|
import gregtech.api.util.GT_Log;
|
|
|
|
import gregtech.api.world.GT_Worldgen;
|
2017-06-11 13:26:28 +00:00
|
|
|
import gregtech.common.blocks.BlockGeneratedOres;
|
2016-12-17 16:56:09 +00:00
|
|
|
import gregtech.common.blocks.GT_Block_GeneratedOres;
|
2016-08-18 13:45:25 +00:00
|
|
|
import net.minecraft.init.Biomes;
|
2016-12-15 14:58:15 +00:00
|
|
|
import net.minecraft.init.Blocks;
|
2016-08-18 13:45:25 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
2016-12-15 14:58:15 +00:00
|
|
|
import net.minecraft.world.World;
|
2016-08-18 13:45:25 +00:00
|
|
|
import net.minecraft.world.biome.Biome;
|
|
|
|
import net.minecraft.world.chunk.IChunkGenerator;
|
2015-06-23 22:29:05 +00:00
|
|
|
import net.minecraft.world.chunk.IChunkProvider;
|
|
|
|
import net.minecraft.world.gen.ChunkProviderEnd;
|
|
|
|
import net.minecraft.world.gen.ChunkProviderHell;
|
2016-12-15 14:58:15 +00:00
|
|
|
import net.minecraftforge.fml.common.IWorldGenerator;
|
|
|
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
2015-06-23 22:29:05 +00:00
|
|
|
|
2015-10-22 02:06:25 +00:00
|
|
|
import java.util.Random;
|
|
|
|
|
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;
|
2016-12-28 20:16:39 +00:00
|
|
|
private static int mGCAsteroidProbability = 50;
|
2015-10-22 02:06:25 +00:00
|
|
|
private static int mSize = 100;
|
|
|
|
private static int endMinSize = 50;
|
|
|
|
private static int endMaxSize = 200;
|
2016-12-28 20:16:39 +00:00
|
|
|
private static int gcMinSize = 100;
|
|
|
|
private static int gcMaxSize = 400;
|
2015-10-22 02:06:25 +00:00
|
|
|
private static boolean endAsteroids = true;
|
2016-12-28 20:16:39 +00:00
|
|
|
private static boolean gcAsteroids = true;
|
2016-09-30 16:20:15 +00:00
|
|
|
private static Random mRandom;
|
2015-10-22 02:06:25 +00:00
|
|
|
|
|
|
|
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);
|
2016-12-28 20:16:39 +00:00
|
|
|
gcAsteroids = GregTech_API.sWorldgenFile.get("gcasteroids", "GenerateGCAsteroids", true);
|
|
|
|
gcMinSize = GregTech_API.sWorldgenFile.get("gcasteroids", "GCAsteroidMinSize", 100);
|
|
|
|
gcMaxSize = GregTech_API.sWorldgenFile.get("gcasteroids", "GCAsteroidMaxSize", 400);
|
|
|
|
mGCAsteroidProbability = GregTech_API.sWorldgenFile.get("gcasteroids", "GCAsteroidProbability", 300);
|
2015-10-22 02:06:25 +00:00
|
|
|
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-30 16:20:15 +00:00
|
|
|
if(mRandom == null) {
|
|
|
|
mRandom = new XSTR(aRandom.nextLong() ^ System.nanoTime());
|
|
|
|
}
|
2017-04-05 15:22:28 +00:00
|
|
|
Biome biome = aWorld.getBiome(new BlockPos(aX * 16, 64, aZ * 16));
|
2016-09-30 16:20:15 +00:00
|
|
|
generateInternal(aX * 16, aZ * 16,
|
2016-09-22 15:00:27 +00:00
|
|
|
getDimensionType(aChunkGenerator, biome),
|
|
|
|
aWorld, aChunkGenerator, aChunkProvider,
|
|
|
|
biome.getBiomeName());
|
2015-06-23 22:29:05 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
|
2016-09-22 15:00:27 +00:00
|
|
|
private int getDimensionType(IChunkGenerator aChunkGenerator, Biome biome) {
|
|
|
|
return (aChunkGenerator instanceof ChunkProviderEnd || biome == Biomes.SKY) ? 1 :
|
2016-12-28 20:16:39 +00:00
|
|
|
(aChunkGenerator instanceof ChunkProviderHell || biome == Biomes.HELL) ? -1 : 0;
|
2016-09-22 15:00:27 +00:00
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
|
|
|
|
|
2016-09-30 16:20:15 +00:00
|
|
|
private void generateInternal(int mX, int mZ, int mDimensionType, World mWorld, IChunkGenerator mChunkGenerator, IChunkProvider mChunkProvider, String mBiome) {
|
2016-09-22 15:00:27 +00:00
|
|
|
if ((Math.abs(mX / 16) % 3 == 1) && (Math.abs(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 = 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(mWorld, mRandom, mBiome, mDimensionType, mX, mZ, mChunkGenerator, mChunkProvider)) {
|
|
|
|
temp = false;
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
2016-09-22 15:00:27 +00:00
|
|
|
break;
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace(GT_Log.err);
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-23 22:29:05 +00:00
|
|
|
}
|
2016-09-22 15:00:27 +00:00
|
|
|
}
|
|
|
|
int i = 0;
|
|
|
|
for (int tX = mX - 16; i < 3; tX += 16) {
|
|
|
|
int j = 0;
|
|
|
|
for (int tZ = mZ - 16; j < 3; tZ += 16) {
|
2017-04-05 15:22:28 +00:00
|
|
|
String tBiome = mWorld.getBiome(new BlockPos(tX + 8, 0, tZ + 8)).getBiomeName();
|
2016-12-28 20:16:39 +00:00
|
|
|
try {
|
|
|
|
for (GT_Worldgen tWorldGen : GregTech_API.sWorldgenList) {
|
2016-09-22 15:00:27 +00:00
|
|
|
tWorldGen.executeWorldgen(mWorld, mRandom, mBiome, mDimensionType, tX, tZ, mChunkGenerator, mChunkProvider);
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
2016-12-28 20:16:39 +00:00
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace(GT_Log.err);
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
2016-09-22 15:00:27 +00:00
|
|
|
j++;
|
2015-06-23 22:29:05 +00:00
|
|
|
}
|
2016-09-22 15:00:27 +00:00
|
|
|
i++;
|
2015-06-23 22:29:05 +00:00
|
|
|
}
|
2016-09-22 15:00:27 +00:00
|
|
|
}
|
|
|
|
//Asteroid Worldgen
|
|
|
|
int tDimensionType = mWorld.provider.getDimension();
|
2017-01-02 06:56:40 +00:00
|
|
|
String tDimensionName = mWorld.getChunkProvider().makeString();
|
2016-09-22 15:00:27 +00:00
|
|
|
Random aRandom = new Random();
|
2016-12-28 20:16:39 +00:00
|
|
|
if (((tDimensionType == 1) && endAsteroids && ((mEndAsteroidProbability <= 1) || (aRandom.nextInt(mEndAsteroidProbability) == 0))) || ((tDimensionName.equals("Asteroids")) && gcAsteroids && ((mGCAsteroidProbability <= 1) || (aRandom.nextInt(mGCAsteroidProbability) == 0)))) {
|
2016-09-22 15:00:27 +00:00
|
|
|
short primaryMeta = 0;
|
|
|
|
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) {
|
|
|
|
tRandomWeight -= tWorldGen.mWeight;
|
|
|
|
if (tRandomWeight <= 0) {
|
|
|
|
try {
|
2016-12-28 20:16:39 +00:00
|
|
|
if ((tWorldGen.mEndAsteroid && tDimensionType == 1) || (tWorldGen.mAsteroid && tDimensionType == -30)) {
|
2016-09-22 15:00:27 +00:00
|
|
|
primaryMeta = tWorldGen.mPrimaryMeta;
|
|
|
|
secondaryMeta = tWorldGen.mSecondaryMeta;
|
|
|
|
betweenMeta = tWorldGen.mBetweenMeta;
|
|
|
|
sporadicMeta = tWorldGen.mSporadicMeta;
|
|
|
|
temp = false;
|
|
|
|
break;
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
2016-09-22 15:00:27 +00:00
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace(GT_Log.err);
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 15:00:27 +00:00
|
|
|
}
|
|
|
|
int tX = mX + aRandom.nextInt(16);
|
|
|
|
int tY = 50 + aRandom.nextInt(200 - 50);
|
|
|
|
int tZ = mZ + aRandom.nextInt(16);
|
|
|
|
if (tDimensionType == 1) {
|
|
|
|
mSize = aRandom.nextInt(endMaxSize - endMinSize);
|
2016-12-28 20:16:39 +00:00
|
|
|
} else if (tDimensionName.equals("Asteroids")) {
|
|
|
|
mSize = aRandom.nextInt(gcMaxSize - gcMinSize);
|
2016-09-22 15:00:27 +00:00
|
|
|
}
|
|
|
|
if ((mWorld.isAirBlock(new BlockPos(tX, tY, tZ)))) {
|
|
|
|
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);
|
|
|
|
BlockPos randPos = new BlockPos(eX, eY, eZ);
|
|
|
|
if ((var39 * var39 + var42 * var42 + var45 * var45 < 1.0D) && mWorld.isAirBlock(randPos)) {
|
|
|
|
int ranOre = aRandom.nextInt(50);
|
|
|
|
if (ranOre < 3) {
|
2017-06-11 13:26:28 +00:00
|
|
|
BlockGeneratedOres.setOreBlock(mWorld, randPos, primaryMeta, false);
|
2016-09-22 15:00:27 +00:00
|
|
|
} else if (ranOre < 6) {
|
2017-06-11 13:26:28 +00:00
|
|
|
BlockGeneratedOres.setOreBlock(mWorld, randPos, secondaryMeta, false);
|
2016-09-22 15:00:27 +00:00
|
|
|
} else if (ranOre < 8) {
|
2017-06-11 13:26:28 +00:00
|
|
|
BlockGeneratedOres.setOreBlock(mWorld, randPos, betweenMeta, false);
|
2016-09-22 15:00:27 +00:00
|
|
|
} else if (ranOre < 10) {
|
2017-06-11 13:26:28 +00:00
|
|
|
BlockGeneratedOres.setOreBlock(mWorld, randPos, sporadicMeta, false);
|
2016-09-22 15:00:27 +00:00
|
|
|
} else {
|
2016-12-28 20:16:39 +00:00
|
|
|
if (tDimensionType == -1) {
|
|
|
|
mWorld.setBlockState(randPos, Blocks.END_STONE.getDefaultState());
|
|
|
|
} else if (tDimensionName.equals("Asteroids")) {
|
|
|
|
mWorld.setBlockState(randPos, GregTech_API.sBlockGranites.getDefaultState());
|
|
|
|
}
|
2015-10-22 02:06:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-23 22:29:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 15:00:27 +00:00
|
|
|
|
2016-12-28 20:16:39 +00:00
|
|
|
}
|