From e15136ba1a3cf7cc110dedb776428b97ece94faa Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Wed, 15 Nov 2017 01:35:17 -0600 Subject: Feature complete. Ready for testing in multiple dimensions. --- .../gregtech/common/GT_Worldgen_GT_Ore_Layer.java | 34 ++---- .../common/GT_Worldgen_GT_Ore_SmallPieces.java | 13 +- .../java/gregtech/common/GT_Worldgen_Stone.java | 135 +++++++++++++++++---- .../java/gregtech/common/GT_Worldgenerator.java | 18 +-- 4 files changed, 141 insertions(+), 59 deletions(-) (limited to 'src/main/java/gregtech/common') diff --git a/src/main/java/gregtech/common/GT_Worldgen_GT_Ore_Layer.java b/src/main/java/gregtech/common/GT_Worldgen_GT_Ore_Layer.java index edb1fa020d..86d140d6b5 100644 --- a/src/main/java/gregtech/common/GT_Worldgen_GT_Ore_Layer.java +++ b/src/main/java/gregtech/common/GT_Worldgen_GT_Ore_Layer.java @@ -16,7 +16,6 @@ import java.util.ArrayList; import java.util.Random; import static gregtech.api.enums.GT_Values.debugOrevein; -import static gregtech.api.enums.GT_Values.debugWorldGen; public class GT_Worldgen_GT_Ore_Layer extends GT_Worldgen { @@ -97,11 +96,9 @@ public class GT_Worldgen_GT_Ore_Layer public int executeWorldgenChunkified(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, int aChunkZ, int aSeedX, int aSeedZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { if( mWorldGenName.equals("NoOresInVein") ) { - /* if (debugOrevein) GT_Log.out.println( - " NoOresInVein, skipping" + " NoOresInVein" ); - */ // This is a special empty orevein return ORE_PLACED; } @@ -116,39 +113,35 @@ public class GT_Worldgen_GT_Ore_Layer int[] placeCount=new int[4]; // Need to "reseed" RNG with values based on the orevein constants so that two oreveins at this same chunk don't end up trying the same sizes and offsets. - aRandom.nextInt( this.mPrimaryMeta + this.mSecondaryMeta + this.mSporadicMeta + this.mBetweenMeta + aChunkX + aChunkZ); + aRandom.nextInt( this.mPrimaryMeta + this.mSecondaryMeta + this.mSporadicMeta + this.mBetweenMeta + Math.abs(aChunkX + aChunkZ)); int tMinY = mMinY + aRandom.nextInt(mMaxY - mMinY - 5); // Determine West/East ends of orevein int wXVein = aSeedX - aRandom.nextInt(mSize); // West side int eXVein = aSeedX + 16 + aRandom.nextInt(mSize); // Limit Orevein to only blocks present in current chunk - int wX = Math.max( wXVein, aChunkX); - int eX = Math.min( eXVein, aChunkX + 16); + int wX = Math.max( wXVein, aChunkX + 2); // Bias placement by 2 blocks to prevent worldgen cascade. + int eX = Math.min( eXVein, aChunkX + 2 + 16); if (wX >= eX) { //No overlap between orevein and this chunk exists in X -/* if (debugOrevein) { - System.out.println( - "No overlap in X dim!" + GT_Log.out.println( + "No X overlap" ); } -*/ return NO_OVERLAP; } // Determine North/Sound ends of orevein int nZVein = aSeedZ - aRandom.nextInt(mSize); int sZVein = aSeedZ + 16 + aRandom.nextInt(mSize); - int nZ = Math.max(nZVein, aChunkZ); - int sZ = Math.min(sZVein, aChunkZ + 16); + int nZ = Math.max(nZVein, aChunkZ + 2); // Bias placement by 2 blocks to prevent worldgen cascade. + int sZ = Math.min(sZVein, aChunkZ + 2 + 16); if (nZ >= sZ) { //No overlap between orevein and this chunk exists in Z -/* if (debugOrevein) { - System.out.println( - "No overlap in Z dim!" + GT_Log.out.println( + "No Z overlap" ); } -*/ return NO_OVERLAP; } // Adjust the density down the more chunks we are away from the oreseed. The 5 chunks surrounding the seed should always be max density due to truncation of Math.sqrt(). @@ -173,12 +166,9 @@ public class GT_Worldgen_GT_Ore_Layer } } if ((placeCount[1]+placeCount[3])==0) { -/* - GT_Log.out.println( - "Generated Orevein:" + this.mWorldGenName + - " did not place any ores in bottom layer, skipping" + if (debugOrevein) GT_Log.out.println( + " No ore in bottom layer" ); -*/ return NO_ORE_IN_BOTTOM_LAYER; // Exit early, didn't place anything in the bottom layer } for (level = tMinY; level < (tMinY-1+3); level++) { diff --git a/src/main/java/gregtech/common/GT_Worldgen_GT_Ore_SmallPieces.java b/src/main/java/gregtech/common/GT_Worldgen_GT_Ore_SmallPieces.java index a299698f6d..35d619dad5 100644 --- a/src/main/java/gregtech/common/GT_Worldgen_GT_Ore_SmallPieces.java +++ b/src/main/java/gregtech/common/GT_Worldgen_GT_Ore_SmallPieces.java @@ -47,10 +47,11 @@ public class GT_Worldgen_GT_Ore_SmallPieces return false; } int count=0; + if (this.mMeta > 0) { - int i = 0; - for (int j = Math.max(1, this.mAmount / 2 + aRandom.nextInt(this.mAmount) / 2); i < j; i++) { - GT_TileEntity_Ores.setOreBlock(aWorld, aChunkX + aRandom.nextInt(16), this.mMinY + aRandom.nextInt(Math.max(1, this.mMaxY - this.mMinY)), aChunkZ + aRandom.nextInt(16), this.mMeta, true); + int j = Math.max(1, this.mAmount / 2 + aRandom.nextInt(this.mAmount) / 2); + for ( int i = 0; i < j; i++) { + GT_TileEntity_Ores.setOreBlock(aWorld, aChunkX + 8 + aRandom.nextInt(16), this.mMinY + aRandom.nextInt(Math.max(1, this.mMaxY - this.mMinY)), aChunkZ + 8 + aRandom.nextInt(16), this.mMeta, true); count++; } } @@ -58,9 +59,9 @@ public class GT_Worldgen_GT_Ore_SmallPieces GT_Log.out.println( "Small Ore:" + this.mWorldGenName + " @ dim="+aDimensionType+ - " chunkX="+aChunkX+ - " chunkZ="+aChunkZ+ - " ore="+count+" "+new ItemStack(GregTech_API.sBlockOres1,1,mMeta).getDisplayName() + " mX="+aChunkX/16+ + " mZ="+aChunkZ/16+ + " ore="+count ); } return true; diff --git a/src/main/java/gregtech/common/GT_Worldgen_Stone.java b/src/main/java/gregtech/common/GT_Worldgen_Stone.java index c22585d26a..d7ee1d0bfd 100644 --- a/src/main/java/gregtech/common/GT_Worldgen_Stone.java +++ b/src/main/java/gregtech/common/GT_Worldgen_Stone.java @@ -1,6 +1,8 @@ package gregtech.common; import gregtech.api.GregTech_API; +import gregtech.api.objects.XSTR; +import gregtech.api.util.GT_Log; import gregtech.api.world.GT_Worldgen_Ore; import gregtech.common.blocks.GT_Block_Ores_Abstract; import gregtech.common.blocks.GT_TileEntity_Ores; @@ -13,37 +15,116 @@ import net.minecraft.world.chunk.IChunkProvider; import java.util.Collection; import java.util.Random; +import java.util.Hashtable; +import java.util.ArrayList; + +import static gregtech.api.enums.GT_Values.debugStones; public class GT_Worldgen_Stone extends GT_Worldgen_Ore { + + public Hashtable validStoneSeeds = new Hashtable(1024); + + class StoneSeeds { + public boolean mExists; + + StoneSeeds( boolean exists ) { + mExists = exists; + } + }; + + class ValidSeeds { + public int mX; + public int mZ; + ValidSeeds( int x, int z) { + this.mX = x; + this.mZ = z; + } + }; 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 aBiomeList, boolean aAllowToGenerateinVoid) { super(aName, aDefault, aBlock, aBlockMeta, aDimensionType, aAmount, aSize, aProbability, aMinY, aMaxY, aBiomeList, aAllowToGenerateinVoid); } public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - if ((isGenerationAllowed(aWorld, aDimensionType, this.mDimensionType)) && ((this.mBiomeList.isEmpty()) || (this.mBiomeList.contains(aBiome))) && ((this.mProbability <= 1) || (aRandom.nextInt(this.mProbability) == 0))) { + XSTR stoneRNG = new XSTR(); + ArrayList stones = new ArrayList(); + + if ( !isGenerationAllowed(aWorld, aDimensionType, this.mDimensionType)) { + return false; + } + if ( !(this.mBiomeList.isEmpty() || this.mBiomeList.contains(aBiome)) ) { + return false; + } + int windowWidth = (mSize/8)/16 + 1; // Width of chunks to check for a potential stoneseed (I think the real size of the balls is mSize/8, but the code below is difficult to understand) + // Check stone seeds to see if they have been added + for( int x = aChunkX/16 - windowWidth; x < (aChunkX/16 + windowWidth + 1); x++ ) { + for( int z = aChunkZ/16 - windowWidth; z < (aChunkZ/16 + windowWidth + 1); z++ ) { + long hash = (( (long)x << 32) | ( (long)z & 0x00000000ffffffffL )); + if( !validStoneSeeds.containsKey(hash) ) { + // Determine if RNG says to add stone at this chunk + stoneRNG.setSeed((long)aWorld.getSeed() ^ hash); + if ( (this.mProbability <= 1) || (aRandom.nextInt(this.mProbability) == 0) ) { + // Add stone at this chunk + validStoneSeeds.put( hash, new StoneSeeds(true) ); + // Add to generation list + stones.add( new ValidSeeds(x,z) ); + if (debugStones) GT_Log.out.println( + "New stoneseed x="+x+ + " z="+z+ + " mSize="+mSize + ); + } else { + validStoneSeeds.put( hash, new StoneSeeds(false) ); + } + } else { + // This chunk has already been checked, check to see if a boulder exists here + if( validStoneSeeds.get(hash).mExists ) { + // Add to generation list + stones.add( new ValidSeeds(x,z) ); + } + } + } + } + + boolean result = true; + if (stones.size() == 0) { + result = false; + } + // Now process each oreseed vs this requested chunk + for( ; stones.size() != 0; stones.remove(0) ) { + int x = stones.get(0).mX*16; + int z = stones.get(0).mZ*16; + + stoneRNG.setSeed((long)aWorld.getSeed() ^ (( (long)x << 32) | ( (long)z & 0x00000000ffffffffL ))); + 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.getBlock(tX, tY, tZ).isAir(aWorld, tX, tY, tZ))) { + int tX = x + stoneRNG.nextInt(16); + int tY = this.mMinY + stoneRNG.nextInt(this.mMaxY - this.mMinY); + int tZ = z + stoneRNG.nextInt(16); + if ((this.mAllowToGenerateinVoid) || (!aWorld.getBlock(tX, tY, tZ).isAir(aWorld, tX, tY, tZ))) { // Causes slight amount of worldgen cascade since it may load a chunk that is far away. float math_pi = 3.141593F;//FB: CNT - CNT_ROUGH_CONSTANT_VALUE - float var6 = aRandom.nextFloat() * math_pi; - float var1d = this.mSize / 8.0F;int var2d = tX + 8;int var3d = tZ + 8;int var4d = tY - 2; - float mh_s_0 = MathHelper.sin(var6) * var1d;float mh_c_0 = MathHelper.cos(var6) * var1d; + float var6 = stoneRNG.nextFloat() * math_pi; + float var1d = this.mSize / 8.0F; + int var2d = tX + 8; + int var3d = tZ + 8; + int var4d = tY - 2; + float mh_s_0 = MathHelper.sin(var6) * var1d; + float mh_c_0 = MathHelper.cos(var6) * var1d; float var7 = var2d + mh_s_0; float var11 = var3d + mh_c_0; - int var15r = aRandom.nextInt(3);int var17r = aRandom.nextInt(3); + int var15r = stoneRNG.nextInt(3); + int var17r = stoneRNG.nextInt(3); int var15 = var4d + var15r; int mh_n_4=var17r - var15r; - float mh_n_0 = -2*mh_s_0;float mh_n_1 = -2*mh_c_0; + float mh_n_0 = -2*mh_s_0; + float mh_n_1 = -2*mh_c_0; for (int var19 = 0; var19 <= this.mSize; var19++) { float var5d = var19 / this.mSize; float var20 = var7 + mh_n_0 * var5d; float var22 = var15 + mh_n_4 * var5d; float var24 = var11 + mh_n_1 * var5d; float var6d = var19 * math_pi / this.mSize; - float var26 = aRandom.nextFloat() * this.mSize / 16.0F; + float var26 = stoneRNG.nextFloat() * this.mSize / 16.0F; float var28 = ((MathHelper.sin(var6d) + 1.0F) * var26 + 1.0F) / 2.0F; int tMinX = MathHelper.floor_float(var20 - var28); int tMinY = MathHelper.floor_float(var22 - var28); @@ -51,28 +132,35 @@ public class GT_Worldgen_Stone int tMaxX = MathHelper.floor_float(var20 + var28); int tMaxY = MathHelper.floor_float(var22 + var28); int tMaxZ = MathHelper.floor_float(var24 + var28); - for (int eX = tMinX; eX <= tMaxX; eX++) { - float var39 = (eX + 0.5F - var20) / (var28); + + int wX = Math.max( tMinX, aChunkX + 8); + int eX = Math.min( tMaxX, aChunkX + 8 + 16 ); + + int sZ = Math.max( tMinZ, aChunkZ + 8); + int nZ = Math.min( tMaxZ, aChunkZ + 8 + 16 ); + + for (int iX = wX; iX < eX; iX++) { + float var39 = (iX + 0.5F - var20) / (var28); float var10d = var39 * var39; if (var10d < 1.0F) { - for (int eY = tMinY; eY <= tMaxY; eY++) { - float var42 = (eY + 0.5F - var22) / (var28); + for (int iY = tMinY; iY <= tMaxY; iY++) { + float var42 = (iY + 0.5F - var22) / (var28); float var12d = var10d + var42 * var42; if (var12d < 1.0F) { - for (int eZ = tMinZ; eZ <= tMaxZ; eZ++) { - float var45 = (eZ + 0.5F - var24) / (var28); + for (int iZ = sZ; iZ < nZ; iZ++) { + float var45 = (iZ + 0.5F - var24) / (var28); if (var12d + var45 * var45 < 1.0F) { - Block tTargetedBlock = aWorld.getBlock(eX, eY, eZ); + Block tTargetedBlock = aWorld.getBlock(iX, iY, iZ); if (tTargetedBlock instanceof GT_Block_Ores_Abstract) { - TileEntity tTileEntity = aWorld.getTileEntity(eX, eY, eZ); + TileEntity tTileEntity = aWorld.getTileEntity(iX, iY, iZ); if ((tTileEntity instanceof GT_TileEntity_Ores)) { if (tTargetedBlock != GregTech_API.sBlockOres1) { - ((GT_TileEntity_Ores) tTileEntity).convertOreBlock(aWorld, eX, eY, eZ); + ((GT_TileEntity_Ores) tTileEntity).convertOreBlock(aWorld, iX, iY, iZ); } ((GT_TileEntity_Ores)tTileEntity).overrideOreBlockMaterial(this.mBlock, (byte) this.mBlockMeta); } - } else if (((this.mAllowToGenerateinVoid) && (aWorld.getBlock(eX, eY, eZ).isAir(aWorld, eX, eY, eZ))) || ((tTargetedBlock != null) && ((tTargetedBlock.isReplaceableOreGen(aWorld, eX, eY, eZ, Blocks.stone)) || (tTargetedBlock.isReplaceableOreGen(aWorld, eX, eY, eZ, Blocks.end_stone)) || (tTargetedBlock.isReplaceableOreGen(aWorld, eX, eY, eZ, Blocks.netherrack)) || (tTargetedBlock.isReplaceableOreGen(aWorld, eX, eY, eZ, GregTech_API.sBlockGranites)) || (tTargetedBlock.isReplaceableOreGen(aWorld, eX, eY, eZ, GregTech_API.sBlockStones))))) { - aWorld.setBlock(eX, eY, eZ, this.mBlock, this.mBlockMeta, 0); + } else if (((this.mAllowToGenerateinVoid) && (aWorld.getBlock(iX, iY, iZ).isAir(aWorld, iX, iY, iZ))) || ((tTargetedBlock != null) && ((tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.stone)) || (tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.end_stone)) || (tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, Blocks.netherrack)) || (tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, GregTech_API.sBlockGranites)) || (tTargetedBlock.isReplaceableOreGen(aWorld, iX, iY, iZ, GregTech_API.sBlockStones))))) { + aWorld.setBlock(iX, iY, iZ, this.mBlock, this.mBlockMeta, 0); } } } @@ -83,8 +171,7 @@ public class GT_Worldgen_Stone } } } - return true; } - return false; + return result; } } diff --git a/src/main/java/gregtech/common/GT_Worldgenerator.java b/src/main/java/gregtech/common/GT_Worldgenerator.java index 019917a148..60fa422d6a 100644 --- a/src/main/java/gregtech/common/GT_Worldgenerator.java +++ b/src/main/java/gregtech/common/GT_Worldgenerator.java @@ -173,7 +173,7 @@ implements IWorldGenerator { int placementResult = tWorldGen.executeWorldgenChunkified(this.mWorld, new XSTR( oreveinSeed ), this.mBiome, this.mDimensionType, this.mX*16, this.mZ*16, oreseedX*16, oreseedZ*16, this.mChunkGenerator, this.mChunkProvider); switch(placementResult) { case GT_Worldgen_GT_Ore_Layer.ORE_PLACED: - if (debugWorldGen) GT_Log.out.println( + if (debugOrevein) GT_Log.out.println( " Added oreveinSeed=" + oreveinSeed + " mX="+ this.mX + " mZ="+ this.mZ + @@ -196,7 +196,7 @@ implements IWorldGenerator { } break; // Try the next orevein } catch (Throwable e) { - if (debugWorldGen) GT_Log.out.println( + if (debugOrevein) GT_Log.out.println( "Exception occurred on oreVein" + tWorldGen + " oreveinSeed="+ oreveinSeed + " mX="+ this.mX + @@ -211,7 +211,7 @@ implements IWorldGenerator { } // Only add an empty orevein if are unable to place a vein at the oreseed chunk. if ((!oreveinFound) && (this.mX == oreseedX) && (this.mZ == oreseedZ)){ - if (debugWorldGen) GT_Log.out.println( + if (debugOrevein) GT_Log.out.println( " Empty oreveinSeed="+ oreveinSeed + " mX="+ this.mX + " mZ="+ this.mZ + @@ -224,7 +224,7 @@ implements IWorldGenerator { validOreveins.put(oreveinSeed, noOresInVein ); } } else if(oreveinPercentageRoll >= oreveinPercentage) { - if (debugWorldGen) GT_Log.out.println( + if (debugOrevein) GT_Log.out.println( " Skipped oreveinSeed="+ oreveinSeed + " mX="+ this.mX + " mZ="+ this.mZ + @@ -238,7 +238,7 @@ implements IWorldGenerator { } }else { // oreseed is located in the previously processed table - if (debugWorldGen) GT_Log.out.print( + if (debugOrevein) GT_Log.out.print( " Valid oreveinSeed="+ oreveinSeed + " validOreveins.size()=" + validOreveins.size() + " " ); @@ -268,15 +268,19 @@ implements IWorldGenerator { } // Now process each oreseed vs this requested chunk - for( ; seedList.size() != 0; ) { + for( ; seedList.size() != 0; seedList.remove(0) ) { worldGenFindVein( seedList.get(0).mX, seedList.get(0).mZ ); - seedList.remove(0); } // Do leftover worldgen for this chunk (GT_Stones and GT_small_ores) try { for (GT_Worldgen tWorldGen : GregTech_API.sWorldgenList) { + /* + if (debugWorldGen) GT_Log.out.println( + "tWorldGen.mWorldGenName="+tWorldGen.mWorldGenName + ); + */ tWorldGen.executeWorldgen(this.mWorld, this.mRandom, this.mBiome, this.mDimensionType, this.mX*16, this.mZ*16, this.mChunkGenerator, this.mChunkProvider); } } catch (Throwable e) { -- cgit