diff options
author | Spacebuilder2020 <spacebuilder2020@users.noreply.github.com> | 2024-08-12 10:14:55 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-12 23:14:55 +0700 |
commit | c7ae290572e761c8ee0c1a2191d6091f8dcf709d (patch) | |
tree | 662e430957c9ec013244d5000ef7a6ed613977ba /src/main/java/gregtech/api | |
parent | 0ac5ccb1384d5e6c56bafe7ae7dd96b653d0df9c (diff) | |
download | GT5-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/api')
3 files changed, 40 insertions, 4 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), |