diff options
author | Richard Hendricks <richardhendricks@pobox.com> | 2017-11-12 21:27:13 -0600 |
---|---|---|
committer | Richard Hendricks <richardhendricks@pobox.com> | 2017-11-24 00:48:02 -0600 |
commit | 376f7c63f6d7ea9df0b967e9dc1ecbd710370307 (patch) | |
tree | 6cb42a912cb1c0db014f114a538a61c55d1072c6 /src/main/java | |
parent | 9574e1b1986a6d582d2e3f6714d370ada34f9a18 (diff) | |
download | GT5-Unofficial-376f7c63f6d7ea9df0b967e9dc1ecbd710370307.tar.gz GT5-Unofficial-376f7c63f6d7ea9df0b967e9dc1ecbd710370307.tar.bz2 GT5-Unofficial-376f7c63f6d7ea9df0b967e9dc1ecbd710370307.zip |
First pass at chunkifying oreveins
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/gregtech/GT_Mod.java | 2 | ||||
-rw-r--r-- | src/main/java/gregtech/api/enums/GT_Values.java | 12 | ||||
-rw-r--r-- | src/main/java/gregtech/api/world/GT_Worldgen.java | 4 | ||||
-rw-r--r-- | src/main/java/gregtech/common/GT_Worldgen_GT_Ore_Layer.java | 221 | ||||
-rw-r--r-- | src/main/java/gregtech/common/GT_Worldgenerator.java | 209 | ||||
-rw-r--r-- | src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java | 57 |
6 files changed, 389 insertions, 116 deletions
diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index 4e4f93bef5..e2ed973ed6 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -194,6 +194,8 @@ public class GT_Mod implements IGT_Mod { GT_Values.debugSmallOres = tMainConfig.get(aTextGeneral, "debugSmallOres", false).getBoolean(false); GT_Values.oreveinPercentage = tMainConfig.get(aTextGeneral, "oreveinPercentage_75",75).getInt(75); GT_Values.oreveinAttempts = tMainConfig.get(aTextGeneral, "oreveinAttempts_64",64).getInt(64); + GT_Values.oreveinMaxPlacementAttempts = tMainConfig.get(aTextGeneral, "oreveinMaxPlacementAttempts_8",8).getInt(8); + GT_Values.oreveinMaxSize = tMainConfig.get(aTextGeneral, "oreveinMaxSize_64",64).getInt(64); GregTech_API.TICKS_FOR_LAG_AVERAGING = tMainConfig.get(aTextGeneral, "TicksForLagAveragingWithScanner", 25).getInt(25); GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING = tMainConfig.get(aTextGeneral, "MillisecondsPassedInGTTileEntityUntilLagWarning", 100).getInt(100); diff --git a/src/main/java/gregtech/api/enums/GT_Values.java b/src/main/java/gregtech/api/enums/GT_Values.java index d6fae23b01..d4b98fd291 100644 --- a/src/main/java/gregtech/api/enums/GT_Values.java +++ b/src/main/java/gregtech/api/enums/GT_Values.java @@ -122,10 +122,18 @@ public class GT_Values { */ public static int oreveinPercentage; /** - * Control number of attempts to find a valid orevein. Lower numbers is slightly faster chunkgen, but more empty chunks with thin stone height. + * Control number of attempts to find a valid orevein. Generally this maximum limit isn't hit, selecting a vein is cheap */ public static int oreveinAttempts; /** + * Control number of attempts to place a valid orevein. If a vein wasn't placed due to height restrictions, completely in the water, etc, another attempt is tried. + */ + public static int oreveinMaxPlacementAttempts; + /** + * How wide to look for oreveins that affect a requested chunk. Trying to use oreveins larger than this will not work correctly. Increasing the size will cause additional worldgenerator lag. + */ + public static int oreveinMaxSize; + /** * Not really Constants, but they set using the Config and therefore should be constant (those are for the Debug Mode) */ public static boolean D1 = false, D2 = false; @@ -149,4 +157,4 @@ public class GT_Values { * If you have to give something a World Parameter but there is no World... (Dummy World) */ public static World DW; -}
\ No newline at end of file +} diff --git a/src/main/java/gregtech/api/world/GT_Worldgen.java b/src/main/java/gregtech/api/world/GT_Worldgen.java index e464c475f1..2fdb637e87 100644 --- a/src/main/java/gregtech/api/world/GT_Worldgen.java +++ b/src/main/java/gregtech/api/world/GT_Worldgen.java @@ -34,6 +34,10 @@ public abstract class GT_Worldgen { return false; } + public int executeWorldgenChunkified(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX, int aChunkZ, int seedX, int seedZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { + return 0; + } + /** * @param aWorld The World Object * @param aRandom The Random Generator to use 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<Runnable> mList = new ArrayList();
- public HashSet<Long> ProcChunks = new HashSet<Long>();
+ public static List<Runnable> mList = new ArrayList();
+ public static HashSet<Long> ProcChunks = new HashSet<Long>();
+ // 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<Long, GT_Worldgen> 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<NearbySeeds> 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<oreveinPercentage) && (GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) {
+ int placementAttempts = 0;
+ boolean oreveinFound = false;
+ int i;
+
+ for( i = 0; (i < oreveinAttempts) && (!oreveinFound) && (placementAttempts<oreveinMaxPlacementAttempts); i++ ) {
+ int tRandomWeight = oreveinRNG.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 {
+ 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);
+ 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) +
+ " attempts to find" +
+ " and " + placementAttempts +
+ " tries to place " +
+ " in dimensionName=" + tDimensionName
+ );
+ validOreveins.put(oreveinSeed, tWorldGen);
+ oreveinFound = true;
+ break;
+ case GT_Worldgen_GT_Ore_Layer.NO_ORE_IN_BOTTOM_LAYER:
+ // SHould do retry in this case until out of chances
+ break;
+ case GT_Worldgen_GT_Ore_Layer.NO_OVERLAP:
+ // Orevein didn't reach this chunk, can't add it yet to the hash
+ break;
+ }
+ break; // Try the next orevein
+ } catch (Throwable e) {
+ e.printStackTrace(GT_Log.err);
+ }
+ }
+ }
+ }
+ // 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 (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 +
+ " tries at oremix=" + i +
+ " placementAttempts=" + placementAttempts +
+ "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 +
+ " %=" + oreveinPercentage+
+ " dimensionName=" + tDimensionName
+ );
+ validOreveins.put(oreveinSeed, noOresInVein);
+ }
+ }else {
+ // 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 +
+ " in dimensionName=" + tDimensionName
+ );
+ GT_Worldgen tWorldGen = validOreveins.get(oreveinSeed);
+ oreveinRNG.setSeed(oreveinSeed); // reset seed for RNG to only be based on oreseed X/Z
+ tWorldGen.executeWorldgenChunkified(this.mWorld, oreveinRNG, this.mBiome, this.mDimensionType, this.mX*16, this.mZ*16, oreseedX*16, oreseedZ*16, this.mChunkGenerator, this.mChunkProvider);
+ }
+ }
+
+ public void run() {
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);
+
+ // Search for orevein seeds and add to the list;
+ for( int x = wXbox; x < eXbox; x++ ) {
+ for( int z = nZbox; z < sZbox; z++ ) {
+ // Determine if this X/Z is an orevein seed
+ if ( ( (Math.abs(x)%3) == 1) && ( (Math.abs(z)%3) == 1 ) ) {
+ seedList.add( new NearbySeeds(x,z) );
+ }
+ }
+ }
+
+ // 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)
+
+ 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);
+ }
+ } 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);
if (( oreveinRNG < oreveinPercentage) && (GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) {
@@ -125,14 +273,18 @@ public class GT_Worldgenerator int tRandomWeight;
int i;
- for (i = 0; (i < oreveinAttempts) && (temp); i++) {
+ int placementAttempts=0;
+ for (i = 0; (i < oreveinAttempts) && (temp) && (placementAttempts<oreveinMaxPlacementAttempts); 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)) {
+ int genResult = tWorldGen.executeWorldgenInt(this.mWorld, this.mRandom, this.mBiome, this.mDimensionType, this.mX, this.mZ, this.mChunkGenerator, this.mChunkProvider);
+ if (genResult == GT_Worldgen_GT_Ore_Layer.ORE_PLACED) { // Successful ore placement
temp = false;
+ } else if (genResult == GT_Worldgen_GT_Ore_Layer.NO_ORE_IN_BOTTOM_LAYER) { // Ore vein allowed, but could not place any
+ placementAttempts++;
}
break;
} catch (Throwable e) {
@@ -143,18 +295,22 @@ public class GT_Worldgenerator }
if (debugOrevein & temp) {
GT_Log.out.println(
- "No orevein selected!" +
+ " Could not find/place valid orevein" +
" chunkX="+ this.mX +
" chunkZ="+ this.mZ +
- " oreveinAttemps=" + oreveinAttempts +
- " dimensionName=" + tDimensionName
+ " tries at oremix=" + i +
+ " placementAttempts=" + placementAttempts +
+ " oreveinMaxPlacementAttempts=" + oreveinMaxPlacementAttempts +
+ "in dimensionName=" + tDimensionName
);
} else if (debugOrevein)
{
GT_Log.out.println(
- "Orevein took " + i +
+ " Orevein took " + (i-1) +
" attempts to find" +
- " dimensionName=" + tDimensionName
+ " and " + placementAttempts +
+ " tries to place " +
+ " in dimensionName=" + tDimensionName
);
}
@@ -163,7 +319,7 @@ public class GT_Worldgenerator if((oreveinRNG >= oreveinPercentage) && (debugOrevein))
{
GT_Log.out.println(
- "Skipped orevein in this 3x3 chunk!" +
+ " Skipped orevein in this 3x3 chunk!" +
" chunkX="+ this.mX +
" chunkZ="+ this.mZ +
" RNG=" + oreveinRNG +
@@ -197,7 +353,7 @@ public class GT_Worldgenerator {
if (debugOrevein) {
GT_Log.out.println(
- "Skipped chunk, not 3x3 center" +
+ " Skipped chunk, not 3x3 center" +
" @ dim="+this.mDimensionType+
" chunkX="+this.mX+
" chunkZ="+this.mZ+
@@ -205,6 +361,9 @@ public class GT_Worldgenerator );
}
}
+
+*/
+
//Asteroid Worldgen
int tDimensionType = this.mWorld.provider.dimensionId;
//String tDimensionName = this.mWorld.provider.getDimensionName();
@@ -320,7 +479,7 @@ public class GT_Worldgenerator long duration = (endTime - startTime);
if (debugWorldGen) {
GT_Log.out.println(
- "Oregen took " + duration +
+ " Oregen took " + duration +
" nanoseconds"
);
}
diff --git a/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java b/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java index c6618dca60..d4717535cb 100644 --- a/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java +++ b/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java @@ -31,7 +31,7 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit public static byte getHarvestData(short aMetaData, int aBaseBlockHarvestLevel) { Materials aMaterial = GregTech_API.sGeneratedMaterials[(aMetaData % 1000)]; byte tByte = aMaterial == null ? 0 : (byte) Math.max(aBaseBlockHarvestLevel, Math.min(7, aMaterial.mToolQuality - (aMetaData < 16000 ? 0 : 1))); - if(GT_Mod.gregtechproxy.mChangeHarvestLevels ){ + if(GT_Mod.gregtechproxy.mChangeHarvestLevels ) { tByte = aMaterial == null ? 0 : (byte) Math.max(aBaseBlockHarvestLevel, Math.min(GT_Mod.gregtechproxy.mMaxHarvestLevel, GT_Mod.gregtechproxy.mHarvestLevel[aMaterial.mMetaItemSubID] - (aMetaData < 16000 ? 0 : 1))); } return tByte; @@ -51,38 +51,9 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit String BlockName = tBlock.getUnlocalizedName(); aMetaData += isSmallOre ? 16000 : 0; if ((aMetaData > 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); |