From 75a723d393cc18ac1af8cbc49728d74dd417c2a2 Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Fri, 8 Sep 2017 02:44:16 -0500 Subject: 1909: Fix oregen issue with empty chunks. Problem was caused by not using threadsafe techiniques on ArrayList. Also add and fix some more debug messages, including messages to show a vein being genererated in the air, and if an orevein failed to be chosen after 256 tries. --- .../gregtech/common/GT_Worldgen_GT_Ore_Layer.java | 21 +++++++---- .../java/gregtech/common/GT_Worldgenerator.java | 43 ++++++++++++++++++++-- 2 files changed, 52 insertions(+), 12 deletions(-) (limited to 'src/main/java') 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 2fa8f27307..0cf8a65898 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 @@ -93,6 +93,7 @@ public class GT_Worldgen_GT_Ore_Layer int eX = aChunkX + 16 + aRandom.nextInt(this.mSize); int[] execCount=new int[4]; + 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); @@ -100,25 +101,29 @@ public class GT_Worldgen_GT_Ore_Layer 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)) { - GT_TileEntity_Ores.setOreBlock(aWorld, tX, i, tZ, this.mSecondaryMeta, false); + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, i, tZ, this.mSecondaryMeta, false)) + placeCount[1]++; execCount[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))) { - GT_TileEntity_Ores.setOreBlock(aWorld, tX, tMinY + 2 + aRandom.nextInt(2), tZ, this.mBetweenMeta, false); + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, tMinY + 2 + aRandom.nextInt(2), tZ, this.mBetweenMeta, false)) + placeCount[2]++; execCount[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)) { - GT_TileEntity_Ores.setOreBlock(aWorld, tX, i, tZ, this.mPrimaryMeta, false); + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, i, tZ, this.mPrimaryMeta, false)) + placeCount[0]++; execCount[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))) { - GT_TileEntity_Ores.setOreBlock(aWorld, tX, tMinY - 1 + aRandom.nextInt(7), tZ, this.mSporadicMeta, false); + if (GT_TileEntity_Ores.setOreBlock(aWorld, tX, tMinY - 1 + aRandom.nextInt(7), tZ, this.mSporadicMeta, false)) + placeCount[3]++; execCount[3]++; } } @@ -129,10 +134,10 @@ public class GT_Worldgen_GT_Ore_Layer " @ dim="+aDimensionType+ " chunkX="+aChunkX+ " chunkZ="+aChunkZ+ - " Secondary="+execCount[1]+" "+new ItemStack(GregTech_API.sBlockOres1,1,mPrimaryMeta).getDisplayName()+ - " Between="+execCount[2]+" "+new ItemStack(GregTech_API.sBlockOres1,1,mPrimaryMeta).getDisplayName()+ - " Primary="+execCount[0]+" "+new ItemStack(GregTech_API.sBlockOres1,1,mPrimaryMeta).getDisplayName()+ - " Sporadic="+execCount[3]+" "+new ItemStack(GregTech_API.sBlockOres1,1,mPrimaryMeta).getDisplayName() + " Secondary="+execCount[1]+","+placeCount[1]+" "+new ItemStack(GregTech_API.sBlockOres1,1,mSecondaryMeta).getDisplayName()+ + " Between="+execCount[2]+","+placeCount[2]+" "+new ItemStack(GregTech_API.sBlockOres1,1,mBetweenMeta).getDisplayName()+ + " Primary="+execCount[0]+","+placeCount[0]+" "+new ItemStack(GregTech_API.sBlockOres1,1,mPrimaryMeta).getDisplayName()+ + " Sporadic="+execCount[3]+","+placeCount[3]+" "+new ItemStack(GregTech_API.sBlockOres1,1,mSporadicMeta).getDisplayName() ); } return true; diff --git a/src/main/java/gregtech/common/GT_Worldgenerator.java b/src/main/java/gregtech/common/GT_Worldgenerator.java index fec82a14b0..a80d7e0ff6 100644 --- a/src/main/java/gregtech/common/GT_Worldgenerator.java +++ b/src/main/java/gregtech/common/GT_Worldgenerator.java @@ -15,6 +15,7 @@ import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.ChunkProviderEnd; import net.minecraft.world.gen.ChunkProviderHell; +import static gregtech.api.enums.GT_Values.D1; import java.util.ArrayList; import java.util.List; @@ -33,6 +34,7 @@ public class GT_Worldgenerator private static boolean endAsteroids = true; public List mList = new ArrayList(); public boolean mIsGenerating = false; + public static final Object listLock = new Object(); //private static boolean gcAsteroids = true; @@ -46,17 +48,31 @@ public class GT_Worldgenerator //gcMaxSize = GregTech_API.sWorldgenFile.get("gcasteroids", "GCAsteroidMaxSize", 400); //mGCAsteroidProbability = GregTech_API.sWorldgenFile.get("gcasteroids", "GCAsteroidProbability", 300); GameRegistry.registerWorldGenerator(this, 1073741823); + if (D1) { + GT_Log.out.println( + "GT_Worldgenerator created" + ); + } } 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) + { + 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)); + if (D1) {GT_Log.out.println("ADD WorldGen chunk x:" + aX + " z:" + aZ + " SIZE: " + this.mList.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 (D1) {GT_Log.out.println("RUN WorldGen chunk x:" + toRun.mX/16 + " z:" + toRun.mZ/16 + " SIZE: " + this.mList.size());} + synchronized (listLock) + { + this.mList.remove(0); + } + toRun.run(); } - this.mList.clear(); this.mIsGenerating = false; } } @@ -112,6 +128,14 @@ public class GT_Worldgenerator } } } + if (D1 & temp) { + GT_Log.out.println( + "No Orevein Selected!" + + " @ dim="+ this.mDimensionType+ + " chunkX="+ this.mX + + " chunkZ="+ this.mZ + ); + } } int i = 0; for (int tX = this.mX - 16; i < 3; tX += 16) { @@ -133,6 +157,17 @@ public class GT_Worldgenerator i++; } } + else + { + if (D1) { + GT_Log.out.println( + "Chunk Skipped, not 3x3 center" + + " @ dim="+this.mDimensionType+ + " chunkX="+this.mX+ + " chunkZ="+this.mZ + ); + } + } //Asteroid Worldgen int tDimensionType = this.mWorld.provider.dimensionId; //String tDimensionName = this.mWorld.provider.getDimensionName(); @@ -246,4 +281,4 @@ public class GT_Worldgenerator } } } -} \ No newline at end of file +} -- cgit