aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech
diff options
context:
space:
mode:
authorSpacebuilder2020 <spacebuilder2020@users.noreply.github.com>2024-08-12 10:14:55 -0600
committerGitHub <noreply@github.com>2024-08-12 23:14:55 +0700
commitc7ae290572e761c8ee0c1a2191d6091f8dcf709d (patch)
tree662e430957c9ec013244d5000ef7a6ed613977ba /src/main/java/gregtech
parent0ac5ccb1384d5e6c56bafe7ae7dd96b653d0df9c (diff)
downloadGT5-Unofficial-c7ae290572e761c8ee0c1a2191d6091f8dcf709d.tar.gz
GT5-Unofficial-c7ae290572e761c8ee0c1a2191d6091f8dcf709d.tar.bz2
GT5-Unofficial-c7ae290572e761c8ee0c1a2191d6091f8dcf709d.zip
Implement dim num agnostic isGenerationAllowed function (#2854)
* Implement dim num agnostic isGenerationAllowed function Replaces references to old function in as many places as possible Only reference that can't be changed right now is `E:\MinecraftProjects\GT5-Unofficial\src\main\java\com\github\bartimaeusnek\crossmod\galacticgreg\VoidMinerUtility.java:189` * Account for unloaded world or null provider by instead doing a dim number check This route should be avoided when possible. * Apply Spotless
Diffstat (limited to 'src/main/java/gregtech')
-rw-r--r--src/main/java/gregtech/api/world/GT_Worldgen.java38
-rw-r--r--src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock.java3
-rw-r--r--src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock_UnderLava.java3
-rw-r--r--src/main/java/gregtech/common/GT_Worldgen_GT_Ore_Layer.java27
-rw-r--r--src/main/java/gregtech/common/GT_Worldgen_GT_Ore_SmallPieces.java40
-rw-r--r--src/main/java/gregtech/common/GT_Worldgen_Stone.java2
6 files changed, 98 insertions, 15 deletions
diff --git a/src/main/java/gregtech/api/world/GT_Worldgen.java b/src/main/java/gregtech/api/world/GT_Worldgen.java
index 4e9ed6229b..bd85813e2b 100644
--- a/src/main/java/gregtech/api/world/GT_Worldgen.java
+++ b/src/main/java/gregtech/api/world/GT_Worldgen.java
@@ -1,5 +1,6 @@
package gregtech.api.world;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;
@@ -7,6 +8,7 @@ import java.util.concurrent.ConcurrentHashMap;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
+import net.minecraftforge.common.DimensionManager;
import gregtech.api.GregTech_API;
@@ -91,4 +93,40 @@ public abstract class GT_Worldgen {
}
return tAllowed;
}
+
+ public boolean isGenerationAllowed(World aWorld, int aAllowedDimensionType) {
+ World allowedWorld = DimensionManager.getWorld(aAllowedDimensionType);
+ if (allowedWorld != null && allowedWorld.provider != null) {
+ return isGenerationAllowed(aWorld, allowedWorld.provider.getClass());
+ } else {
+ return aWorld.provider.dimensionId == aAllowedDimensionType;
+ }
+ }
+
+ /**
+ *
+ * @param aWorld The World Object
+ * @param aAllowedDimensionTypes The Types of allowed Worldgeneration
+ * @return if generation for this world is allowed for MoronTech (tm) OreGen (ATM (2.0.3.1Dev) only End, Nether,
+ * Overworld, Twilight Forest and Deep Dark)
+ */
+ public boolean isGenerationAllowed(World aWorld, Class... aAllowedDimensionTypes) {
+ String aDimName = aWorld.provider.getDimensionName();
+ if (!(aDimName.equalsIgnoreCase("Overworld") || aDimName.equalsIgnoreCase("Nether")
+ || aDimName.equalsIgnoreCase("The End")
+ || aDimName.equalsIgnoreCase("Twilight Forest")
+ || aDimName.equalsIgnoreCase("Underdark"))) return false;
+
+ Boolean tAllowed = mDimensionMap.get(aDimName);
+ if (tAllowed == null) {
+ boolean tValue = GregTech_API.sWorldgenFile.get(
+ "worldgen." + mWorldGenName,
+ aDimName,
+ Arrays.stream(aAllowedDimensionTypes)
+ .anyMatch(worldProvider -> worldProvider.isInstance(aWorld.provider)));
+ mDimensionMap.put(aDimName, tValue);
+ return tValue;
+ }
+ return tAllowed;
+ }
}
diff --git a/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock.java b/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock.java
index 900f7808b1..f89d3ad8f8 100644
--- a/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock.java
+++ b/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock.java
@@ -31,8 +31,7 @@ public class GT_Worldgen_Ore_SingleBlock extends GT_Worldgen_Ore {
@Override
public boolean executeWorldgen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX,
int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) {
- if (isGenerationAllowed(aWorld, aDimensionType, mDimensionType)
- && (mBiomeList.isEmpty() || mBiomeList.contains(aBiome))
+ if (isGenerationAllowed(aWorld, mDimensionType) && (mBiomeList.isEmpty() || mBiomeList.contains(aBiome))
&& (mProbability <= 1 || aRandom.nextInt(mProbability) == 0)) {
for (int i = 0; i < mAmount; i++) {
int tX = aChunkX + aRandom.nextInt(16), tY = mMinY + aRandom.nextInt(mMaxY - mMinY),
diff --git a/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock_UnderLava.java b/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock_UnderLava.java
index 956cd0eb4c..3993c65f2a 100644
--- a/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock_UnderLava.java
+++ b/src/main/java/gregtech/api/world/GT_Worldgen_Ore_SingleBlock_UnderLava.java
@@ -31,8 +31,7 @@ public class GT_Worldgen_Ore_SingleBlock_UnderLava extends GT_Worldgen_Ore {
@Override
public boolean executeCavegen(World aWorld, Random aRandom, String aBiome, int aDimensionType, int aChunkX,
int aChunkZ, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) {
- if (isGenerationAllowed(aWorld, aDimensionType, mDimensionType)
- && (mBiomeList.isEmpty() || mBiomeList.contains(aBiome))
+ if (isGenerationAllowed(aWorld, mDimensionType) && (mBiomeList.isEmpty() || mBiomeList.contains(aBiome))
&& (mProbability <= 1 || aRandom.nextInt(mProbability) == 0)) {
for (int i = 0; i < mAmount; i++) {
int tX = aChunkX + aRandom.nextInt(16), tY = mMinY + aRandom.nextInt(mMaxY - mMinY),
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 fd260d73a4..23bf149b9c 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
@@ -5,12 +5,16 @@ import static gregtech.api.enums.GT_Values.oreveinPlacerOres;
import static gregtech.api.enums.GT_Values.oreveinPlacerOresMultiplier;
import java.util.ArrayList;
+import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
+import net.minecraft.world.WorldProviderEnd;
+import net.minecraft.world.WorldProviderHell;
+import net.minecraft.world.WorldProviderSurface;
import net.minecraft.world.chunk.IChunkProvider;
import gregtech.api.GregTech_API;
@@ -48,6 +52,8 @@ public class GT_Worldgen_GT_Ore_Layer extends GT_Worldgen {
public final boolean mMoon = false, mMars = false, mAsteroid = false;
public final String aTextWorldgen = "worldgen.";
+ public Class[] mAllowedProviders;
+
@Deprecated
public GT_Worldgen_GT_Ore_Layer(String aName, boolean aDefault, int aMinY, int aMaxY, int aWeight, int aDensity,
int aSize, boolean aOverworld, boolean aNether, boolean aEnd, boolean GC_UNUSED1, boolean GC_UNUSED2,
@@ -104,6 +110,20 @@ public class GT_Worldgen_GT_Ore_Layer extends GT_Worldgen {
if (this.mEnabled) {
sWeight += this.mWeight;
}
+
+ List<Class> allowedProviders = new ArrayList<>();
+ if (this.mNether) {
+ allowedProviders.add(WorldProviderHell.class);
+ }
+
+ if (this.mOverworld) {
+ allowedProviders.add(WorldProviderSurface.class);
+ }
+
+ if (this.mEnd) {
+ allowedProviders.add(WorldProviderEnd.class);
+ }
+ mAllowedProviders = allowedProviders.toArray(new Class[allowedProviders.size()]);
}
@Override
@@ -114,11 +134,8 @@ public class GT_Worldgen_GT_Ore_Layer extends GT_Worldgen {
// Return a special empty orevein
return ORE_PLACED;
}
- if (!isGenerationAllowed(
- aWorld,
- aDimensionType,
- ((aDimensionType == -1) && (this.mNether)) || ((aDimensionType == 0) && (this.mOverworld))
- || ((aDimensionType == 1) && (this.mEnd)) ? aDimensionType : ~aDimensionType)) {
+
+ if (!isGenerationAllowed(aWorld, mAllowedProviders)) {
// The following code can be used for debugging, but it spams in logs
// if (debugOrevein) { GT_Log.out.println( "Wrong dimension" ); }
return WRONG_DIMENSION;
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 c8219e8361..f1e0c92703 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
@@ -3,9 +3,13 @@ package gregtech.common;
import static gregtech.api.enums.GT_Values.debugSmallOres;
import java.util.ArrayList;
+import java.util.List;
import java.util.Random;
import net.minecraft.world.World;
+import net.minecraft.world.WorldProviderEnd;
+import net.minecraft.world.WorldProviderHell;
+import net.minecraft.world.WorldProviderSurface;
import net.minecraft.world.chunk.IChunkProvider;
import gregtech.api.GregTech_API;
@@ -28,6 +32,8 @@ public class GT_Worldgen_GT_Ore_SmallPieces extends GT_Worldgen {
public final String aTextWorldgen = "worldgen.";
public static ArrayList<GT_Worldgen_GT_Ore_SmallPieces> sList = new ArrayList<>();
+ public Class[] mAllowedProviders;
+
// TODO CHECK IF INSTANTIATION IS CORRECT
public GT_Worldgen_GT_Ore_SmallPieces(String aName, boolean aDefault, int aMinY, int aMaxY, int aAmount,
boolean aOverworld, boolean aNether, boolean aEnd, Materials aPrimary) {
@@ -45,6 +51,20 @@ public class GT_Worldgen_GT_Ore_SmallPieces extends GT_Worldgen {
.get(aTextWorldgen + this.mWorldGenName, "Ore", aPrimary.mMetaItemSubID));
this.mBiome = GregTech_API.sWorldgenFile.get(aTextWorldgen + this.mWorldGenName, "BiomeName", "None");
sList.add(this);
+
+ List<Class> allowedProviders = new ArrayList<>();
+ if (this.mNether) {
+ allowedProviders.add(WorldProviderHell.class);
+ }
+
+ if (this.mOverworld) {
+ allowedProviders.add(WorldProviderSurface.class);
+ }
+
+ if (this.mEnd) {
+ allowedProviders.add(WorldProviderEnd.class);
+ }
+ mAllowedProviders = allowedProviders.toArray(new Class[allowedProviders.size()]);
}
public GT_Worldgen_GT_Ore_SmallPieces(String aName, boolean aDefault, int aMinY, int aMaxY, int aAmount,
@@ -64,6 +84,20 @@ public class GT_Worldgen_GT_Ore_SmallPieces extends GT_Worldgen {
.get(aTextWorldgen + this.mWorldGenName, "Ore", aPrimary.mMetaItemSubID));
this.mBiome = GregTech_API.sWorldgenFile.get(aTextWorldgen + this.mWorldGenName, "BiomeName", "None");
sList.add(this);
+
+ List<Class> allowedProviders = new ArrayList<>();
+ if (this.mNether) {
+ allowedProviders.add(WorldProviderHell.class);
+ }
+
+ if (this.mOverworld) {
+ allowedProviders.add(WorldProviderSurface.class);
+ }
+
+ if (this.mEnd) {
+ allowedProviders.add(WorldProviderEnd.class);
+ }
+ mAllowedProviders = allowedProviders.toArray(new Class[allowedProviders.size()]);
}
@Override
@@ -72,11 +106,7 @@ public class GT_Worldgen_GT_Ore_SmallPieces extends GT_Worldgen {
if (!this.mBiome.equals("None") && !(this.mBiome.equals(aBiome))) {
return false; // Not the correct biome for ore mix
}
- if (!isGenerationAllowed(
- aWorld,
- aDimensionType,
- ((aDimensionType == -1) && (this.mNether)) || ((aDimensionType == 0) && (this.mOverworld))
- || ((aDimensionType == 1) && (this.mEnd)) ? aDimensionType : ~aDimensionType)) {
+ if (!isGenerationAllowed(aWorld, mAllowedProviders)) {
return false;
}
int count = 0;
diff --git a/src/main/java/gregtech/common/GT_Worldgen_Stone.java b/src/main/java/gregtech/common/GT_Worldgen_Stone.java
index 835f9d5c67..a9001d3f26 100644
--- a/src/main/java/gregtech/common/GT_Worldgen_Stone.java
+++ b/src/main/java/gregtech/common/GT_Worldgen_Stone.java
@@ -82,7 +82,7 @@ public class GT_Worldgen_Stone extends GT_Worldgen_Ore {
XSTR stoneRNG = new XSTR();
ArrayList<ValidSeeds> stones = new ArrayList<>();
- if (!isGenerationAllowed(aWorld, aDimensionType, this.mDimensionType)) {
+ if (!isGenerationAllowed(aWorld, mDimensionType)) {
return false;
}
if (!(this.mBiomeList.isEmpty() || this.mBiomeList.contains(aBiome))) {