From 82ae85b87631c23f01df61905359c222e2524cb4 Mon Sep 17 00:00:00 2001 From: Spacebuilder2020 Date: Wed, 13 Nov 2024 23:17:59 -0700 Subject: [PATCH] Adds a blacklist to prevent certain dims like Twilight Forest from generating overworld ores (#3438) Co-authored-by: Martin Robertz Co-authored-by: chochem <40274384+chochem@users.noreply.github.com> Co-authored-by: Alexdoru <57050655+Alexdoru@users.noreply.github.com> --- .../java/gregtech/api/world/GTWorldgen.java | 37 +++++++++++-------- .../gregtech/common/WorldgenGTOreLayer.java | 17 ++++++++- .../common/WorldgenGTOreSmallPieces.java | 15 ++++++++ 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/main/java/gregtech/api/world/GTWorldgen.java b/src/main/java/gregtech/api/world/GTWorldgen.java index 19c3c242456..07c76e0e3a5 100644 --- a/src/main/java/gregtech/api/world/GTWorldgen.java +++ b/src/main/java/gregtech/api/world/GTWorldgen.java @@ -9,9 +9,6 @@ import net.minecraft.world.chunk.IChunkProvider; import net.minecraftforge.common.DimensionManager; -import gregtech.common.WorldgenGTOreLayer; -import gregtech.common.WorldgenGTOreSmallPieces; - public abstract class GTWorldgen { public final String mWorldGenName; @@ -85,6 +82,18 @@ public boolean isGenerationAllowed(World aWorld, int aAllowedDimensionType) { * Overworld, Twilight Forest and Deep Dark) */ public boolean isGenerationAllowed(World aWorld, Class... aAllowedDimensionTypes) { + return isGenerationAllowed(aWorld, null, aAllowedDimensionTypes); + } + + /** + * + * @param aWorld The World Object + * @param blackListedProviders List of blacklisted Worldgeneration classes + * @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, String[] blackListedProviders, Class... aAllowedDimensionTypes) { String aDimName = aWorld.provider.getDimensionName(); if (aDimName.equalsIgnoreCase("Underdark")) { return false; @@ -95,6 +104,15 @@ public boolean isGenerationAllowed(World aWorld, Class... aAllowedDimensionTypes Boolean tAllowed = mDimensionMap.get(aDimName); if (tAllowed == null) { + if (blackListedProviders != null) { + for (String dimClass : blackListedProviders) { + if (dimClass.equals( + aWorld.provider.getClass() + .getName())) { + return false; + } + } + } boolean value = false; for (Class aAllowedDimensionType : aAllowedDimensionTypes) { if (aAllowedDimensionType.isInstance(aWorld.provider)) { @@ -103,19 +121,6 @@ public boolean isGenerationAllowed(World aWorld, Class... aAllowedDimensionTypes } } - // ugly, but idk how to do it better without hard depping on tf provider in ore constructors - if (this instanceof WorldgenGTOreSmallPieces ore) { - if (ore.twilightForest && aWorld.provider.dimensionId == 7) { - value = true; - } - } - - if (this instanceof WorldgenGTOreLayer ore) { - if (ore.twilightForest && aWorld.provider.dimensionId == 7) { - value = true; - } - } - mDimensionMap.put(aDimName, value); return value; } diff --git a/src/main/java/gregtech/common/WorldgenGTOreLayer.java b/src/main/java/gregtech/common/WorldgenGTOreLayer.java index 2a31395a69c..0e7c69b867a 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreLayer.java +++ b/src/main/java/gregtech/common/WorldgenGTOreLayer.java @@ -51,6 +51,14 @@ public class WorldgenGTOreLayer extends GTWorldgen { public final String aTextWorldgen = "worldgen."; public Class[] mAllowedProviders; + public String[] blackListedProviders; + public static Class tfProviderClass; + + static { + try { + tfProviderClass = Class.forName("twilightforest.world.WorldProviderTwilightForest"); + } catch (ClassNotFoundException ignored) {} + } public WorldgenGTOreLayer(OreMixBuilder mix) { super(mix.oreMixName, sList, mix.enabledByDefault); @@ -87,6 +95,13 @@ public WorldgenGTOreLayer(OreMixBuilder mix) { if (this.mOverworld) { allowedProviders.add(WorldProviderSurface.class); + if (!this.twilightForest) { + blackListedProviders = new String[] { "twilightforest.world.WorldProviderTwilightForest" }; + } + } + + if (tfProviderClass != null && this.twilightForest) { + allowedProviders.add(tfProviderClass); } if (this.mEnd) { @@ -104,7 +119,7 @@ public int executeWorldgenChunkified(World aWorld, Random aRandom, String aBiome return ORE_PLACED; } - if (!isGenerationAllowed(aWorld, mAllowedProviders)) { + if (!isGenerationAllowed(aWorld, blackListedProviders, mAllowedProviders)) { // The following code can be used for debugging, but it spams in logs // if (debugOrevein) { GTLog.out.println( "Wrong dimension" ); } return WRONG_DIMENSION; diff --git a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java index 4eb4eb4cce3..e3be59a6287 100644 --- a/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java +++ b/src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java @@ -31,6 +31,14 @@ public class WorldgenGTOreSmallPieces extends GTWorldgen { public static ArrayList sList = new ArrayList<>(); public Class[] mAllowedProviders; + public String[] blackListedProviders; + public static Class tfProviderClass; + + static { + try { + tfProviderClass = Class.forName("twilightforest.world.WorldProviderTwilightForest"); + } catch (ClassNotFoundException ignored) {} + } public WorldgenGTOreSmallPieces(SmallOreBuilder ore) { super(ore.smallOreName, GregTechAPI.sWorldgenList, ore.enabledByDefault); @@ -54,6 +62,13 @@ public WorldgenGTOreSmallPieces(SmallOreBuilder ore) { if (this.mOverworld) { allowedProviders.add(WorldProviderSurface.class); + if (!this.twilightForest) { + blackListedProviders = new String[] { "twilightforest.world.WorldProviderTwilightForest" }; + } + } + + if (tfProviderClass != null && this.twilightForest) { + allowedProviders.add(tfProviderClass); } if (this.mEnd) {