Partially implement/uncomment worldGeneratorOverride
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
package com.seibel.lod.api.items.interfaces.override;
|
||||
|
||||
import com.seibel.lod.api.items.enums.worldGeneration.EDhApiWorldGenerationStep;
|
||||
import com.seibel.lod.api.items.enums.worldGeneration.EDhApiWorldGenThreadMode;
|
||||
import com.seibel.lod.api.items.interfaces.world.IDhApiChunkWrapper;
|
||||
import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.override.worldGenerator.ICoreDhApiWorldGenerator;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world.ICoreDhApiLevelWrapper;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.objects.converters.GenericEnumConverter;
|
||||
import com.seibel.lod.core.enums.worldGeneration.EWorldGenThreadMode;
|
||||
import com.seibel.lod.core.enums.worldGeneration.EWorldGenerationStep;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
* @version 2022-9-8
|
||||
*/
|
||||
public abstract class AbstractDhApiWorldGenerator implements ICoreDhApiWorldGenerator, IDhApiOverrideable
|
||||
{
|
||||
private final GenericEnumConverter<EWorldGenThreadMode, EDhApiWorldGenThreadMode> threadModeEnumConverter = new GenericEnumConverter<>(EWorldGenThreadMode.class, EDhApiWorldGenThreadMode.class);
|
||||
private final GenericEnumConverter<EWorldGenerationStep, EDhApiWorldGenerationStep> generationStepEnumConverter = new GenericEnumConverter<>(EWorldGenerationStep.class, EDhApiWorldGenerationStep.class);
|
||||
|
||||
|
||||
/** Returns which thread chunk generation requests can be created on. */
|
||||
public abstract EDhApiWorldGenThreadMode getThreadingMode();
|
||||
|
||||
@Override
|
||||
public EWorldGenThreadMode getCoreThreadingMode()
|
||||
{
|
||||
return threadModeEnumConverter.convertToCoreType(this.getThreadingMode());
|
||||
}
|
||||
|
||||
public abstract IDhApiChunkWrapper generateChunk(int chunkPosX, int chunkPosZ, IDhApiLevelWrapper serverLevelWrapper, EDhApiWorldGenerationStep maxStepToGenerate);
|
||||
|
||||
@Override
|
||||
public final IChunkWrapper generateCoreChunk(int chunkPosX, int chunkPosZ, ICoreDhApiLevelWrapper serverLevelWrapper, EWorldGenerationStep maxStepToGenerate)
|
||||
{
|
||||
// TODO probably need to change the return type
|
||||
return null; //generateChunk(chunkPosX, chunkPosZ, null, generationStepEnumConverter.convertToApiType(maxStepToGenerate));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package com.seibel.lod.api.items.interfaces.override;
|
||||
|
||||
import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneration.EDhApiWorldGenerationStep;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneration.EDhApiWorldGenThreadMode;
|
||||
import com.seibel.lod.api.items.interfaces.world.IDhApiChunkWrapper;
|
||||
import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
* @version 2022-7-26
|
||||
*/
|
||||
public interface IDhApiWorldGenerator extends IDhApiOverrideable
|
||||
{
|
||||
/** Returns which thread chunk generation requests can be created on. */
|
||||
EDhApiWorldGenThreadMode getThreadingMode();
|
||||
|
||||
IDhApiChunkWrapper generateChunk(int chunkPosX, int chunkPosZ, IDhApiLevelWrapper serverLevelWrapper, EDhApiWorldGenerationStep maxStepToGenerate);
|
||||
|
||||
}
|
||||
+6
-4
@@ -17,17 +17,19 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.core.api.external.coreImplementations.objects.wrappers;
|
||||
package com.seibel.lod.api.items.objects.wrappers;
|
||||
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world.ICoreDhApiDimensionTypeWrapper;
|
||||
import com.seibel.lod.api.items.interfaces.IDhApiUnsafeWrapper;
|
||||
import com.seibel.lod.api.items.interfaces.world.IDhApiDimensionTypeWrapper;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.ICoreDhApiUnsafeWrapper;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world.ICoreDhApiDimensionTypeWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IDimensionTypeWrapper;
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
* @version 2022-8-23
|
||||
* @version 2022-9-8
|
||||
*/
|
||||
public class DhApiDimensionTypeWrapper implements ICoreDhApiDimensionTypeWrapper, ICoreDhApiUnsafeWrapper
|
||||
public class DhApiDimensionTypeWrapper implements IDhApiDimensionTypeWrapper
|
||||
{
|
||||
private final IDimensionTypeWrapper dimensionTypeWrapper;
|
||||
|
||||
+16
-4
@@ -17,9 +17,12 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.core.api.external.coreImplementations.objects.wrappers;
|
||||
package com.seibel.lod.api.items.objects.wrappers;
|
||||
|
||||
import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneration.EDhApiLevelType;
|
||||
import com.seibel.lod.api.items.enums.worldGeneration.EDhApiLevelType;
|
||||
import com.seibel.lod.api.items.interfaces.IDhApiUnsafeWrapper;
|
||||
import com.seibel.lod.api.items.interfaces.world.IDhApiDimensionTypeWrapper;
|
||||
import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world.ICoreDhApiLevelWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IDimensionTypeWrapper;
|
||||
@@ -30,9 +33,9 @@ import com.seibel.lod.core.wrapperInterfaces.world.IServerLevelWrapper;
|
||||
* Can be either a Server or Client level.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-8-23
|
||||
* @version 2022-9-8
|
||||
*/
|
||||
public class DhApiLevelWrapper implements ICoreDhApiLevelWrapper
|
||||
public class DhApiLevelWrapper implements IDhApiLevelWrapper
|
||||
{
|
||||
private final ILevelWrapper levelWrapper;
|
||||
private final IDimensionTypeWrapper dimensionTypeWrapper;
|
||||
@@ -45,6 +48,10 @@ public class DhApiLevelWrapper implements ICoreDhApiLevelWrapper
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IDhApiDimensionTypeWrapper getDimensionType() { return new DhApiDimensionTypeWrapper(this.dimensionTypeWrapper); }
|
||||
|
||||
@Override
|
||||
public EDhApiLevelType getLevelType()
|
||||
{
|
||||
if (this.levelWrapper.getClass().isAssignableFrom(IClientLevelWrapper.class))
|
||||
@@ -62,14 +69,19 @@ public class DhApiLevelWrapper implements ICoreDhApiLevelWrapper
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCeiling() { return this.levelWrapper.hasCeiling(); }
|
||||
|
||||
@Override
|
||||
public boolean hasSkyLight() { return this.levelWrapper.hasSkyLight(); }
|
||||
|
||||
@Override
|
||||
public int getHeight() { return this.levelWrapper.getHeight(); }
|
||||
|
||||
@Override
|
||||
public int getMinHeight() { return this.levelWrapper.getMinHeight(); }
|
||||
|
||||
|
||||
@Override
|
||||
public Object getWrappedMcObject_UNSAFE() { return this.levelWrapper.unwrapLevel(); }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.seibel.lod.api.methods.events;
|
||||
|
||||
import com.seibel.lod.api.items.objects.DhApiResult;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.events.ICoreDhApiEvent;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.DhApiEventInjector;
|
||||
|
||||
@@ -7,44 +8,44 @@ import com.seibel.lod.core.handlers.dependencyInjection.DhApiEventInjector;
|
||||
* Handles adding/removing event handlers.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-7-16
|
||||
* @version 2022-9-8
|
||||
*/
|
||||
public class DhApiEventRegister
|
||||
{
|
||||
// /**
|
||||
// * Registers the given event handler. <Br>
|
||||
// * Only one eventHandler of a specific class can be registered at a time.
|
||||
// * If multiple of the same eventHandler are added DhApiResult will return
|
||||
// * the name of the already added handler and success = false.
|
||||
// */
|
||||
// public static DhApiResult on(Class<? extends ICoreDhApiEvent> eventInterface, ICoreDhApiEvent eventHandlerImplementation)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// DhApiEventInjector.INSTANCE.bind(eventInterface, eventHandlerImplementation);
|
||||
// return DhApiResult.createSuccess();
|
||||
// }
|
||||
// catch (IllegalStateException e)
|
||||
// {
|
||||
// return DhApiResult.createFail(e.getMessage());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Unregisters the given event handler for this event if one has been registered. <br>
|
||||
// * If no eventHandler of the given class has been registered the result will return
|
||||
// * success = false.
|
||||
// */
|
||||
// public static DhApiResult off(Class<? extends ICoreDhApiEvent> eventInterface, Class<ICoreDhApiEvent> eventHandlerClass)
|
||||
// {
|
||||
// if (DhApiEventInjector.INSTANCE.unbind(eventInterface, eventHandlerClass))
|
||||
// {
|
||||
// return DhApiResult.createSuccess();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return DhApiResult.createFail("No event handler [" + eventHandlerClass.getSimpleName() + "] was bound for the event [" + eventInterface.getSimpleName() + "].");
|
||||
// }
|
||||
// }
|
||||
/**
|
||||
* Registers the given event handler. <Br>
|
||||
* Only one eventHandler of a specific class can be registered at a time.
|
||||
* If multiple of the same eventHandler are added DhApiResult will return
|
||||
* the name of the already added handler and success = false.
|
||||
*/
|
||||
public static DhApiResult on(Class<? extends ICoreDhApiEvent> eventInterface, ICoreDhApiEvent eventHandlerImplementation)
|
||||
{
|
||||
try
|
||||
{
|
||||
DhApiEventInjector.INSTANCE.bind(eventInterface, eventHandlerImplementation);
|
||||
return DhApiResult.createSuccess();
|
||||
}
|
||||
catch (IllegalStateException e)
|
||||
{
|
||||
return DhApiResult.createFail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters the given event handler for this event if one has been registered. <br>
|
||||
* If no eventHandler of the given class has been registered the result will return
|
||||
* success = false.
|
||||
*/
|
||||
public static DhApiResult off(Class<? extends ICoreDhApiEvent> eventInterface, Class<ICoreDhApiEvent> eventHandlerClass)
|
||||
{
|
||||
if (DhApiEventInjector.INSTANCE.unbind(eventInterface, eventHandlerClass))
|
||||
{
|
||||
return DhApiResult.createSuccess();
|
||||
}
|
||||
else
|
||||
{
|
||||
return DhApiResult.createFail("No event handler [" + eventHandlerClass.getSimpleName() + "] was bound for the event [" + eventInterface.getSimpleName() + "].");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,15 +1,15 @@
|
||||
package com.seibel.lod.api.override;
|
||||
|
||||
import com.seibel.lod.api.items.interfaces.override.IDhApiWorldGenerator;
|
||||
import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
|
||||
import com.seibel.lod.api.items.objects.DhApiResult;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.override.worldGenerator.ICoreDhApiWorldGenerator;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.WorldGeneratorInjector;
|
||||
|
||||
/**
|
||||
* Handles adding world generator overrides.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-8-15
|
||||
* @version 2022-9-8
|
||||
*/
|
||||
public class DhApiWorldGeneratorOverrideRegister
|
||||
{
|
||||
@@ -21,11 +21,11 @@ public class DhApiWorldGeneratorOverrideRegister
|
||||
* If another world generator has already been registered, DhApiResult will return
|
||||
* the name of the previously registered generator and success = false.
|
||||
*/
|
||||
public static DhApiResult registerWorldGeneratorOverride(IDhApiWorldGenerator worldGenerator)
|
||||
public static DhApiResult registerWorldGeneratorOverride(ICoreDhApiWorldGenerator worldGenerator)
|
||||
{
|
||||
try
|
||||
{
|
||||
// WorldGeneratorInjector.INSTANCE.bind(worldGenerator);
|
||||
WorldGeneratorInjector.INSTANCE.bind(worldGenerator);
|
||||
return DhApiResult.createSuccess();
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -41,7 +41,7 @@ public class DhApiWorldGeneratorOverrideRegister
|
||||
* If another world generator has already been registered, DhApiResult will return
|
||||
* the name of the previously registered generator and success = false.
|
||||
*/
|
||||
public static DhApiResult registerWorldGeneratorOverride(IDhApiLevelWrapper levelWrapper, IDhApiWorldGenerator worldGenerator)
|
||||
public static DhApiResult registerWorldGeneratorOverride(IDhApiLevelWrapper levelWrapper, ICoreDhApiWorldGenerator worldGenerator)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.seibel.lod.core.api.external.coreImplementations.interfaces.override.worldGenerator;
|
||||
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.override.ICoreDhApiOverrideable;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world.ICoreDhApiLevelWrapper;
|
||||
import com.seibel.lod.core.enums.worldGeneration.EWorldGenThreadMode;
|
||||
import com.seibel.lod.core.enums.worldGeneration.EWorldGenerationStep;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
* @version 2022-9-8
|
||||
*/
|
||||
public interface ICoreDhApiWorldGenerator extends ICoreDhApiOverrideable
|
||||
{
|
||||
/** Returns which thread chunk generation requests can be created on. */
|
||||
EWorldGenThreadMode getCoreThreadingMode();
|
||||
|
||||
IChunkWrapper generateCoreChunk(int chunkPosX, int chunkPosZ, ICoreDhApiLevelWrapper serverLevelWrapper, EWorldGenerationStep maxStepToGenerate);
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.core.api.external.coreImplementations.objects.wrappers;
|
||||
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world.ICoreDhApiDimensionTypeWrapper;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.ICoreDhApiUnsafeWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IDimensionTypeWrapper;
|
||||
|
||||
/**
|
||||
* @author James Seibel
|
||||
* @version 2022-9-8
|
||||
*/
|
||||
public class CoreDhApiDimensionTypeWrapper implements ICoreDhApiDimensionTypeWrapper, ICoreDhApiUnsafeWrapper
|
||||
{
|
||||
private final IDimensionTypeWrapper dimensionTypeWrapper;
|
||||
|
||||
|
||||
public CoreDhApiDimensionTypeWrapper(IDimensionTypeWrapper newDimensionTypeWrapper)
|
||||
{
|
||||
this.dimensionTypeWrapper = newDimensionTypeWrapper;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getDimensionName() { return this.dimensionTypeWrapper.getDimensionName(); }
|
||||
|
||||
@Override
|
||||
public boolean hasCeiling() { return this.dimensionTypeWrapper.hasCeiling(); }
|
||||
|
||||
@Override
|
||||
public boolean hasSkyLight() { return this.dimensionTypeWrapper.hasSkyLight(); }
|
||||
|
||||
|
||||
@Override
|
||||
public Object getWrappedMcObject_UNSAFE() { return this.dimensionTypeWrapper.getWrappedMcObject(); }
|
||||
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2022 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.core.api.external.coreImplementations.objects.wrappers;
|
||||
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world.ICoreDhApiLevelWrapper;
|
||||
import com.seibel.lod.core.enums.ELevelType;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IDimensionTypeWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IServerLevelWrapper;
|
||||
|
||||
/**
|
||||
* Can be either a Server or Client level.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-9-8
|
||||
*/
|
||||
public class CoreDhApiLevelWrapper implements ICoreDhApiLevelWrapper
|
||||
{
|
||||
private final ILevelWrapper levelWrapper;
|
||||
private final IDimensionTypeWrapper dimensionTypeWrapper;
|
||||
|
||||
|
||||
public CoreDhApiLevelWrapper(ILevelWrapper newLevelWrapper)
|
||||
{
|
||||
this.levelWrapper = newLevelWrapper;
|
||||
this.dimensionTypeWrapper = this.levelWrapper.getDimensionType();
|
||||
}
|
||||
|
||||
|
||||
public ELevelType getLevelType()
|
||||
{
|
||||
if (this.levelWrapper.getClass().isAssignableFrom(IClientLevelWrapper.class))
|
||||
{
|
||||
return ELevelType.CLIENT_LEVEL;
|
||||
}
|
||||
else if (this.levelWrapper.getClass().isAssignableFrom(IServerLevelWrapper.class))
|
||||
{
|
||||
return ELevelType.CLIENT_LEVEL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// shouldn't normally happen, but just in case
|
||||
return ELevelType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCeiling() { return this.levelWrapper.hasCeiling(); }
|
||||
|
||||
public boolean hasSkyLight() { return this.levelWrapper.hasSkyLight(); }
|
||||
|
||||
public int getHeight() { return this.levelWrapper.getHeight(); }
|
||||
|
||||
public int getMinHeight() { return this.levelWrapper.getMinHeight(); }
|
||||
|
||||
@Override
|
||||
public Object getWrappedMcObject_UNSAFE() { return this.levelWrapper.unwrapLevel(); }
|
||||
|
||||
}
|
||||
+117
-114
@@ -19,7 +19,10 @@
|
||||
|
||||
package com.seibel.lod.core.handlers.dependencyInjection;
|
||||
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.override.worldGenerator.ICoreDhApiWorldGenerator;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.wrappers.world.ICoreDhApiLevelWrapper;
|
||||
import com.seibel.lod.core.util.StringUtil;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -28,122 +31,122 @@ import java.util.HashMap;
|
||||
* This is done so other mods can override our world generator(s) to improve or replace them.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-9-7
|
||||
* @version 2022-9-8
|
||||
*/
|
||||
public class WorldGeneratorInjector
|
||||
{
|
||||
// public static final WorldGeneratorInjector INSTANCE = new WorldGeneratorInjector();
|
||||
//
|
||||
// private final HashMap<IDhApiLevelWrapper, OverrideInjector<IDhApiWorldGenerator>> 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<IDhApiWorldGenerator> 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. <Br>
|
||||
// * 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(IDhApiWorldGenerator worldGeneratorImplementation) throws IllegalStateException, IllegalArgumentException
|
||||
// {
|
||||
// bind(null, worldGeneratorImplementation);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Binds the world generator to the given level. <Br>
|
||||
// * 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)
|
||||
// {
|
||||
// // bind this generator to a specific level
|
||||
// if (!worldGeneratorByLevelWrapper.containsKey(levelForWorldGenerator))
|
||||
// {
|
||||
// worldGeneratorByLevelWrapper.put(levelForWorldGenerator, new OverrideInjector<>(this.corePackagePath));
|
||||
// }
|
||||
//
|
||||
// worldGeneratorByLevelWrapper.get(levelForWorldGenerator).bind(IDhApiWorldGenerator.class, worldGeneratorImplementation);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // a null level wrapper binds the generator to all levels
|
||||
// backupUniversalWorldGenerators.bind(IDhApiWorldGenerator.class, worldGeneratorImplementation);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Returns the backup world generator with the highest priority. <br>
|
||||
// * See {@link OverrideInjector#get(Class) get(Class)} for more documentation.
|
||||
// *
|
||||
// * @see OverrideInjector#get(Class)
|
||||
// */
|
||||
// public IDhApiWorldGenerator get() throws ClassCastException
|
||||
// {
|
||||
// return backupUniversalWorldGenerators.get(IDhApiWorldGenerator.class);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the bound world generator with the highest priority. <br>
|
||||
// * (Returns a backup world generator if no world generators have been bound for this specific level.) <br>
|
||||
// * See {@link OverrideInjector#get(Class) get(Class)} for more documentation.
|
||||
// *
|
||||
// * @see OverrideInjector#get(Class)
|
||||
// */
|
||||
// public IDhApiWorldGenerator get(IDhApiLevelWrapper levelForWorldGenerator) throws ClassCastException
|
||||
// {
|
||||
// if (!worldGeneratorByLevelWrapper.containsKey(levelForWorldGenerator))
|
||||
// {
|
||||
// // no generator exists for this specific level.
|
||||
// // check for a backup universal world generator
|
||||
// return backupUniversalWorldGenerators.get(IDhApiWorldGenerator.class);
|
||||
// }
|
||||
//
|
||||
// // use the existing world generator
|
||||
// return worldGeneratorByLevelWrapper.get(levelForWorldGenerator).get(IDhApiWorldGenerator.class);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /** Removes all bound world generators. */
|
||||
// public void clearBoundDependencies() // TODO this should be done when leaving from the current world/server
|
||||
// {
|
||||
// this.worldGeneratorByLevelWrapper.clear();
|
||||
// this.backupUniversalWorldGenerators.clear();
|
||||
// }
|
||||
public static final WorldGeneratorInjector INSTANCE = new WorldGeneratorInjector();
|
||||
|
||||
private final HashMap<ICoreDhApiLevelWrapper, OverrideInjector> 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. <Br>
|
||||
* 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(ICoreDhApiWorldGenerator worldGeneratorImplementation) throws IllegalStateException, IllegalArgumentException
|
||||
{
|
||||
bind(null, worldGeneratorImplementation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds the world generator to the given level. <Br>
|
||||
* 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(ICoreDhApiLevelWrapper levelForWorldGenerator, ICoreDhApiWorldGenerator worldGeneratorImplementation) throws IllegalStateException, IllegalArgumentException
|
||||
{
|
||||
if (levelForWorldGenerator != null)
|
||||
{
|
||||
// bind this generator to a specific level
|
||||
if (!worldGeneratorByLevelWrapper.containsKey(levelForWorldGenerator))
|
||||
{
|
||||
worldGeneratorByLevelWrapper.put(levelForWorldGenerator, new OverrideInjector(this.corePackagePath));
|
||||
}
|
||||
|
||||
worldGeneratorByLevelWrapper.get(levelForWorldGenerator).bind(ICoreDhApiWorldGenerator.class, worldGeneratorImplementation);
|
||||
}
|
||||
else
|
||||
{
|
||||
// a null level wrapper binds the generator to all levels
|
||||
backupUniversalWorldGenerators.bind(ICoreDhApiWorldGenerator.class, worldGeneratorImplementation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the backup world generator with the highest priority. <br>
|
||||
* See {@link OverrideInjector#get(Class) get(Class)} for more documentation.
|
||||
*
|
||||
* @see OverrideInjector#get(Class)
|
||||
*/
|
||||
public ICoreDhApiWorldGenerator get() throws ClassCastException
|
||||
{
|
||||
return backupUniversalWorldGenerators.get(ICoreDhApiWorldGenerator.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bound world generator with the highest priority. <br>
|
||||
* (Returns a backup world generator if no world generators have been bound for this specific level.) <br>
|
||||
* See {@link OverrideInjector#get(Class) get(Class)} for more documentation.
|
||||
*
|
||||
* @see OverrideInjector#get(Class)
|
||||
*/
|
||||
public ICoreDhApiWorldGenerator get(ICoreDhApiLevelWrapper levelForWorldGenerator) throws ClassCastException
|
||||
{
|
||||
if (!worldGeneratorByLevelWrapper.containsKey(levelForWorldGenerator))
|
||||
{
|
||||
// no generator exists for this specific level.
|
||||
// check for a backup universal world generator
|
||||
return backupUniversalWorldGenerators.get(ICoreDhApiWorldGenerator.class);
|
||||
}
|
||||
|
||||
// use the existing world generator
|
||||
return worldGeneratorByLevelWrapper.get(levelForWorldGenerator).get(ICoreDhApiWorldGenerator.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Removes all bound world generators. */
|
||||
public void clearBoundDependencies() // TODO this should be done when leaving the current world/server
|
||||
{
|
||||
this.worldGeneratorByLevelWrapper.clear();
|
||||
this.backupUniversalWorldGenerators.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-13
@@ -1,7 +1,8 @@
|
||||
package testItems.worldGeneratorInjection.objects;
|
||||
|
||||
import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneration.EDhApiWorldGenThreadMode;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneration.EDhApiWorldGenerationStep;
|
||||
import com.seibel.lod.core.api.external.coreImplementations.interfaces.override.worldGenerator.ICoreDhApiWorldGenerator;
|
||||
import com.seibel.lod.core.enums.worldGeneration.EWorldGenThreadMode;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.OverrideInjector;
|
||||
|
||||
/**
|
||||
* Dummy test implementation object for world generator injection unit tests.
|
||||
@@ -9,27 +10,27 @@ import com.seibel.lod.core.api.external.coreImplementations.enums.worldGeneratio
|
||||
* @author James Seibel
|
||||
* @version 2022-7-26
|
||||
*/
|
||||
//public class WorldGeneratorTestPrimary implements IDhApiWorldGenerator
|
||||
//public class WorldGeneratorTestPrimary implements ICoreDhApiWorldGenerator
|
||||
//{
|
||||
// public static EDhApiWorldGenThreadMode THREAD_MODE = EDhApiWorldGenThreadMode.MULTI_THREADED;
|
||||
//
|
||||
//
|
||||
// public static EWorldGenThreadMode THREAD_MODE = EWorldGenThreadMode.MULTI_THREADED;
|
||||
//
|
||||
//
|
||||
// //==============//
|
||||
// // IOverridable //
|
||||
// //==============//
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public EDhApiOverridePriority getOverrideType() { return EDhApiOverridePriority.PRIMARY; }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public int getOverridePriority() { return OverrideInjector.DEFAULT_NON_CORE_OVERRIDE_PRIORITY; }
|
||||
//
|
||||
//
|
||||
//
|
||||
// //======================//
|
||||
// // IDhApiWorldGenerator //
|
||||
// //======================//
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public EDhApiWorldGenThreadMode getThreadingMode() { return THREAD_MODE; }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public IDhApiChunkWrapper generateChunk(int chunkPosX, int chunkPosZ, IDhApiLevelWrapper serverLevelWrapper, EDhApiWorldGenerationStep maxStepToGenerate)
|
||||
// {
|
||||
|
||||
Reference in New Issue
Block a user