Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a blacklist to prevent certain dims like Twilight Forest from generating overworld ores #3438

Merged
37 changes: 21 additions & 16 deletions src/main/java/gregtech/api/world/GTWorldgen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
}
chochem marked this conversation as resolved.
Show resolved Hide resolved
boolean value = false;
for (Class aAllowedDimensionType : aAllowedDimensionTypes) {
if (aAllowedDimensionType.isInstance(aWorld.provider)) {
Expand All @@ -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;
}
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/gregtech/common/WorldgenGTOreLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/gregtech/common/WorldgenGTOreSmallPieces.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public class WorldgenGTOreSmallPieces extends GTWorldgen {
public static ArrayList<WorldgenGTOreSmallPieces> 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);
Expand All @@ -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) {
Expand Down