Make API setters return success booleans

This commit is contained in:
James Seibel
2022-05-28 18:22:09 -05:00
parent 8133620fcf
commit e862124c68
3 changed files with 76 additions and 28 deletions
@@ -1,24 +1,43 @@
package com.seibel.lod.core.api.external;
import com.seibel.lod.core.config.types.ConfigEntry;
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
/**
* This stores objects and variables that
* are shared between the different Core external api classes. <br> <br>
* are shared between the different external api classes. <br> <br>
*
* The external api package is designed to hold any code that
* interfaces between Distant Horizons and other mods or projects.
* For example: if a weather mod wanted to disable LOD rendering during a blizzard
* interfaces between Distant Horizons and other mods or projects. <Br>
* <strong>For example:</strong> if a weather mod wanted to disable LOD rendering during a blizzard
* they would do that through a method in the external api.
*
*
* @author James Seibel
* @version 2022-4-24
* @version 2022-5-28
*/
public class ExternalApiShared
{
public static final ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class);
/**
* If the ConfigEntry doesn't allowApiOverride nothing happens.
*
* @param configEntry The ConfigEntry to set
* @param newValue the value to set the config too
* @param <T> the type the config accepts
*
* @return true if the value was set, false otherwise
*/
public static <T> boolean attemptToSetApiValue(ConfigEntry<T> configEntry, T newValue)
{
if (configEntry.allowApiOverride)
{
configEntry.set(newValue);
return true;
}
else
{
return false;
}
}
}
@@ -1,40 +1,53 @@
package com.seibel.lod.core.api.external.config.client;
import com.seibel.lod.core.api.external.ExternalApiShared;
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
import com.seibel.lod.core.config.Config.Client.Advanced.Threading;
/**
* General Threading settings.
*
* @author James Seibel
* @version 2022-4-26
* @version 2022-5-28
*/
public class DhApiThreading
{
private static final ILodConfigWrapperSingleton.IClient.IAdvanced.IThreading threadSettings = ExternalApiShared.CONFIG.client().advanced().threading();
/** Number of threads used to generate terrain outside the vanilla render distance. */
/**
* Returns the number of threads used to generate
* terrain outside the vanilla render distance.
*/
public static int getNumberOfWorldGeneratorThreads_v1()
{
return threadSettings._getWorldGenerationThreadPoolSize();
return Threading.getWorldGenerationThreadPoolSize();
}
/** @return true if the value was set, false otherwise. */
public static boolean setNumberOfWorldGeneratorThreads_v1(double newValue)
{
return ExternalApiShared.attemptToSetApiValue(Threading.numberOfWorldGenerationThreads, newValue);
}
/**
* Returns a number between 0.0 and 1.0.
* Returns a number between 0.0 and 1.0, represents the expected time a world generator
* thread will be actively generating terrain as a percentage. <br> <br>
*
* 0.0 = active 0% of the time
* 0.5 = active 50% of the time
* 1.0 = active 100% of the time
* 0.0 = active 0% of the time <br>
* 0.5 = active 50% of the time <br>
* 1.0 = active 100% of the time <br>
*/
public static double getWorldGeneratorThreadActivePercentage_v1()
{
return threadSettings._getWorldGenerationPartialRunTime();
return Threading.getWorldGenerationPartialRunTime();
}
/** Number of threads used to rebuild geometry data. */
/** Returns the number of threads used to rebuild geometry data. */
public static int getNumberOfBufferBuilderThreads_v1()
{
return threadSettings.getNumberOfBufferBuilderThreads();
return Threading.numberOfBufferBuilderThreads.get();
}
/** @return true if the value was set, false otherwise. */
public static boolean setNumberOfBufferBuilderThreads_v1(int newValue)
{
return ExternalApiShared.attemptToSetApiValue(Threading.numberOfBufferBuilderThreads, newValue);
}
}
@@ -1,28 +1,44 @@
package com.seibel.lod.core.api.external.config.client.graphics;
import com.seibel.lod.core.api.external.ExternalApiShared;
import com.seibel.lod.core.config.Config;
import com.seibel.lod.core.enums.rendering.RendererType;
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
import com.seibel.lod.core.config.Config.Client.Graphics.Quality;
import com.seibel.lod.core.config.Config.Client.Advanced.Debugging;
/**
* General graphics settings.
*
* @author James Seibel
* @version 2022-4-26
* @version 2022-5-28
*/
public class DhApiGraphicsGeneral
{
private static final ILodConfigWrapperSingleton.IClient.IGraphics.IQuality qualitySettings = ExternalApiShared.CONFIG.client().graphics().quality();
/** Returns the current Disant Horizons render distance radius in chunks. */
public static int getLodChunkRenderDistance_v1()
{
return qualitySettings.getLodChunkRenderDistance();
return Quality.lodChunkRenderDistance.get();
}
/** @return true if the value was set, false otherwise. */
public static boolean setLodChunkRenderDistance_v1(int newValue)
{
return ExternalApiShared.attemptToSetApiValue(Quality.lodChunkRenderDistance, newValue);
}
/**
* Returns true if rendering is currently enabled. <br>
* Returns false when rendering is disabled or debug rendering is enabled.
*/
public static boolean getRenderingEnabled_v1()
{
return ExternalApiShared.CONFIG.client().advanced().debugging().getRendererType() == RendererType.DEFAULT;
return Config.Client.Advanced.Debugging.rendererType.get() == RendererType.DEFAULT;
}
/** @return true if the value was set, false otherwise. */
public static boolean setRenderingEnabled_v1(boolean enableRendering)
{
RendererType newValue = enableRendering ? RendererType.DEFAULT : RendererType.DISABLED;
return ExternalApiShared.attemptToSetApiValue(Debugging.rendererType, newValue);
}
}