diff --git a/api/src/main/java/com/seibel/lod/api/interfaces/override/IDhApiOverrideable.java b/api/src/main/java/com/seibel/lod/api/interfaces/override/IDhApiOverrideable.java
index 083053a18..56fd42ca3 100644
--- a/api/src/main/java/com/seibel/lod/api/interfaces/override/IDhApiOverrideable.java
+++ b/api/src/main/java/com/seibel/lod/api/interfaces/override/IDhApiOverrideable.java
@@ -12,7 +12,7 @@ import com.seibel.lod.core.interfaces.dependencyInjection.IOverrideInjector;
public interface IDhApiOverrideable extends IBindable
{
/**
- * Returns when this Override should be used.
+ * Higher (larger numerical) priorities override lower (smaller numerical) priorities .
* For most developers this can be left at the default.
*/
default int getPriority() { return IOverrideInjector.DEFAULT_NON_CORE_OVERRIDE_PRIORITY; }
diff --git a/api/src/main/java/com/seibel/lod/api/interfaces/override/worldGenerator/IDhApiWorldGeneratorOverrideRegister.java b/api/src/main/java/com/seibel/lod/api/interfaces/override/worldGenerator/IDhApiWorldGeneratorOverrideRegister.java
index 6e56212ed..d22a6fd67 100644
--- a/api/src/main/java/com/seibel/lod/api/interfaces/override/worldGenerator/IDhApiWorldGeneratorOverrideRegister.java
+++ b/api/src/main/java/com/seibel/lod/api/interfaces/override/worldGenerator/IDhApiWorldGeneratorOverrideRegister.java
@@ -7,20 +7,10 @@ import com.seibel.lod.api.objects.DhApiResult;
* Handles adding world generator overrides.
*
* @author James Seibel
- * @version 2022-9-16
+ * @version 2022-12-10
*/
public interface IDhApiWorldGeneratorOverrideRegister
{
- /**
- * Registers the given world generator.
- *
- * This registers a backup world generator for all levels and will be overridden if there
- * is a world generator for the specific level.
- * If another world generator has already been registered, DhApiResult will return
- * the name of the previously registered generator and success = false.
- */
- DhApiResult registerWorldGeneratorOverride(IDhApiWorldGenerator worldGenerator);
-
/**
* Registers the given world generator for the given level.
*
diff --git a/api/src/main/java/com/seibel/lod/api/methods/override/DhApiWorldGeneratorOverrideRegister.java b/api/src/main/java/com/seibel/lod/api/methods/override/DhApiWorldGeneratorOverrideRegister.java
index 2d45f7aa9..b823251bb 100644
--- a/api/src/main/java/com/seibel/lod/api/methods/override/DhApiWorldGeneratorOverrideRegister.java
+++ b/api/src/main/java/com/seibel/lod/api/methods/override/DhApiWorldGeneratorOverrideRegister.java
@@ -10,7 +10,7 @@ import com.seibel.lod.core.DependencyInjection.WorldGeneratorInjector;
* Handles adding world generator overrides.
*
* @author James Seibel
- * @version 2022-9-16
+ * @version 2022-12-10
*/
public class DhApiWorldGeneratorOverrideRegister implements IDhApiWorldGeneratorOverrideRegister
{
@@ -20,20 +20,6 @@ public class DhApiWorldGeneratorOverrideRegister implements IDhApiWorldGenerator
- @Override
- public DhApiResult registerWorldGeneratorOverride(IDhApiWorldGenerator worldGenerator)
- {
- try
- {
- WorldGeneratorInjector.INSTANCE.bind(worldGenerator);
- return DhApiResult.createSuccess();
- }
- catch (Exception e)
- {
- return DhApiResult.createFail(e.getMessage());
- }
- }
-
@Override
public DhApiResult registerWorldGeneratorOverride(IDhApiLevelWrapper levelWrapper, IDhApiWorldGenerator worldGenerator)
{
diff --git a/api/src/main/java/com/seibel/lod/core/DependencyInjection/WorldGeneratorInjector.java b/api/src/main/java/com/seibel/lod/core/DependencyInjection/WorldGeneratorInjector.java
index e39a875f4..62f31130c 100644
--- a/api/src/main/java/com/seibel/lod/core/DependencyInjection/WorldGeneratorInjector.java
+++ b/api/src/main/java/com/seibel/lod/core/DependencyInjection/WorldGeneratorInjector.java
@@ -29,102 +29,77 @@ import java.util.HashMap;
/**
* This class takes care of dependency injection for world generators.
* This is done so other mods can override our world generator(s) to improve or replace them.
- *
* @author James Seibel
- * @version 2022-11-25
+ * @version 2022-12-10
*/
public class WorldGeneratorInjector
{
public static final WorldGeneratorInjector INSTANCE = new WorldGeneratorInjector();
-
+
private final HashMap worldGeneratorByLevelWrapper = new HashMap<>();
- /** World generators that aren't bound to a specific level and are used if no other world generators are bound. */
- private final OverrideInjector backupUniversalWorldGenerators;
-
+
/**
* This is used to determine if an override is part of Distant Horizons'
* Core or not.
* This probably isn't the best way of going about this, but it works for now.
*/
private final String corePackagePath;
-
-
-
+
+
+
public WorldGeneratorInjector()
{
String thisPackageName = this.getClass().getPackage().getName();
int secondPackageEndingIndex = StringUtil.nthIndexOf(thisPackageName, ".", 3);
this.corePackagePath = thisPackageName.substring(0, secondPackageEndingIndex); // this should be "com.seibel.lod"
-
- this.backupUniversalWorldGenerators = new OverrideInjector(this.corePackagePath);
}
-
+
/** This constructor should only be used for testing different corePackagePaths. */
public WorldGeneratorInjector(String newCorePackagePath)
{
this.corePackagePath = newCorePackagePath;
-
- this.backupUniversalWorldGenerators = new OverrideInjector(this.corePackagePath);
}
-
-
-
+
+
+
/**
- * Binds the backup world generator.
+ * Binds a world generator to the given level.
* See {@link DependencyInjector#bind(Class, IBindable) bind(Class, IBindable)} for full documentation.
- *
+ *
+ * @throws NullPointerException if any parameter is null
* @throws IllegalArgumentException if a non-Distant Horizons world generator with the priority CORE is passed in
+ *
* @see DependencyInjector#bind(Class, IBindable)
*/
- public void bind(IDhApiWorldGenerator worldGeneratorImplementation) throws IllegalStateException, IllegalArgumentException
+ public void bind(IDhApiLevelWrapper levelForWorldGenerator, IDhApiWorldGenerator worldGeneratorImplementation) throws NullPointerException, IllegalArgumentException
{
- this.bind(null, worldGeneratorImplementation);
- }
-
- /**
- * Binds the world generator to the given level.
- * See {@link DependencyInjector#bind(Class, IBindable) bind(Class, IBindable)} for full documentation.
- *
- * @throws IllegalArgumentException if a non-Distant Horizons world generator with the priority CORE is passed in
- * @see DependencyInjector#bind(Class, IBindable)
- */
- public void bind(IDhApiLevelWrapper levelForWorldGenerator, IDhApiWorldGenerator worldGeneratorImplementation) throws IllegalStateException, IllegalArgumentException
- {
- if (levelForWorldGenerator != null)
+ // validate inputs
+ if (levelForWorldGenerator == null)
{
- // bind this generator to a specific level
- if (!this.worldGeneratorByLevelWrapper.containsKey(levelForWorldGenerator))
- {
- this.worldGeneratorByLevelWrapper.put(levelForWorldGenerator, new OverrideInjector(this.corePackagePath));
- }
-
- this.worldGeneratorByLevelWrapper.get(levelForWorldGenerator).bind(IDhApiWorldGenerator.class, worldGeneratorImplementation);
+ throw new NullPointerException("A [" + IDhApiLevelWrapper.class.getSimpleName() + "] is required when binding a world generator.");
}
- else
+
+ if (worldGeneratorImplementation == null)
{
- // a null level wrapper binds the generator to all levels
- this.backupUniversalWorldGenerators.bind(IDhApiWorldGenerator.class, worldGeneratorImplementation);
+ throw new NullPointerException("No [" + IDhApiWorldGenerator.class.getSimpleName() + "] given.");
}
+
+
+ // bind this generator to the given level
+ if (!this.worldGeneratorByLevelWrapper.containsKey(levelForWorldGenerator))
+ {
+ this.worldGeneratorByLevelWrapper.put(levelForWorldGenerator, new OverrideInjector(this.corePackagePath));
+ }
+ this.worldGeneratorByLevelWrapper.get(levelForWorldGenerator).bind(IDhApiWorldGenerator.class, worldGeneratorImplementation);
}
-
-
-
- /**
- * Returns the backup world generator with the highest priority.
- * See {@link OverrideInjector#get(Class) get(Class)} for more documentation.
- *
- * @see OverrideInjector#get(Class)
- */
- public IDhApiWorldGenerator get() throws ClassCastException
- {
- return this.backupUniversalWorldGenerators.get(IDhApiWorldGenerator.class);
- }
-
+
+
+
/**
* Returns the bound world generator with the highest priority.
- * (Returns a backup world generator if no world generators have been bound for this specific level.)
- * See {@link OverrideInjector#get(Class) get(Class)} for more documentation.
- *
+ * Returns null if no world generators have been bound for this specific level.
+ *
+ * See {@link OverrideInjector#get(Class) get(Class)} for full documentation.
* @see OverrideInjector#get(Class)
*/
public IDhApiWorldGenerator get(IDhApiLevelWrapper levelForWorldGenerator) throws ClassCastException
@@ -132,21 +107,18 @@ public class WorldGeneratorInjector
if (!this.worldGeneratorByLevelWrapper.containsKey(levelForWorldGenerator))
{
// no generator exists for this specific level.
- // check for a backup universal world generator
- return this.backupUniversalWorldGenerators.get(IDhApiWorldGenerator.class);
+ return null;
}
-
+
// use the existing world generator
return this.worldGeneratorByLevelWrapper.get(levelForWorldGenerator).get(IDhApiWorldGenerator.class);
}
-
-
-
+
+
+
/** Removes all bound world generators. */
- public void clear()
- {
- this.worldGeneratorByLevelWrapper.clear();
- this.backupUniversalWorldGenerators.clear();
- }
+ public void clear() { this.worldGeneratorByLevelWrapper.clear(); }
+
+
}
diff --git a/core/src/main/java/com/seibel/lod/core/generation/BatchGenerator.java b/core/src/main/java/com/seibel/lod/core/generation/BatchGenerator.java
index 724869ecf..007212e61 100644
--- a/core/src/main/java/com/seibel/lod/core/generation/BatchGenerator.java
+++ b/core/src/main/java/com/seibel/lod/core/generation/BatchGenerator.java
@@ -21,6 +21,7 @@ package com.seibel.lod.core.generation;
import com.seibel.lod.api.enums.worldGeneration.EDhApiWorldGenThreadMode;
import com.seibel.lod.api.interfaces.override.worldGenerator.IDhApiWorldGenerator;
+import com.seibel.lod.core.interfaces.dependencyInjection.IOverrideInjector;
import com.seibel.lod.core.level.IDhLevel;
import com.seibel.lod.core.config.Config;
import com.seibel.lod.api.enums.config.EDistanceGenerationMode;
@@ -39,7 +40,7 @@ import java.util.function.Consumer;
/**
* @author Leetom
- * @version 2022-11-25
+ * @version 2022-12-10
*/
public class BatchGenerator implements IDhApiWorldGenerator
{
@@ -61,6 +62,15 @@ public class BatchGenerator implements IDhApiWorldGenerator
+ //=====================//
+ // override parameters //
+ //=====================//
+
+ @Override
+ public int getPriority() { return IOverrideInjector.CORE_PRIORITY; }
+
+
+
//======================//
// generator parameters //
//======================//
@@ -85,20 +95,6 @@ public class BatchGenerator implements IDhApiWorldGenerator
// generator methods //
//===================//
- @Override
- public void close() { this.stop(true); }
- public void stop(boolean blocking)
- {
- LOGGER.info("Batch Chunk Generator shutting down...");
- this.generationGroup.stop(blocking);
- }
-
- @Override
- public boolean isBusy()
- {
- return this.generationGroup.getEventCount() > Math.max(Config.Client.Advanced.Threading.numberOfWorldGenerationThreads.get().intValue(), 1) * 1.5;
- }
-
@Override
public CompletableFuture generateChunks(int chunkPosMinX, int chunkPosMinZ, byte granularity, byte targetDataDetail, Consumer