Add IReflectionHandler
This commit is contained in:
@@ -22,6 +22,7 @@ package com.seibel.lod.api.lod;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.seibel.lod.ModInfo;
|
||||
import com.seibel.lod.core.builders.worldGeneration.LodGenWorker;
|
||||
import com.seibel.lod.core.objects.lod.LodDimension;
|
||||
import com.seibel.lod.core.objects.math.Mat4f;
|
||||
@@ -47,7 +48,7 @@ import net.minecraft.profiler.IProfiler;
|
||||
public class ClientApi
|
||||
{
|
||||
public static final ClientApi INSTANCE = new ClientApi();
|
||||
public static final Logger LOGGER = LogManager.getLogger("LOD");
|
||||
public static final Logger LOGGER = LogManager.getLogger(ModInfo.NAME);
|
||||
|
||||
public static LodRenderer renderer = new LodRenderer(ApiShared.lodBufferBuilderFactory);
|
||||
|
||||
|
||||
@@ -49,8 +49,8 @@ import com.seibel.lod.core.wrapperAdapters.SingletonHandler;
|
||||
import com.seibel.lod.core.wrapperAdapters.block.AbstractBlockPosWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.chunk.AbstractChunkPosWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.config.ILodConfigWrapperSingleton;
|
||||
import com.seibel.lod.core.wrapperAdapters.handlers.IReflectionHandler;
|
||||
import com.seibel.lod.core.wrapperAdapters.minecraft.IMinecraftWrapper;
|
||||
import com.seibel.lod.wrappers.handlers.ReflectionHandler;
|
||||
import com.seibel.lod.wrappers.minecraft.MinecraftRenderWrapper;
|
||||
|
||||
import net.minecraft.profiler.IProfiler;
|
||||
@@ -67,6 +67,7 @@ public class LodRenderer
|
||||
private static final IMinecraftWrapper MC = SingletonHandler.get(IMinecraftWrapper.class);
|
||||
private static final MinecraftRenderWrapper MC_RENDER = MinecraftRenderWrapper.INSTANCE;
|
||||
private static final ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class);
|
||||
private static final IReflectionHandler REFLECTION_HANDLER = SingletonHandler.get(IReflectionHandler.class);
|
||||
private static final IWrapperFactory FACTORY = SingletonHandler.get(IWrapperFactory.class);
|
||||
|
||||
|
||||
@@ -179,7 +180,6 @@ public class LodRenderer
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO move the buffer regeneration logic into its own class (probably called in the client proxy instead)
|
||||
// starting here...
|
||||
determineIfLodsShouldRegenerate(lodDim, partialTicks);
|
||||
@@ -690,7 +690,7 @@ public class LodRenderer
|
||||
NearFarFogSettings fogSettings = new NearFarFogSettings();
|
||||
|
||||
|
||||
FogQuality quality = ReflectionHandler.INSTANCE.getFogQuality();
|
||||
FogQuality quality = REFLECTION_HANDLER.getFogQuality();
|
||||
FogDrawOverride override = CONFIG.client().graphics().fogQuality().getFogDrawOverride();
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizon mod (formerly the LOD Mod),
|
||||
* licensed under the GNU GPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.lod.core.wrapperAdapters.handlers;
|
||||
|
||||
import com.seibel.lod.core.enums.rendering.FogQuality;
|
||||
import com.seibel.lod.core.objects.math.Mat4f;
|
||||
|
||||
/**
|
||||
* A singleton used to get variables from methods
|
||||
* where they are private or potentially absent.
|
||||
* Specifically the fog setting in Optifine or the
|
||||
* presence/absence of other mods.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 11-18-2021
|
||||
*/
|
||||
public interface IReflectionHandler
|
||||
{
|
||||
/**
|
||||
* Get what type of fog optifine is currently set to render.
|
||||
* @return the fog quality
|
||||
*/
|
||||
public FogQuality getFogQuality();
|
||||
|
||||
/** Detect if Vivecraft is present. Attempts to find the "VRRenderer" class. */
|
||||
public boolean vivecraftPresent();
|
||||
|
||||
/**
|
||||
* Modifies the projection matrix's clip planes.
|
||||
* The projection matrix must be in column-major format.
|
||||
*
|
||||
* @param projectionMatrix The projection matrix to be modified.
|
||||
* @param newNearClipPlane the new near clip plane value.
|
||||
* @param newFarClipPlane the new far clip plane value.
|
||||
* @return The modified matrix.
|
||||
*/
|
||||
public Mat4f ModifyProjectionClipPlanes(Mat4f projectionMatrix, float newNearClipPlane, float newFarClipPlane);
|
||||
}
|
||||
@@ -4,10 +4,12 @@ import com.seibel.lod.core.wrapperAdapters.IWrapperFactory;
|
||||
import com.seibel.lod.core.wrapperAdapters.SingletonHandler;
|
||||
import com.seibel.lod.core.wrapperAdapters.block.IBlockColorSingletonWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.config.ILodConfigWrapperSingleton;
|
||||
import com.seibel.lod.core.wrapperAdapters.handlers.IReflectionHandler;
|
||||
import com.seibel.lod.core.wrapperAdapters.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.lod.core.wrapperAdapters.minecraft.IMinecraftWrapper;
|
||||
import com.seibel.lod.wrappers.block.BlockColorSingletonWrapper;
|
||||
import com.seibel.lod.wrappers.config.LodConfigWrapperSingleton;
|
||||
import com.seibel.lod.wrappers.handlers.ReflectionHandler;
|
||||
import com.seibel.lod.wrappers.minecraft.MinecraftRenderWrapper;
|
||||
import com.seibel.lod.wrappers.minecraft.MinecraftWrapper;
|
||||
|
||||
@@ -29,5 +31,6 @@ public class DependencySetup
|
||||
SingletonHandler.bind(IMinecraftWrapper.class, MinecraftWrapper.INSTANCE);
|
||||
SingletonHandler.bind(IMinecraftRenderWrapper.class, MinecraftRenderWrapper.INSTANCE);
|
||||
SingletonHandler.bind(IWrapperFactory.class, WrapperFactory.INSTANCE);
|
||||
SingletonHandler.bind(IReflectionHandler.class, ReflectionHandler.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,20 +22,28 @@ package com.seibel.lod.wrappers.handlers;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.seibel.lod.api.lod.ClientApi;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.seibel.lod.ModInfo;
|
||||
import com.seibel.lod.core.enums.rendering.FogQuality;
|
||||
import com.seibel.lod.core.objects.math.Mat4f;
|
||||
import com.seibel.lod.core.wrapperAdapters.handlers.IReflectionHandler;
|
||||
import com.seibel.lod.wrappers.minecraft.MinecraftWrapper;
|
||||
|
||||
/**
|
||||
* This object is used to get variables from methods
|
||||
* where they are private. Specifically the fog setting
|
||||
* in Optifine.
|
||||
* A singleton used to get variables from methods
|
||||
* where they are private or potentially absent.
|
||||
* Specifically the fog setting in Optifine or the
|
||||
* presence/absence of other mods.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 9 -25-2021
|
||||
* @version 11-18-2021
|
||||
*/
|
||||
public class ReflectionHandler
|
||||
public class ReflectionHandler implements IReflectionHandler
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger(ModInfo.NAME + "-" + ReflectionHandler.class.getSimpleName());
|
||||
|
||||
public static final ReflectionHandler INSTANCE = new ReflectionHandler();
|
||||
|
||||
public Field ofFogField = null;
|
||||
@@ -49,9 +57,7 @@ public class ReflectionHandler
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* finds the Optifine fog type field
|
||||
*/
|
||||
/** finds the Optifine fog type field */
|
||||
private void setupFogField()
|
||||
{
|
||||
// get every variable from the entity renderer
|
||||
@@ -70,7 +76,7 @@ public class ReflectionHandler
|
||||
// we didn't find the field,
|
||||
// either optifine isn't installed, or
|
||||
// optifine changed the name of the variable
|
||||
ClientApi.LOGGER.info(ReflectionHandler.class.getSimpleName() + ": unable to find the Optifine fog field. If Optifine isn't installed this can be ignored.");
|
||||
LOGGER.info(ReflectionHandler.class.getSimpleName() + ": unable to find the Optifine fog field. If Optifine isn't installed this can be ignored.");
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +84,7 @@ public class ReflectionHandler
|
||||
* Get what type of fog optifine is currently set to render.
|
||||
* @return the fog quality
|
||||
*/
|
||||
@Override
|
||||
public FogQuality getFogQuality()
|
||||
{
|
||||
if (ofFogField == null)
|
||||
@@ -116,8 +123,11 @@ public class ReflectionHandler
|
||||
}
|
||||
}
|
||||
|
||||
/** Detect if Vivecraft is present using reflection. Attempts to find the "VRRenderer" class. */
|
||||
public boolean detectVivecraft()
|
||||
|
||||
|
||||
/** Detect if Vivecraft is present. Attempts to find the "VRRenderer" class. */
|
||||
@Override
|
||||
public boolean vivecraftPresent()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -126,31 +136,32 @@ public class ReflectionHandler
|
||||
}
|
||||
catch (ClassNotFoundException ignored)
|
||||
{
|
||||
System.out.println("Vivecraft not detected.");
|
||||
LOGGER.info(ReflectionHandler.class.getSimpleName() + ": Vivecraft not detected.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies a projection matrix's clip planes.
|
||||
* The projection matrix must be in a column-major format.
|
||||
* Modifies the projection matrix's clip planes.
|
||||
* The projection matrix must be in column-major format.
|
||||
*
|
||||
* @param projectionMatrix The projection matrix to be modified.
|
||||
* @param nearClipPlane the new near clip plane value.
|
||||
* @param farClipPlane the new far clip plane value.
|
||||
* @param newNearClipPlane the new near clip plane value.
|
||||
* @param newFarClipPlane the new far clip plane value.
|
||||
* @return The modified matrix.
|
||||
*/
|
||||
public Mat4f Matrix4fModifyClipPlanes(Mat4f projectionMatrix, float nearClipPlane, float farClipPlane)
|
||||
@Override
|
||||
public Mat4f ModifyProjectionClipPlanes(Mat4f projectionMatrix, float newNearClipPlane, float newFarClipPlane)
|
||||
{
|
||||
// find the matrix values.
|
||||
float nearMatrixValue = -((farClipPlane + nearClipPlane) / (farClipPlane - nearClipPlane));
|
||||
float farMatrixValue = -((2 * farClipPlane * nearClipPlane) / (farClipPlane - nearClipPlane));
|
||||
float nearMatrixValue = -((newFarClipPlane + newNearClipPlane) / (newFarClipPlane - newNearClipPlane));
|
||||
float farMatrixValue = -((2 * newFarClipPlane * newNearClipPlane) / (newFarClipPlane - newNearClipPlane));
|
||||
|
||||
try
|
||||
{
|
||||
// TODO this was originally created before we had the Mat4f object,
|
||||
// so this doesn't need to be done with reflection anymore.
|
||||
// And should be moved to the LodRenderer
|
||||
// And should be moved to RenderUtil
|
||||
|
||||
// get the fields of the projectionMatrix
|
||||
Field[] fields = projectionMatrix.getClass().getDeclaredFields();
|
||||
|
||||
Reference in New Issue
Block a user