From 376f7c63f6d7ea9df0b967e9dc1ecbd710370307 Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Sun, 12 Nov 2017 21:27:13 -0600 Subject: First pass at chunkifying oreveins --- .../gregtech/common/GT_Worldgen_GT_Ore_Layer.java | 221 ++++++++++++++++----- .../java/gregtech/common/GT_Worldgenerator.java | 209 ++++++++++++++++--- .../gregtech/common/blocks/GT_TileEntity_Ores.java | 57 +++--- 3 files changed, 373 insertions(+), 114 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 dcc256498b..11772e8fd6 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 @@ -37,6 +37,13 @@ public class GT_Worldgen_GT_Ore_Layer public final boolean mNether; public final boolean mEnd; public final boolean mEndAsteroid; + public static final int WRONG_BIOME=0; + public static final int WRONG_DIMENSION=1; + public static final int NO_ORE_IN_BOTTOM_LAYER=2; + public static final int NO_OVERLAP=3; + public static final int ORE_PLACED=4; + + //public final boolean mMoon; //public final boolean mMars; //public final boolean mAsteroid; @@ -88,69 +95,173 @@ public class GT_Worldgen_GT_Ore_Layer } } - public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - if (!this.mRestrictBiome.equals("None") && !(this.mRestrictBiome.equals(aBiome))) { - return false; //Not the correct biome for ore mix - } + public int executeWorldgenChunkified(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, int aChunkZ, int aSeedX, int aSeedZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { //if (!isGenerationAllowed(aWorld, aDimensionType, ((aDimensionType == -1) && (this.mNether)) || ((aDimensionType == 0) && (this.mOverworld)) || ((aDimensionType == 1) && (this.mEnd)) || ((aWorld.provider.getDimensionName().equals("Moon")) && (this.mMoon)) || ((aWorld.provider.getDimensionName().equals("Mars")) && (this.mMars)) ? aDimensionType : aDimensionType ^ 0xFFFFFFFF)) { if (!isGenerationAllowed(aWorld, aDimensionType, ((aDimensionType == -1) && (this.mNether)) || ((aDimensionType == 0) && (this.mOverworld)) || ((aDimensionType == 1) && (this.mEnd)) ? aDimensionType : aDimensionType ^ 0xFFFFFFFF)) { - return false; + return WRONG_DIMENSION; } - int tMinY = this.mMinY + aRandom.nextInt(this.mMaxY - this.mMinY - 5); - - int cX = aChunkX - aRandom.nextInt(this.mSize); - int eX = aChunkX + 16 + aRandom.nextInt(this.mSize); - - int[] placeCount=new int[4]; - for (int tX = cX; tX <= eX; tX++) { - int cZ = aChunkZ - aRandom.nextInt(this.mSize); - int eZ = aChunkZ + 16 + aRandom.nextInt(this.mSize); - for (int tZ = cZ; tZ <= eZ; tZ++) { - if (this.mSecondaryMeta > 0) { - for (int i = tMinY - 1; i < tMinY + 2; i++) { - if ((aRandom.nextInt(Math.max(1, Math.max(MathHelper.abs_int(cZ - tZ), MathHelper.abs_int(eZ - tZ)) / this.mDensity)) == 0) || (aRandom.nextInt(Math.max(1, Math.max(MathHelper.abs_int(cX - tX), MathHelper.abs_int(eX - tX)) / this.mDensity)) == 0)) { - if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, i, tZ, this.mSecondaryMeta, false)) - placeCount[1]++; - } - } - } - if ((this.mBetweenMeta > 0) && ((aRandom.nextInt(Math.max(1, Math.max(MathHelper.abs_int(cZ - tZ), MathHelper.abs_int(eZ - tZ)) / this.mDensity)) == 0) || (aRandom.nextInt(Math.max(1, Math.max(MathHelper.abs_int(cX - tX), MathHelper.abs_int(eX - tX)) / this.mDensity)) == 0))) { - if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, tMinY + 2 + aRandom.nextInt(2), tZ, this.mBetweenMeta, false)) - placeCount[2]++; - } - if (this.mPrimaryMeta > 0) { - for (int i = tMinY + 3; i < tMinY + 6; i++) { - if ((aRandom.nextInt(Math.max(1, Math.max(MathHelper.abs_int(cZ - tZ), MathHelper.abs_int(eZ - tZ)) / this.mDensity)) == 0) || (aRandom.nextInt(Math.max(1, Math.max(MathHelper.abs_int(cX - tX), MathHelper.abs_int(eX - tX)) / this.mDensity)) == 0)) { - if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, i, tZ, this.mPrimaryMeta, false)) - placeCount[0]++; - } - } - } - if ((this.mSporadicMeta > 0) && ((aRandom.nextInt(Math.max(1, Math.max(MathHelper.abs_int(cZ - tZ), MathHelper.abs_int(eZ - tZ)) / this.mDensity)) == 0) || (aRandom.nextInt(Math.max(1, Math.max(MathHelper.abs_int(cX - tX), MathHelper.abs_int(eX - tX)) / this.mDensity)) == 0))) { - if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, tMinY - 1 + aRandom.nextInt(7), tZ, this.mSporadicMeta, false)) - placeCount[3]++; - } - } + if (!this.mRestrictBiome.equals("None") && !(this.mRestrictBiome.equals(aBiome))) { + return WRONG_BIOME; //Not the correct biome for ore mix } + 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); + + 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); + if (wX >= eX) { //No overlap between orevein and this chunk exists in X +/* + if (debugOrevein) { + System.out.println( + "No overlap in X dim!" + ); + } +*/ + 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); + if (nZ >= sZ) { //No overlap between orevein and this chunk exists in Z +/* + if (debugOrevein) { + System.out.println( + "No overlap in Z dim!" + ); + } +*/ + return NO_OVERLAP; + } + // Need to "reseed" RNG with values based on the chunkX/Z location so that filled chunks don't repeat the same RNG values + aRandom.nextInt( aChunkX + aChunkZ ); + + // To allow for early exit due to no ore placed in the bottom layer (probably because we are in the sky), unroll 1 pass through the loop + // Now we do bottom-level-first oregen, and work our way upwards. + int level = tMinY - 1; //Dunno why, but the first layer is actually played one below tMinY. Go figure. + for (int tX = wX; tX < eX; tX++) { + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))); + for (int tZ = nZ; tZ < sZ; tZ++) { + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))); + if ( ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSecondaryMeta > 0) ) { + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSecondaryMeta, false, false)) { + placeCount[1]++; + } + } + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) + placeCount[3]++; + } + } + } + if ((placeCount[1]+placeCount[3])==0) { +/* + GT_Log.out.println( + "Generated Orevein:" + this.mWorldGenName + + " did not place any ores in bottom layer, skipping" + ); +*/ + return NO_ORE_IN_BOTTOM_LAYER; // Exit early, didn't place anything in the bottom layer + } + for (level = tMinY; level < (tMinY-1+3); level++) { + for (int tX = wX; tX < eX; tX++) { + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))); + for (int tZ = nZ; tZ < sZ; tZ++) { + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))); + if ( ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSecondaryMeta > 0) ) { + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSecondaryMeta, false, false)) { + placeCount[1]++; + } + } + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) + placeCount[3]++; + } + } + } + } + // Low Middle layer is between + sporadic + // level should be = tMinY-1+3 from end of for loop + for (int tX = wX; tX < eX; tX++) { + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))); + for (int tZ = nZ; tZ < sZ; tZ++) { + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))); + if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mBetweenMeta > 0) ) { // Between are only 1 per vertical column, reduce by 1/2 to compensate + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mBetweenMeta, false, false)) { + placeCount[2]++; + } + } + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) + placeCount[3]++; + } + } + } + // High Middle layer is between + primary + sporadic + level++; // Increment level to next layer + for (int tX = wX; tX < eX; tX++) { + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))); + for (int tZ = nZ; tZ < sZ; tZ++) { + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))); + if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mBetweenMeta > 0) ) { // Between are only 1 per vertical column, reduce by 1/2 to compensate + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mBetweenMeta, false, false)) { + placeCount[2]++; + } + } + else if ( ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mPrimaryMeta > 0) ) { + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mPrimaryMeta, false, false)) { + placeCount[0]++; + } + } + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) + placeCount[3]++; + } + } + } + // Top two layers are primary + sporadic + level++; // Increment level to next layer + for( ; level < (tMinY + 6); level++){ // should do two layers + for (int tX = wX; tX < eX; tX++) { + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))); + for (int tZ = nZ; tZ < sZ; tZ++) { + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))); + if ( ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mPrimaryMeta > 0) ) { + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mPrimaryMeta, false, false)) { + placeCount[0]++; + } + } + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) + placeCount[3]++; + } + } + } + } if (debugOrevein) { String tDimensionName = aWorld.provider.getDimensionName(); GT_Log.out.println( "Generated Orevein:" + this.mWorldGenName + - " chunkX="+aChunkX+ - " chunkZ="+aChunkZ+ - " chunkY="+tMinY+ - " Density=" + this.mDensity + - " Secondary="+placeCount[1]+" "+new ItemStack(GregTech_API.sBlockOres1,1,mSecondaryMeta).getDisplayName()+ - " Between="+placeCount[2]+" "+new ItemStack(GregTech_API.sBlockOres1,1,mBetweenMeta).getDisplayName()+ - " Primary="+placeCount[0]+" "+new ItemStack(GregTech_API.sBlockOres1,1,mPrimaryMeta).getDisplayName()+ - " Sporadic="+placeCount[3]+" "+new ItemStack(GregTech_API.sBlockOres1,1,mSporadicMeta).getDisplayName() + - " Dimension=" + tDimensionName + " Dimension=" + tDimensionName + + " cX="+aChunkX+ + " cZ="+aChunkZ+ + " cY="+tMinY+ + " Den=" + this.mDensity + + " Sec="+placeCount[1]+ + " Spo="+placeCount[3]+ + " Bet="+placeCount[2]+ + " Pri="+placeCount[0] ); - } - // Didn't place anything, return false - if( (placeCount[0] + placeCount[1] + placeCount[2] + placeCount[3]) == 0 ) - return false; - else - return true; + } + // Something (at least the bottom layer must have 1 block) must have been placed, return true + return ORE_PLACED; } } diff --git a/src/main/java/gregtech/common/GT_Worldgenerator.java b/src/main/java/gregtech/common/GT_Worldgenerator.java index f42bc4ef1b..789abbc070 100644 --- a/src/main/java/gregtech/common/GT_Worldgenerator.java +++ b/src/main/java/gregtech/common/GT_Worldgenerator.java @@ -20,16 +20,21 @@ import static gregtech.api.enums.GT_Values.oreveinPercentage; import static gregtech.api.enums.GT_Values.debugWorldGen; import static gregtech.api.enums.GT_Values.debugOrevein; import static gregtech.api.enums.GT_Values.oreveinAttempts; +import static gregtech.api.enums.GT_Values.oreveinMaxPlacementAttempts; +import static gregtech.api.enums.GT_Values.oreveinMaxSize; +import gregtech.api.enums.Materials; + import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.HashSet; +import java.util.Hashtable; import static gregtech.api.enums.GT_Values.D1; public class GT_Worldgenerator - implements IWorldGenerator { +implements IWorldGenerator { //public static boolean sAsteroids = true; private static int mEndAsteroidProbability = 300; //private static int mGCAsteroidProbability = 50; @@ -39,8 +44,11 @@ public class GT_Worldgenerator //private static int gcMinSize = 100; //private static int gcMaxSize = 400; private static boolean endAsteroids = true; - public List mList = new ArrayList(); - public HashSet ProcChunks = new HashSet(); + public static List mList = new ArrayList(); + public static HashSet ProcChunks = new HashSet(); + // This is probably not going to work. Trying to create a fake orevein to put into hashtable when there will be no ores in a vein. + public static GT_Worldgen_GT_Ore_Layer noOresInVein = new GT_Worldgen_GT_Ore_Layer( "NoOresInVein", false, 0, 100, 0, 0, 0, false, false, false, false, false, false, Materials._NULL, Materials._NULL, Materials._NULL, Materials._NULL); + public static Hashtable validOreveins = new Hashtable(1024); public boolean mIsGenerating = false; public static final Object listLock = new Object(); //private static boolean gcAsteroids = true; @@ -63,27 +71,34 @@ public class GT_Worldgenerator } } - public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - this.mList.add(new WorldGenContainer(new XSTR(aRandom.nextInt()), aX * 16, aZ * 16, ((aChunkGenerator instanceof ChunkProviderEnd)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.sky) ? 1 : ((aChunkGenerator instanceof ChunkProviderHell)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.hell) ? -1 : 0, aWorld, aChunkGenerator, aChunkProvider, aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8).biomeName)); + synchronized (listLock) + { + if (!this.ProcChunks.contains( ((long)aX << 32) | ((long)(aZ) & 0x00000000ffffffffL)) ) { + this.ProcChunks.add( ((long)aX << 32) | ((long)(aZ) & 0x00000000ffffffffL)); + this.mList.add(new WorldGenContainer(new XSTR(aRandom.nextInt()), aX, aZ, ((aChunkGenerator instanceof ChunkProviderEnd)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.sky) ? 1 : ((aChunkGenerator instanceof ChunkProviderHell)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.hell) ? -1 : 0, aWorld, aChunkGenerator, aChunkProvider, aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8).biomeName)); + if (debugWorldGen) {GT_Log.out.println("ADD WorldGen chunk x:" + aX + " z:" + aZ + " SIZE: " + this.mList.size());} + } else { + if (debugWorldGen) {GT_Log.out.println("DUP WorldGen chunk x:" + aX + " z:" + aZ + " SIZE: " + this.mList.size() + " ProcChunks.size(): " + ProcChunks.size() ); } + } + } if (!this.mIsGenerating) { this.mIsGenerating = true; int mList_sS=this.mList.size(); for (int i = 0; i < mList_sS; i++) { - ((Runnable) this.mList.get(i)).run(); + WorldGenContainer toRun = (WorldGenContainer) this.mList.get(0); + if (debugWorldGen) {GT_Log.out.println("RUN WorldGen chunk x:" + toRun.mX + " z:" + toRun.mZ + " SIZE: " + this.mList.size() + " i: " + i );} + this.ProcChunks.remove( ((long)(toRun.mX) << 32) | ((long)(toRun.mZ) & 0x00000000ffffffffL)); + synchronized (listLock) + { + this.mList.remove(0); + } + toRun.run(); } - if (debugWorldGen) { - GT_Log.out.println( - "Tossing " + (this.mList.size() - mList_sS) + - " chunks!" - ); - } - this.mList.clear(); this.mIsGenerating = false; } } - //public synchronized void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) {//TODO CHECK??? // int tempDimensionId = aWorld.provider.dimensionId; // if (tempDimensionId != -1 && tempDimensionId != 1 && !aChunkGenerator.getClass().getName().contains("galacticraft")) { @@ -102,7 +117,18 @@ public class GT_Worldgenerator public final IChunkProvider mChunkGenerator; public final IChunkProvider mChunkProvider; public final String mBiome; + // Local class to track which orevein seeds must be checked when doing chunkified worldgen + class NearbySeeds { + public int mX; + public int mZ; + NearbySeeds( int x, int z) { + this.mX = x; + this.mZ = z; + } + }; + public static ArrayList seedList = new ArrayList(); + // aX and aZ are now the by-chunk X and Z for the chunk of interest public WorldGenContainer(Random aRandom, int aX, int aZ, int aDimensionType, World aWorld, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider, String aBiome) { this.mRandom = aRandom; this.mX = aX; @@ -114,10 +140,132 @@ public class GT_Worldgenerator this.mBiome = aBiome; } - public void run() { + public void worldGenFindVein( int oreseedX, int oreseedZ) { + Long oreveinSeed = this.mWorld.getSeed() ^ ( (long)oreseedX << 32) | ( (long)oreseedZ & 0x00000000ffffffffL ); // Use an RNG that is identical every time it is called for this oreseed + XSTR oreveinRNG = new XSTR( oreveinSeed ); + int oreveinPercentageRoll = oreveinRNG.nextInt(100); // Roll the dice, see if we get an orevein here at all + int noOrePlacedCount=0; String tDimensionName = ""; if (debugOrevein) { tDimensionName = this.mWorld.provider.getDimensionName(); } + + // Search for a valid orevein for this dimension + if( !validOreveins.containsKey(oreveinSeed) ) { + if ( (oreveinPercentageRoll 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) { + int placementAttempts = 0; + boolean oreveinFound = false; + int i; + + for( i = 0; (i < oreveinAttempts) && (!oreveinFound) && (placementAttempts 0) && ((tBlock != Blocks.air) || air)) { - if (BlockName.equals("tile.igneousStone")) { - if (GregTech_API.sBlockOresUb1 != null) { - tOreBlock = GregTech_API.sBlockOresUb1; - aMetaData += (BlockMeta * 1000); - //System.out.println("Block changed to UB1"); - } - } else if (BlockName.equals("tile.metamorphicStone")) { - if (GregTech_API.sBlockOresUb2 != null) { - tOreBlock = GregTech_API.sBlockOresUb2; - aMetaData += (BlockMeta * 1000); - //System.out.println("Block changed to UB2"); - } - } else if (BlockName.equals("tile.sedimentaryStone")) { - if (GregTech_API.sBlockOresUb3 != null) { - tOreBlock = GregTech_API.sBlockOresUb3; - aMetaData += (BlockMeta * 1000); - //System.out.println("Block changed to UB3"); - } - //} else if (BlockName.equals("tile.moonBlock") && (BlockMeta == 3 || BlockMeta == 4)) { - // if (GregTech_API.sBlockOresGC != null) { - // switch (BlockMeta) { - // case 3: tOreBlock = GregTech_API.sBlockOresGC; break; - // case 4: aMetaData += 1000; tOreBlock = GregTech_API.sBlockOresGC; break; - // } - // } - //} else if (BlockName.equals("tile.mars") && (BlockMeta == 6 || BlockMeta == 9)) { - // if (GregTech_API.sBlockOresGC != null) { - // switch (BlockMeta) { - // case 6: aMetaData += 2000; tOreBlock = GregTech_API.sBlockOresGC; break; - // case 9: aMetaData += 3000; tOreBlock = GregTech_API.sBlockOresGC; break; - // } - // } + if (tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.stone)) { + //Do nothing, stone background is default background. + //Do this comparison first since stone is most common } else if (tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.netherrack)) { aMetaData += 1000; } else if (tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.end_stone)) { @@ -107,7 +78,25 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit } else { aMetaData += 5000; } - } else if (!tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.stone)) { + } else if (BlockName.equals("tile.igneousStone")) { + if (GregTech_API.sBlockOresUb1 != null) { + tOreBlock = GregTech_API.sBlockOresUb1; + aMetaData += (BlockMeta * 1000); + //System.out.println("Block changed to UB1"); + } + } else if (BlockName.equals("tile.metamorphicStone")) { + if (GregTech_API.sBlockOresUb2 != null) { + tOreBlock = GregTech_API.sBlockOresUb2; + aMetaData += (BlockMeta * 1000); + //System.out.println("Block changed to UB2"); + } + } else if (BlockName.equals("tile.sedimentaryStone")) { + if (GregTech_API.sBlockOresUb3 != null) { + tOreBlock = GregTech_API.sBlockOresUb3; + aMetaData += (BlockMeta * 1000); + //System.out.println("Block changed to UB3"); + } + } else { return false; } //System.out.println(tOreBlock); -- cgit From 5cc6156d221f92b0226152a705b1da17e5177866 Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Mon, 13 Nov 2017 03:32:02 -0600 Subject: Cascading worldgen is being caused by something in other worldgen, possibly small ores or stones? Don't know for sure, need to investigate. --- .../gregtech/common/GT_Worldgen_GT_Ore_Layer.java | 77 +++++++++++++--------- .../java/gregtech/common/GT_Worldgenerator.java | 76 ++++++++++++++------- 2 files changed, 97 insertions(+), 56 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 11772e8fd6..a2b9c7e98e 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 @@ -96,6 +96,14 @@ 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" + ); + // This is a special empty orevein + return ORE_PLACED; + } + //if (!isGenerationAllowed(aWorld, aDimensionType, ((aDimensionType == -1) && (this.mNether)) || ((aDimensionType == 0) && (this.mOverworld)) || ((aDimensionType == 1) && (this.mEnd)) || ((aWorld.provider.getDimensionName().equals("Moon")) && (this.mMoon)) || ((aWorld.provider.getDimensionName().equals("Mars")) && (this.mMars)) ? aDimensionType : aDimensionType ^ 0xFFFFFFFF)) { if (!isGenerationAllowed(aWorld, aDimensionType, ((aDimensionType == -1) && (this.mNether)) || ((aDimensionType == 0) && (this.mOverworld)) || ((aDimensionType == 1) && (this.mEnd)) ? aDimensionType : aDimensionType ^ 0xFFFFFFFF)) { return WRONG_DIMENSION; @@ -106,15 +114,15 @@ 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); + aRandom.nextInt( this.mPrimaryMeta + this.mSecondaryMeta + this.mSporadicMeta + this.mBetweenMeta + 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 + 1); + int eX = Math.min( eXVein, aChunkX + 15); if (wX >= eX) { //No overlap between orevein and this chunk exists in X /* if (debugOrevein) { @@ -129,8 +137,8 @@ public class GT_Worldgen_GT_Ore_Layer 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 + 1); + int sZ = Math.min(sZVein, aChunkZ + 15); if (nZ >= sZ) { //No overlap between orevein and this chunk exists in Z /* if (debugOrevein) { @@ -141,22 +149,25 @@ public class GT_Worldgen_GT_Ore_Layer */ return NO_OVERLAP; } - // Need to "reseed" RNG with values based on the chunkX/Z location so that filled chunks don't repeat the same RNG values - aRandom.nextInt( aChunkX + aChunkZ ); - - // To allow for early exit due to no ore placed in the bottom layer (probably because we are in the sky), unroll 1 pass through the loop + if (debugOrevein) GT_Log.out.println( + "wX=" + wX + + " eX=" + eX + + " nZ=" + nZ + + " sZ=" + sZ + ); + // To allow for early exit due to no ore placed in the bottom layer (probably because we are in the sky), unroll 1 pass through the loop // Now we do bottom-level-first oregen, and work our way upwards. int level = tMinY - 1; //Dunno why, but the first layer is actually played one below tMinY. Go figure. for (int tX = wX; tX < eX; tX++) { - int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))); + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))/mDensity); for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))); - if ( ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSecondaryMeta > 0) ) { + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))/mDensity); + if ( ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSecondaryMeta > 0) ) { if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSecondaryMeta, false, false)) { placeCount[1]++; } } - else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) placeCount[3]++; } @@ -173,15 +184,15 @@ public class GT_Worldgen_GT_Ore_Layer } for (level = tMinY; level < (tMinY-1+3); level++) { for (int tX = wX; tX < eX; tX++) { - int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))); + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))/mDensity); for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))); - if ( ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSecondaryMeta > 0) ) { + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))/mDensity); + if ( ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSecondaryMeta > 0) ) { if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSecondaryMeta, false, false)) { placeCount[1]++; } } - else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) placeCount[3]++; } @@ -191,15 +202,15 @@ public class GT_Worldgen_GT_Ore_Layer // Low Middle layer is between + sporadic // level should be = tMinY-1+3 from end of for loop for (int tX = wX; tX < eX; tX++) { - int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))); + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))/mDensity); for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))); - if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mBetweenMeta > 0) ) { // Between are only 1 per vertical column, reduce by 1/2 to compensate + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))/mDensity); + if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mBetweenMeta > 0) ) { // Between are only 1 per vertical column, reduce by 1/2 to compensate if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mBetweenMeta, false, false)) { placeCount[2]++; } } - else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) placeCount[3]++; } @@ -208,20 +219,20 @@ public class GT_Worldgen_GT_Ore_Layer // High Middle layer is between + primary + sporadic level++; // Increment level to next layer for (int tX = wX; tX < eX; tX++) { - int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))); + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))/mDensity); for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))); - if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mBetweenMeta > 0) ) { // Between are only 1 per vertical column, reduce by 1/2 to compensate + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))/mDensity); + if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mBetweenMeta > 0) ) { // Between are only 1 per vertical column, reduce by 1/2 to compensate if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mBetweenMeta, false, false)) { placeCount[2]++; } } - else if ( ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mPrimaryMeta > 0) ) { + else if ( ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mPrimaryMeta > 0) ) { if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mPrimaryMeta, false, false)) { placeCount[0]++; } } - else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) placeCount[3]++; } @@ -231,15 +242,15 @@ public class GT_Worldgen_GT_Ore_Layer level++; // Increment level to next layer for( ; level < (tMinY + 6); level++){ // should do two layers for (int tX = wX; tX < eX; tX++) { - int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))); + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))/mDensity); for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))); - if ( ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mPrimaryMeta > 0) ) { + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))/mDensity); + if ( ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mPrimaryMeta > 0) ) { if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mPrimaryMeta, false, false)) { placeCount[0]++; } } - else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ/mDensity) == 0) || (aRandom.nextInt(placeX/mDensity) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate + else if ((aRandom.nextInt(7) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSporadicMeta > 0) ) { // Sporadics are only 1 per vertical column normally, reduce by 1/7 to compensate if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSporadicMeta, false, false)) placeCount[3]++; } @@ -251,8 +262,10 @@ public class GT_Worldgen_GT_Ore_Layer GT_Log.out.println( "Generated Orevein:" + this.mWorldGenName + " Dimension=" + tDimensionName + - " cX="+aChunkX+ - " cZ="+aChunkZ+ + " mX="+aChunkX/16+ + " mZ="+aChunkZ/16+ + " oreseedX="+ aSeedX/16 + + " oreseedZ="+ aSeedZ/16 + " cY="+tMinY+ " Den=" + this.mDensity + " Sec="+placeCount[1]+ diff --git a/src/main/java/gregtech/common/GT_Worldgenerator.java b/src/main/java/gregtech/common/GT_Worldgenerator.java index 789abbc070..6383ab44db 100644 --- a/src/main/java/gregtech/common/GT_Worldgenerator.java +++ b/src/main/java/gregtech/common/GT_Worldgenerator.java @@ -47,7 +47,7 @@ implements IWorldGenerator { public static List mList = new ArrayList(); public static HashSet ProcChunks = new HashSet(); // This is probably not going to work. Trying to create a fake orevein to put into hashtable when there will be no ores in a vein. - public static GT_Worldgen_GT_Ore_Layer noOresInVein = new GT_Worldgen_GT_Ore_Layer( "NoOresInVein", false, 0, 100, 0, 0, 0, false, false, false, false, false, false, Materials._NULL, Materials._NULL, Materials._NULL, Materials._NULL); + public static GT_Worldgen_GT_Ore_Layer noOresInVein = new GT_Worldgen_GT_Ore_Layer( "NoOresInVein", false, 0, 255, 0, 255, 16, false, false, false, false, false, false, Materials.Aluminium, Materials.Aluminium, Materials.Aluminium, Materials.Aluminium); public static Hashtable validOreveins = new Hashtable(1024); public boolean mIsGenerating = false; public static final Object listLock = new Object(); @@ -141,12 +141,19 @@ implements IWorldGenerator { } public void worldGenFindVein( int oreseedX, int oreseedZ) { - Long oreveinSeed = this.mWorld.getSeed() ^ ( (long)oreseedX << 32) | ( (long)oreseedZ & 0x00000000ffffffffL ); // Use an RNG that is identical every time it is called for this oreseed + long oreveinSeed = (long)this.mWorld.getSeed() ^ (( (long)oreseedX << 32) | ( (long)oreseedZ & 0x00000000ffffffffL )); // Use an RNG that is identical every time it is called for this oreseed XSTR oreveinRNG = new XSTR( oreveinSeed ); int oreveinPercentageRoll = oreveinRNG.nextInt(100); // Roll the dice, see if we get an orevein here at all int noOrePlacedCount=0; String tDimensionName = ""; if (debugOrevein) { tDimensionName = this.mWorld.provider.getDimensionName(); } + if (debugOrevein) GT_Log.out.println( + " Finding oreveins for oreveinSeed="+ oreveinSeed + + " mX="+ this.mX + + " mZ="+ this.mZ + + " oreseedX="+ oreseedX + + " oreseedZ="+ oreseedZ + ); // Search for a valid orevein for this dimension if( !validOreveins.containsKey(oreveinSeed) ) { @@ -160,13 +167,17 @@ implements IWorldGenerator { for (GT_Worldgen tWorldGen : GT_Worldgen_GT_Ore_Layer.sList) { tRandomWeight -= ((GT_Worldgen_GT_Ore_Layer) tWorldGen).mWeight; if (tRandomWeight <= 0) { - try { - oreveinRNG.setSeed(oreveinSeed); // reset seed for RNG to only be based on oreseed X/Z - int placementResult = tWorldGen.executeWorldgenChunkified(this.mWorld, oreveinRNG, this.mBiome, this.mDimensionType, this.mX*16, this.mZ*16, oreseedX*16, oreseedZ*16, this.mChunkGenerator, this.mChunkProvider); + try { + 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 (debugOrevein) GT_Log.out.println( - " Adding orevein to hash table. Orevein took " + (i-1) + + " Adding orevein to hash table. oreveinSeed=" + oreveinSeed + + " mX="+ this.mX + + " mZ="+ this.mZ + + " oreseedX="+ oreseedX + + " oreseedZ="+ oreseedZ + + " Orevein took " + (i-1) + " attempts to find" + " and " + placementAttempts + " tries to place " + @@ -184,6 +195,14 @@ implements IWorldGenerator { } break; // Try the next orevein } catch (Throwable e) { + if (debugOrevein) GT_Log.out.println( + "Exception occurred on oreVein" + tWorldGen + + " oreveinSeed="+ oreveinSeed + + " mX="+ this.mX + + " mZ="+ this.mZ + + " oreseedX="+ oreseedX + + " oreseedZ="+ oreseedZ + ); e.printStackTrace(GT_Log.err); } } @@ -193,22 +212,26 @@ implements IWorldGenerator { if ((!oreveinFound) && (this.mX == oreseedX) && (this.mZ == oreseedZ)){ if (debugOrevein) GT_Log.out.println( " Adding empty orevein to hash table. Could not find/place valid orevein" + - " chunkX="+ this.mX*16 + - " chunkZ="+ this.mZ*16 + - " oreseedX="+ oreseedX*16 + - " oreseedZ="+ oreseedZ*16 + + " oreveinSeed="+ oreveinSeed + + " mX="+ this.mX + + " mZ="+ this.mZ + + " oreseedX="+ oreseedX + + " oreseedZ="+ oreseedZ + " tries at oremix=" + i + " placementAttempts=" + placementAttempts + - "in dimensionName=" + tDimensionName + " in dimensionName=" + tDimensionName ); validOreveins.put(oreveinSeed, noOresInVein ); } } else if(oreveinPercentageRoll >= oreveinPercentage) { if (debugOrevein) GT_Log.out.println( " Skipped orevein in this 3x3 chunk!" + - " chunkX="+ this.mX + - " chunkZ="+ this.mZ + - " RNG=" + oreveinRNG + + " oreveinSeed="+ oreveinSeed + + " mX="+ this.mX + + " mZ="+ this.mZ + + " oreseedX=" + oreseedX + + " oreseedZ="+ oreseedZ + + " RNG=" + oreveinPercentageRoll + " %=" + oreveinPercentage+ " dimensionName=" + tDimensionName ); @@ -218,10 +241,12 @@ implements IWorldGenerator { // oreseed is located in the previously processed table if (debugOrevein) GT_Log.out.println( " Valid orevein found in hash table" + - " chunkX="+ this.mX*16 + - " chunkZ="+ this.mZ*16 + - " oreseedX="+ oreseedX*16 + - " oreseedZ="+ oreseedZ*16 + + " oreveinSeed="+ oreveinSeed + + " validOreveins.size()=" + validOreveins.size() + + " mX="+ this.mX + + " mZ="+ this.mZ + + " oreseedX="+ oreseedX + + " oreseedZ="+ oreseedZ + " in dimensionName=" + tDimensionName ); GT_Worldgen tWorldGen = validOreveins.get(oreveinSeed); @@ -234,10 +259,10 @@ implements IWorldGenerator { long startTime = System.nanoTime(); // Determine bounding box on how far out to check for oreveins affecting this chunk - int wXbox = this.mX - (oreveinMaxSize/4 ); - int eXbox = this.mX + (oreveinMaxSize/4 + 1); // Need to add 1 since it is compared using a < - int nZbox = this.mZ - (oreveinMaxSize/4 ); - int sZbox = this.mZ + (oreveinMaxSize/4 + 1); + int wXbox = this.mX - (oreveinMaxSize/16 ); + int eXbox = this.mX + (oreveinMaxSize/16 + 1); // Need to add 1 since it is compared using a < + int nZbox = this.mZ - (oreveinMaxSize/16 ); + int sZbox = this.mZ + (oreveinMaxSize/16 + 1); // Search for orevein seeds and add to the list; for( int x = wXbox; x < eXbox; x++ ) { @@ -251,12 +276,15 @@ implements IWorldGenerator { // Now process each oreseed vs this requested chunk for( ; seedList.size() != 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) - + +/////RAH Disable these for now +/* try { for (GT_Worldgen tWorldGen : GregTech_API.sWorldgenList) { tWorldGen.executeWorldgen(this.mWorld, this.mRandom, this.mBiome, this.mDimensionType, this.mX*16, this.mZ*16, this.mChunkGenerator, this.mChunkProvider); @@ -264,7 +292,7 @@ implements IWorldGenerator { } catch (Throwable e) { e.printStackTrace(GT_Log.err); } - +*/ /* if ((Math.abs(this.mX / 16) % 3 == 1) && (Math.abs(this.mZ / 16) % 3 == 1)) { int oreveinRNG = this.mRandom.nextInt(100); -- cgit From d2d59276cf5eb4486e275509c9d1aff8b835418a Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Tue, 14 Nov 2017 11:03:13 -0600 Subject: Happy with orevein generation now. Working on small ores next. --- .../gregtech/common/GT_Worldgen_GT_Ore_Layer.java | 40 ++++++++--------- .../java/gregtech/common/GT_Worldgenerator.java | 50 +++++++++------------- 2 files changed, 40 insertions(+), 50 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 a2b9c7e98e..edb1fa020d 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 @@ -97,9 +97,11 @@ 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" ); + */ // This is a special empty orevein return ORE_PLACED; } @@ -121,8 +123,8 @@ public class GT_Worldgen_GT_Ore_Layer 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 + 1); - int eX = Math.min( eXVein, aChunkX + 15); + int wX = Math.max( wXVein, aChunkX); + int eX = Math.min( eXVein, aChunkX + 16); if (wX >= eX) { //No overlap between orevein and this chunk exists in X /* if (debugOrevein) { @@ -137,8 +139,8 @@ public class GT_Worldgen_GT_Ore_Layer int nZVein = aSeedZ - aRandom.nextInt(mSize); int sZVein = aSeedZ + 16 + aRandom.nextInt(mSize); - int nZ = Math.max(nZVein, aChunkZ + 1); - int sZ = Math.min(sZVein, aChunkZ + 15); + int nZ = Math.max(nZVein, aChunkZ); + int sZ = Math.min(sZVein, aChunkZ + 16); if (nZ >= sZ) { //No overlap between orevein and this chunk exists in Z /* if (debugOrevein) { @@ -149,19 +151,16 @@ public class GT_Worldgen_GT_Ore_Layer */ return NO_OVERLAP; } - if (debugOrevein) GT_Log.out.println( - "wX=" + wX + - " eX=" + eX + - " nZ=" + nZ + - " sZ=" + sZ - ); + // 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(). + int localDensity = Math.max(1, this.mDensity / ((int)Math.sqrt(2 + Math.pow(aChunkX/16 - aSeedX/16, 2) + Math.pow(aChunkZ/16 - aSeedZ/16, 2))) ); + // To allow for early exit due to no ore placed in the bottom layer (probably because we are in the sky), unroll 1 pass through the loop // Now we do bottom-level-first oregen, and work our way upwards. int level = tMinY - 1; //Dunno why, but the first layer is actually played one below tMinY. Go figure. for (int tX = wX; tX < eX; tX++) { - int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))/mDensity); + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX))/localDensity); for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))/mDensity); + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ))/localDensity); if ( ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSecondaryMeta > 0) ) { if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSecondaryMeta, false, false)) { placeCount[1]++; @@ -184,9 +183,9 @@ public class GT_Worldgen_GT_Ore_Layer } for (level = tMinY; level < (tMinY-1+3); level++) { for (int tX = wX; tX < eX; tX++) { - int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))/mDensity); + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX))/localDensity); for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))/mDensity); + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ))/localDensity); if ( ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mSecondaryMeta > 0) ) { if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mSecondaryMeta, false, false)) { placeCount[1]++; @@ -202,9 +201,9 @@ public class GT_Worldgen_GT_Ore_Layer // Low Middle layer is between + sporadic // level should be = tMinY-1+3 from end of for loop for (int tX = wX; tX < eX; tX++) { - int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))/mDensity); + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX))/localDensity); for (int tZ = nZ; tZ < sZ; tZ++) { - int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZ - tZ), MathHelper.abs_int(nZ - tZ))/mDensity); + int placeZ = Math.max(1, Math.max(MathHelper.abs_int(sZVein - tZ), MathHelper.abs_int(nZVein - tZ))/localDensity); if ((aRandom.nextInt(2) == 0) && ((aRandom.nextInt(placeZ) == 0) || (aRandom.nextInt(placeX) == 0)) && (this.mBetweenMeta > 0) ) { // Between are only 1 per vertical column, reduce by 1/2 to compensate if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, level, tZ, this.mBetweenMeta, false, false)) { placeCount[2]++; @@ -219,9 +218,9 @@ public class GT_Worldgen_GT_Ore_Layer // High Middle layer is between + primary + sporadic level++; // Increment level to next layer for (int tX = wX; tX < eX; tX++) { - int placeX = Math.max(1, Math.max(MathHelper.abs_int(wX - tX), MathHelper.abs_int(eX - tX))/mDensity); + int placeX = Math.max(1, Math.max(MathHelper.abs_int(wXVein - tX), MathHelper.abs_int(eXVein - tX))