Add worldGen, Override, and DataRepo variables to DhApiMain

This commit is contained in:
James Seibel
2022-09-16 23:57:55 -05:00
parent 52ed3c8733
commit 47645a6346
5 changed files with 177 additions and 107 deletions
@@ -1,13 +1,28 @@
package com.seibel.lod.api;
import com.seibel.lod.api.items.interfaces.config.IDhApiConfig;
import com.seibel.lod.api.interfaces.config.IDhApiConfig;
import com.seibel.lod.api.interfaces.override.IDhApiOverrideable;
import com.seibel.lod.api.interfaces.override.worldGenerator.IDhApiWorldGeneratorOverrideRegister;
import com.seibel.lod.api.methods.data.DhApiTerrainDataRepo;
import com.seibel.lod.api.methods.override.DhApiWorldGeneratorOverrideRegister;
import com.seibel.lod.core.DependencyInjection.DhApiEventInjector;
import com.seibel.lod.core.DependencyInjection.OverrideInjector;
import com.seibel.lod.core.ModInfo;
import com.seibel.lod.api.interfaces.data.IDhApiTerrainDataRepo;
import com.seibel.lod.core.interfaces.dependencyInjection.IDhApiEventInjector;
import com.seibel.lod.core.interfaces.dependencyInjection.IOverrideInjector;
/**
* This holds API methods related to version numbers and other unchanging endpoints.
* This shouldn't change between API versions.
* This is the masthead of the API, almost everything you could want to do
* can be achieved from here. <br>
* For example: you can access singletons which handle the config or event binding. <br><br>
*
* <strong>Q:</strong> Why should I use this class instead of just getting the API singleton I need? <br>
*
* <strong>A:</strong> This way there is a lower chance of your code breaking if we change something on our end.
* For example, if we realized there is a much better way of handling dependency injection we would keep the
* interface the same so your code doesn't have to change. Whereas if you were directly referencing
* the concrete object we replaced, there would be issues.
*
* @author James Seibel
* @version 2022-9-16
@@ -31,10 +46,19 @@ public class DhApiMain
/** Used to bind/unbind DH Api events. */
public static final IDhApiEventInjector events = DhApiEventInjector.INSTANCE;
/** Used to bind/unbind DH Api events. */
public static final IDhApiWorldGeneratorOverrideRegister worldGenOverrides = DhApiWorldGeneratorOverrideRegister.INSTANCE;
/** This version should only be updated when breaking changes are introduced to the DH API */
/** Used to bind overrides to change DH's core behavior. */
public static final IOverrideInjector<IDhApiOverrideable> overrides = OverrideInjector.INSTANCE;
/** Used to interact with DH's terrain data. */
public static final IDhApiTerrainDataRepo terrainRepo = DhApiTerrainDataRepo.INSTANCE;
/** This version should only be updated when breaking changes are introduced to the DH API. */
public static int getApiMajorVersion() { return ModInfo.API_MAJOR_VERSION; }
/** This version should be updated whenever new methods are added to the DH API */
/** This version should be updated whenever new methods are added to the DH API. */
public static int getApiMinorVersion() { return ModInfo.API_MINOR_VERSION; }
/** Returns the mod's version number in the format: Major.Minor.Patch */
@@ -0,0 +1,48 @@
package com.seibel.lod.api.interfaces.data;
import com.seibel.lod.api.objects.DhApiResult;
import com.seibel.lod.api.objects.data.DhApiTerrainDataPoint;
/**
* @author James Seibel
* @version 2022-9-16
*/
public interface IDhApiTerrainDataRepo
{
/**
* Returns the terrain data at the given block position.
* Null if the position hasn't been generated.
*/
DhApiTerrainDataPoint getDataAtBlockPos(int blockPosX, int blockPosY, int blockPosZ);
/** Sets the terrain data at the given block position. */
DhApiResult setDataAtBlockPos(int blockPosX, int blockPosY, int blockPosZ, DhApiTerrainDataPoint newData);
/**
* Returns the average color for the chunk at the given chunk position.
* Returns null if the position hasn't been generated.
*/
DhApiTerrainDataPoint getDataAtChunkPos(int chunkPosX, int chunkPosZ);
/** Sets the terrain data at the given chunk position. */
DhApiResult setDataAtChunkPos(int chunkPosX, int chunkPosZ, DhApiTerrainDataPoint newData);
/**
* Returns the average color for the chunk at the given chunk position.
* May return inaccurate data if the whole region hasn't been generated yet.
* Returns null if the position hasn't been generated.
*/
DhApiTerrainDataPoint getDataAtRegionPos(int regionPosX, int regionPosZ);
/** Sets the terrain data at the given chunk position. */
DhApiResult setDataAtRegionPos(int regionPosX, int regionPosZ, DhApiTerrainDataPoint newData);
/**
* Returns the average color for the chunk at the given chunk position.
* May return inaccurate data if the whole region hasn't been generated yet.
* Returns null if the position hasn't been generated.
*/
DhApiTerrainDataPoint getDataAtDetailLevelAndPos(short detailLevel, int relativePosX, int relativePosY, int relativePosZ);
/** Sets the terrain data at the given chunk position. */
DhApiResult setDataAtRegionPos(short detailLevel, int relativePosX, int relativePosY, int relativePosZ, DhApiTerrainDataPoint newData);
}
@@ -0,0 +1,34 @@
package com.seibel.lod.api.interfaces.override.worldGenerator;
import com.seibel.lod.api.interfaces.world.IDhApiLevelWrapper;
import com.seibel.lod.api.objects.DhApiResult;
import com.seibel.lod.core.DependencyInjection.WorldGeneratorInjector;
/**
* Handles adding world generator overrides.
*
* @author James Seibel
* @version 2022-9-16
*/
public interface IDhApiWorldGeneratorOverrideRegister
{
/**
* Registers the given world generator. <Br> <Br>
*
* This registers a backup world generator for all levels and will be overridden if there
* is a world generator for the specific level. <Br>
* 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. <Br> <Br>
*
* Only one world generator can be registered for a specific level at a given time. <Br>
* If another world generator has already been registered, DhApiResult will return
* the name of the previously registered generator and success = false.
*/
DhApiResult registerWorldGeneratorOverride(IDhApiLevelWrapper levelWrapper, IDhApiWorldGenerator worldGenerator);
}
@@ -1,7 +1,8 @@
package com.seibel.lod.api.methods.data;
import com.seibel.lod.api.items.objects.DhApiResult;
import com.seibel.lod.api.items.objects.data.DhApiTerrainDataPoint;
import com.seibel.lod.api.objects.DhApiResult;
import com.seibel.lod.api.objects.data.DhApiTerrainDataPoint;
import com.seibel.lod.api.interfaces.data.IDhApiTerrainDataRepo;
/**
@@ -10,67 +11,35 @@ import com.seibel.lod.api.items.objects.data.DhApiTerrainDataPoint;
* TODO once 1.7's data refactor is complete ask Leetom and/or Leonardo for help on setting these up
*
* @author James Seibel
* @version 2022-7-12
* @version 2022-9-16
*/
public class DhApiTerrainDataRepo
public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
{
/**
* Returns the terrain data at the given block position.
* Null if the position hasn't been generated.
*/
public static DhApiTerrainDataPoint getDataAtBlockPos(int blockPosX, int blockPosY, int blockPosZ)
{
throw new UnsupportedOperationException();
}
/** Sets the terrain data at the given block position. */
public static DhApiResult setDataAtBlockPos(int blockPosX, int blockPosY, int blockPosZ, DhApiTerrainDataPoint newData)
{
throw new UnsupportedOperationException();
}
public static DhApiTerrainDataRepo INSTANCE = new DhApiTerrainDataRepo();
/**
* Returns the average color for the chunk at the given chunk position.
* Returns null if the position hasn't been generated.
*/
public static DhApiTerrainDataPoint getDataAtChunkPos(int chunkPosX, int chunkPosZ)
{
throw new UnsupportedOperationException();
}
/** Sets the terrain data at the given chunk position. */
public static DhApiResult setDataAtChunkPos(int chunkPosX, int chunkPosZ, DhApiTerrainDataPoint newData)
{
throw new UnsupportedOperationException();
}
/**
* Returns the average color for the chunk at the given chunk position.
* May return inaccurate data if the whole region hasn't been generated yet.
* Returns null if the position hasn't been generated.
*/
public static DhApiTerrainDataPoint getDataAtRegionPos(int regionPosX, int regionPosZ)
{
throw new UnsupportedOperationException();
}
/** Sets the terrain data at the given chunk position. */
public static DhApiResult setDataAtRegionPos(int regionPosX, int regionPosZ, DhApiTerrainDataPoint newData)
{
throw new UnsupportedOperationException();
}
private DhApiTerrainDataRepo() { }
/**
* Returns the average color for the chunk at the given chunk position.
* May return inaccurate data if the whole region hasn't been generated yet.
* Returns null if the position hasn't been generated.
*/
public static DhApiTerrainDataPoint getDataAtDetailLevelAndPos(short detailLevel, int relativePosX, int relativePosY, int relativePosZ)
{
throw new UnsupportedOperationException();
}
/** Sets the terrain data at the given chunk position. */
public static DhApiResult setDataAtRegionPos(short detailLevel, int relativePosX, int relativePosY, int relativePosZ, DhApiTerrainDataPoint newData)
{
throw new UnsupportedOperationException();
}
@Override
public DhApiTerrainDataPoint getDataAtBlockPos(int blockPosX, int blockPosY, int blockPosZ) { throw new UnsupportedOperationException(); }
@Override
public DhApiResult setDataAtBlockPos(int blockPosX, int blockPosY, int blockPosZ, DhApiTerrainDataPoint newData) { throw new UnsupportedOperationException(); }
@Override
public DhApiTerrainDataPoint getDataAtChunkPos(int chunkPosX, int chunkPosZ) { throw new UnsupportedOperationException(); }
@Override
public DhApiResult setDataAtChunkPos(int chunkPosX, int chunkPosZ, DhApiTerrainDataPoint newData) { throw new UnsupportedOperationException(); }
@Override
public DhApiTerrainDataPoint getDataAtRegionPos(int regionPosX, int regionPosZ) { throw new UnsupportedOperationException(); }
@Override
public DhApiResult setDataAtRegionPos(int regionPosX, int regionPosZ, DhApiTerrainDataPoint newData) { throw new UnsupportedOperationException(); }
@Override
public DhApiTerrainDataPoint getDataAtDetailLevelAndPos(short detailLevel, int relativePosX, int relativePosY, int relativePosZ) { throw new UnsupportedOperationException(); }
@Override
public DhApiResult setDataAtRegionPos(short detailLevel, int relativePosX, int relativePosY, int relativePosZ, DhApiTerrainDataPoint newData) { throw new UnsupportedOperationException(); }
}
@@ -1,56 +1,51 @@
package com.seibel.lod.api.methods.override;
import com.seibel.lod.api.items.interfaces.world.IDhApiLevelWrapper;
import com.seibel.lod.api.items.objects.DhApiResult;
import com.seibel.lod.api.interfaces.override.worldGenerator.IDhApiWorldGenerator;
import com.seibel.lod.api.interfaces.override.worldGenerator.IDhApiWorldGeneratorOverrideRegister;
import com.seibel.lod.api.interfaces.world.IDhApiLevelWrapper;
import com.seibel.lod.api.objects.DhApiResult;
import com.seibel.lod.core.DependencyInjection.WorldGeneratorInjector;
/**
* Handles adding world generator overrides.
*
* @author James Seibel
* @version 2022-9-8
* @version 2022-9-16
*/
public class DhApiWorldGeneratorOverrideRegister
public class DhApiWorldGeneratorOverrideRegister implements IDhApiWorldGeneratorOverrideRegister
{
/**
* Registers the given world generator. <Br> <Br>
*
* This registers a backup world generator for all levels and will be overridden if there
* is a world generator for the specific level. <Br>
* 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(ICoreDhApiWorldGenerator worldGenerator)
// {
// try
// {
// WorldGeneratorInjector.INSTANCE.bind(worldGenerator);
// return DhApiResult.createSuccess();
// }
// catch (Exception e)
// {
// return DhApiResult.createFail(e.getMessage());
// }
// }
public static DhApiWorldGeneratorOverrideRegister INSTANCE = new DhApiWorldGeneratorOverrideRegister();
/**
* Registers the given world generator for the given level. <Br> <Br>
*
* Only one world generator can be registered for a specific level at a given time. <Br>
* 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, ICoreDhApiWorldGenerator worldGenerator)
// {
// try
// {
// WorldGeneratorInjector.INSTANCE.bind(levelWrapper, worldGenerator);
// return DhApiResult.createSuccess();
// }
// catch (Exception e)
// {
// return DhApiResult.createFail(e.getMessage());
// }
// }
private DhApiWorldGeneratorOverrideRegister() { }
@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)
{
try
{
WorldGeneratorInjector.INSTANCE.bind(levelWrapper, worldGenerator);
return DhApiResult.createSuccess();
}
catch (Exception e)
{
return DhApiResult.createFail(e.getMessage());
}
}
}