GT5-Unofficial/src/main/java/gregtech/common/GT_Worldgen_Stone.java

91 lines
6.1 KiB
Java
Raw Normal View History

2015-06-23 22:29:05 +00:00
package gregtech.common;
import gregtech.api.GregTech_API;
import gregtech.api.world.GT_Worldgen_Ore;
2016-09-22 15:00:27 +00:00
import gregtech.api.world.GT_Worldgen_Constants;
import gregtech.common.blocks.GT_Block_Ores_Abstract;
2015-06-23 22:29:05 +00:00
import gregtech.common.blocks.GT_TileEntity_Ores;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
2015-06-23 22:29:05 +00:00
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
2015-06-23 22:29:05 +00:00
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkGenerator;
2015-06-23 22:29:05 +00:00
import net.minecraft.world.chunk.IChunkProvider;
2015-10-22 02:06:25 +00:00
import java.util.Collection;
import java.util.Random;
2015-06-23 22:29:05 +00:00
public class GT_Worldgen_Stone
2015-10-22 02:06:25 +00:00
extends GT_Worldgen_Ore {
public GT_Worldgen_Stone(String aName, boolean aDefault, Block aBlock, int aBlockMeta, int aDimensionType, int aAmount, int aSize, int aProbability, int aMinY, int aMaxY, Collection<String> aBiomeList, boolean aAllowToGenerateinVoid) {
super(aName, aDefault, aBlock, aBlockMeta, aDimensionType, aAmount, aSize, aProbability, aMinY, aMaxY, aBiomeList, aAllowToGenerateinVoid);
}
@Override
public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, int aChunkZ, IChunkGenerator aChunkGenerator, IChunkProvider aChunkProvider) {
2016-09-12 11:07:17 +00:00
if ((isDimensionAllowed(aWorld, aDimensionType, this.mDimensionType)) && ((this.mBiomeList.isEmpty()) || (this.mBiomeList.contains(aBiome))) && ((this.mProbability <= 1) || (aRandom.nextInt(this.mProbability) == 0))) {
2015-10-22 02:06:25 +00:00
for (int i = 0; i < this.mAmount; i++) {
int tX = aChunkX + aRandom.nextInt(16);
int tY = this.mMinY + aRandom.nextInt(this.mMaxY - this.mMinY);
int tZ = aChunkZ + aRandom.nextInt(16);
if ((this.mAllowToGenerateinVoid) || (!aWorld.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) * this.mSize / 8.0F;
double var9 = tX + 8 - MathHelper.sin(var6) * this.mSize / 8.0F;
double var11 = tZ + 8 + MathHelper.cos(var6) * this.mSize / 8.0F;
double var13 = tZ + 8 - MathHelper.cos(var6) * this.mSize / 8.0F;
double var15 = tY + aRandom.nextInt(3) - 2;
double var17 = tY + aRandom.nextInt(3) - 2;
for (int var19 = 0; var19 <= this.mSize; var19++) {
double var20 = var7 + (var9 - var7) * var19 / this.mSize;
double var22 = var15 + (var17 - var15) * var19 / this.mSize;
double var24 = var11 + (var13 - var11) * var19 / this.mSize;
double var26 = aRandom.nextDouble() * this.mSize / 16.0D;
double var28 = (MathHelper.sin(var19 * 3.141593F / this.mSize) + 1.0F) * var26 + 1.0D;
double var30 = (MathHelper.sin(var19 * 3.141593F / this.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);
if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D) {
BlockPos randPos = new BlockPos(eX, eY, eZ);
IBlockState tTargetedBlock = aWorld.getBlockState(randPos);
if (tTargetedBlock instanceof GT_Block_Ores_Abstract) {
TileEntity tTileEntity = aWorld.getTileEntity(randPos);
2015-10-22 02:06:25 +00:00
if ((tTileEntity instanceof GT_TileEntity_Ores)) {
if (tTargetedBlock != GregTech_API.sBlockOres1) {
((GT_TileEntity_Ores) tTileEntity).convertOreBlock(aWorld, eX, eY, eZ);
}
2016-07-22 03:31:57 +00:00
((GT_TileEntity_Ores)tTileEntity).overrideOreBlockMaterial(this.mBlock, (byte) this.mBlockMeta);
2015-10-22 02:06:25 +00:00
}
} else if ((this.mAllowToGenerateinVoid && aWorld.isAirBlock(randPos)) ||
2016-09-22 15:00:27 +00:00
(tTargetedBlock != null && tTargetedBlock.getBlock().isReplaceableOreGen(tTargetedBlock, aWorld, randPos, GT_Worldgen_Constants.ANY))) {
aWorld.setBlockState(randPos, this.mBlock.getStateFromMeta(mBlockMeta));
2015-10-22 02:06:25 +00:00
}
}
}
}
}
}
2015-06-23 22:29:05 +00:00
}
}
}
}
2015-10-22 02:06:25 +00:00
return true;
2015-06-23 22:29:05 +00:00
}
2015-10-22 02:06:25 +00:00
return false;
2015-06-23 22:29:05 +00:00
}
}