Remove unused wrapper functions and refactor

This commit is contained in:
James Seibel
2025-12-10 18:50:35 -06:00
parent 8f0930fa02
commit 895e04b7cc
14 changed files with 132 additions and 160 deletions
@@ -9,6 +9,7 @@ import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.network.event.internal.CloseInternalEvent;
import com.seibel.distanthorizons.core.network.messages.base.LevelInitMessage;
import com.seibel.distanthorizons.core.network.session.NetworkSession;
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import org.jetbrains.annotations.NotNull;
@@ -89,7 +90,7 @@ public class ClientPluginChannelApi
LOGGER.info("Server level key received: [" + msg.levelKey + "].");
MC.executeOnRenderThread(() ->
GLProxy.getInstance().queueRunningOnRenderThread(() ->
{
IClientLevelWrapper clientLevel = MC.getWrappedClientLevel(true);
IServerKeyedClientLevel existingKeyedClientLevel = KEYED_CLIENT_LEVEL_MANAGER.getServerKeyedLevel();
@@ -123,7 +123,6 @@ public class Config
{
// common config links need to have their destination
// since they aren't part of "client" config class
// TODO determine their destination programically instead of hard coding the value
public static ConfigUIComment advancedHeader = new ConfigUIComment.Builder().setParentConfigClass(Advanced.class).build();
@@ -169,6 +168,20 @@ public class Config
public static ConfigCategory culling = new ConfigCategory.Builder().set(Culling.class).build();
public static ConfigUISpacer cullingSpacer = new ConfigUISpacer.Builder().build();
public static ConfigEntry<Boolean> overrideVanillaGraphicsSettings = new ConfigEntry.Builder<Boolean>()
.set(true)
.comment("" +
"If true some vanilla graphics settings will be automatically changed \n" +
"during DH setup to provide a better experience. \n" +
" \n" +
"IE disabling vanilla clouds (which render on top of DH LODs), \n" +
" and chunk fading (DH already fades MC chunks) \n" +
"")
.build();
public static ConfigUISpacer overrideVanillaSpacer = new ConfigUISpacer.Builder().build();
public static ConfigCategory experimental = new ConfigCategory.Builder().set(Experimental.class).build();
@@ -260,7 +273,7 @@ public class Config
public static ConfigEntry<Double> lodBias = new ConfigEntry.Builder<Double>()
.setMinDefaultMax(0d, 0d, null)
.comment(""
+ "What the value should vanilla Minecraft's texture LodBias be? \n"
+ "What value should vanilla Minecraft's texture LodBias be? \n"
+ "If set to 0 the mod wont overwrite vanilla's default (which so happens to also be 0)")
.build();
@@ -29,13 +29,14 @@ import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.RenderDataPointUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.dataObjects.render.columnViews.ColumnArrayView;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import com.seibel.distanthorizons.coreapi.util.MathUtil;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import org.jetbrains.annotations.NotNull;
public class ColumnBox
{
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
/**
* if the skylight has this value that means
@@ -122,7 +123,7 @@ public class ColumnBox
&& !isTopTransparent;
if (!skipTop)
{
builder.addQuadUp(minX, maxY, minZ, width, width, ColorUtil.applyShade(color, MC.getShade(EDhDirection.UP)), irisBlockMaterialId, skyLightTop, blockLight);
builder.addQuadUp(minX, maxY, minZ, width, width, ColorUtil.applyShade(color, MC_RENDER.getShade(EDhDirection.UP)), irisBlockMaterialId, skyLightTop, blockLight);
}
}
@@ -133,7 +134,7 @@ public class ColumnBox
&& !isBottomTransparent;
if (!skipBottom)
{
builder.addQuadDown(minX, minY, minZ, width, width, ColorUtil.applyShade(color, MC.getShade(EDhDirection.DOWN)), irisBlockMaterialId, skyLightBot, blockLight);
builder.addQuadDown(minX, minY, minZ, width, width, ColorUtil.applyShade(color, MC_RENDER.getShade(EDhDirection.DOWN)), irisBlockMaterialId, skyLightBot, blockLight);
}
}
@@ -263,7 +264,7 @@ public class ColumnBox
// no adjacent data //
//==================//
color = ColorUtil.applyShade(color, MC.getShade(direction));
color = ColorUtil.applyShade(color, MC_RENDER.getShade(direction));
if (adjColumnView.size == 0
|| RenderDataPointUtil.hasZeroHeight(adjColumnView.get(0)))
@@ -32,6 +32,7 @@ import com.seibel.distanthorizons.core.logging.DhLogger;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.util.ColorUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import com.seibel.distanthorizons.coreapi.util.MathUtil;
import org.lwjgl.system.MemoryUtil;
@@ -44,7 +45,7 @@ import org.lwjgl.system.MemoryUtil;
public class LodQuadBuilder
{
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
@SuppressWarnings("unchecked")
private final ArrayList<BufferQuad>[] opaqueQuads = (ArrayList<BufferQuad>[]) new ArrayList[6];
@@ -379,7 +380,7 @@ public class LodQuadBuilder
// for horizontal and bottom faces of grass blocks, use the dirt color to
// prevent green cliff walls
color = this.clientLevelWrapper.getDirtBlockColor();
color = ColorUtil.applyShade(color, MC.getShade(quad.direction));
color = ColorUtil.applyShade(color, MC_RENDER.getShade(quad.direction));
}
}
}
@@ -56,10 +56,8 @@ public class PregenManager
return pregenState;
}
MC_SERVER.setPreventAutoPause(true);
pregenState.whenComplete((result, throwable) -> {
this.pregenFuture.set(null);
MC_SERVER.setPreventAutoPause(false);
});
pregenState.fillPendingQueue();
@@ -276,7 +276,7 @@ public class DhLogger implements IConfigListener
if (mc_client != null)
{
mc_client.logToChat(level, msgStr);
this.logToChat(level, msgStr);
messageLogged = true;
}
}
@@ -296,6 +296,41 @@ public class DhLogger implements IConfigListener
}
private static boolean loggingLevelIsLessSpecificThan(Level thisLoggingLevel, Level requestedLogLevel)
{ return thisLoggingLevel.intLevel() >= requestedLogLevel.intLevel(); }
/** Sends the given message to chat with a formatted prefix and color based on the log level. */
private void logToChat(Level logLevel, String message)
{
String prefix = "[" + ModInfo.READABLE_NAME + "] ";
if (logLevel == Level.ERROR)
{
prefix += "\u00A74";
}
else if (logLevel == Level.WARN)
{
prefix += "\u00A76";
}
else if (logLevel == Level.INFO)
{
prefix += "\u00A7f";
}
else if (logLevel == Level.DEBUG)
{
prefix += "\u00A77";
}
else if (logLevel == Level.TRACE)
{
prefix += "\u00A78";
}
else
{
prefix += "\u00A7f";
}
prefix += "\u00A7l\u00A7u";
prefix += logLevel.name();
prefix += ":\u00A7r ";
mc_client.sendChatMessage(prefix + message);
}
@@ -42,6 +42,7 @@ import com.seibel.distanthorizons.core.render.renderer.shaders.*;
import com.seibel.distanthorizons.core.util.math.Mat4f;
import com.seibel.distanthorizons.core.util.math.Vec3d;
import com.seibel.distanthorizons.core.util.objects.SortedArraySet;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
@@ -69,6 +70,7 @@ public class LodRenderer
.maxCountPerSecond(4)
.build();
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
private static final IMinecraftGLWrapper GLMC = SingletonInjector.INSTANCE.get(IMinecraftGLWrapper.class);
private static final IIrisAccessor IRIS_ACCESSOR = ModAccessorInjector.INSTANCE.get(IIrisAccessor.class);
@@ -174,6 +176,13 @@ public class LodRenderer
return;
}
// only do this once, that way they can still be reverted if desired
if (Config.Client.Advanced.Graphics.overrideVanillaGraphicsSettings.get())
{
MC.disableVanillaClouds();
MC.disableVanillaChunkFadeIn();
}
this.renderObjectsCreated = true;
}
@@ -164,10 +164,11 @@ public class FogShader extends AbstractShaderRenderer
// Fog uniforms
this.shader.setUniform(this.uFogColor, MC_RENDER.isFogStateSpecial() ? this.getSpecialFogColor(partialTicks) : this.getFogColor(partialTicks));
this.shader.setUniform(this.uFogColor, this.getFogColor(partialTicks));
this.shader.setUniform(this.uFogScale, 1.f / lodDrawDistance);
this.shader.setUniform(this.uFogVerticalScale, 1.f / MC.getWrappedClientLevel().getMaxHeight());
this.shader.setUniform(this.uFullFogMode, MC_RENDER.isFogStateSpecial() ? 1 : 0);
// only used for debugging
this.shader.setUniform(this.uFullFogMode, 0); // 1 = render everything with fog color // 7 = use debug rendering
// fog config
@@ -229,7 +230,6 @@ public class FogShader extends AbstractShaderRenderer
return fogColor;
}
private Color getSpecialFogColor(float partialTicks) { return MC_RENDER.getSpecialFogColor(partialTicks); }
public void setProjectionMatrix(Mat4f projectionMatrix)
{
@@ -32,33 +32,11 @@ import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindab
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import org.apache.logging.log4j.Level;
/**
* Contains everything related to the Minecraft object.
*
* @author James Seibel
* @version 2022-8-20
*/
public interface IMinecraftClientWrapper extends IBindable
{
//================//
// helper methods //
//================//
/**
* This should be called at the beginning of every frame to
* clear any Minecraft data that becomes out of date after a frame. <br> <br>
* <p>
* LightMaps and other time sensitive objects fall in this category. <br> <br>
* <p>
* This doesn't affect OpenGL objects in any way.
*/
void clearFrameObjectCache();
//=================//
// method wrappers //
//=================//
float getShade(EDhDirection lodDirection);
//======================//
// multiplayer handling //
//======================//
boolean hasSinglePlayerServer();
boolean clientConnectedToDedicatedServer();
@@ -69,24 +47,26 @@ public interface IMinecraftClientWrapper extends IBindable
String getCurrentServerIp();
String getCurrentServerVersion();
//=============//
// Simple gets //
//=============//
//=================//
// player handling //
//=================//
boolean playerExists();
UUID getPlayerUUID();
String getUsername();
// TODO returning null would be easier to understand but might make things harder to parse in some cases
/** @return (0,0,0) if no player is loaded */
DhBlockPos getPlayerBlockPos();
// TODO returning null would be easier to understand but might make things harder to parse in some cases
/** @return (0,0) if no player is loaded */
DhChunkPos getPlayerChunkPos();
//================//
// level handling //
//================//
/**
* Returns the level the client is currently in. <br>
* Returns null if the client isn't in a level.
@@ -98,49 +78,37 @@ public interface IMinecraftClientWrapper extends IBindable
*/
IClientLevelWrapper getWrappedClientLevel(boolean bypassLevelKeyManager);
IProfilerWrapper getProfiler();
/** Returns all worlds available to the server */
ArrayList<ILevelWrapper> getAllServerWorlds();
//===========//
// messaging //
//===========//
void sendChatMessage(String string);
/** Will default to sending a chat message if not supported by the current MC version */
/**
* Will default to sending a chat message if not supported by
* the current MC version (1.19.2 and older).
*/
void sendOverlayMessage(String string);
/** Sends the given message to chat with a formatted prefix and color based on the log level. */
default void logToChat(Level logLevel, String message)
{
String prefix = "[" + ModInfo.READABLE_NAME + "] ";
if (logLevel == Level.ERROR)
{
prefix += "\u00A74";
}
else if (logLevel == Level.WARN)
{
prefix += "\u00A76";
}
else if (logLevel == Level.INFO)
{
prefix += "\u00A7f";
}
else if (logLevel == Level.DEBUG)
{
prefix += "\u00A77";
}
else if (logLevel == Level.TRACE)
{
prefix += "\u00A78";
}
else
{
prefix += "\u00A7f";
}
prefix += "\u00A7l\u00A7u";
prefix += logLevel.name();
prefix += ":\u00A7r ";
this.sendChatMessage(prefix + message);
}
//==========================//
// vanilla option overrides //
//==========================//
void disableVanillaClouds();
void disableVanillaChunkFadeIn();
//======//
// misc //
//======//
IProfilerWrapper getProfiler();
/**
* Crashes Minecraft, displaying the given errorMessage <br> <br>
@@ -150,15 +118,17 @@ public interface IMinecraftClientWrapper extends IBindable
* Error: <strong>ExceptionClass: exceptionErrorMessage</strong> <br>
* Exit Code: -1 <br>
*/
void crashMinecraft(String errorMessage, Throwable exception); //FIXME: Move to IMinecraftSharedWrapper
void crashMinecraft(String errorMessage, Throwable exception);
//=============//
// mod support //
//=============//
/** used for Optifine */
Object getOptionsObject();
/**
* Executes the given task on Minecraft's render thread.
* @deprecated use {@link GLProxy#runningOnRenderThread()} instead
*/
@Deprecated
void executeOnRenderThread(Runnable runnable);
}
@@ -21,6 +21,7 @@ package com.seibel.distanthorizons.core.wrapperInterfaces.minecraft;
import java.awt.Color;
import com.seibel.distanthorizons.core.enums.EDhDirection;
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.ILightMapWrapper;
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
import com.seibel.distanthorizons.core.util.math.Vec3d;
@@ -46,8 +47,6 @@ public interface IMinecraftRenderWrapper extends IBindable
Color getFogColor(float partialTicks);
default Color getSpecialFogColor(float partialTicks) { return getFogColor(partialTicks); }
/** Unless you really need to know if the player is blind, use {@link IMinecraftRenderWrapper#isFogStateSpecial()} instead */
boolean isFogStateSpecial();
@@ -58,9 +57,6 @@ public interface IMinecraftRenderWrapper extends IBindable
/** Measured in chunks */
int getRenderDistance();
int getScreenWidth();
int getScreenHeight();
boolean mcRendersToFrameBuffer();
boolean runningLegacyOpenGL();
@@ -82,5 +78,8 @@ public interface IMinecraftRenderWrapper extends IBindable
@Nullable
ILightMapWrapper getLightmapWrapper(@NotNull ILevelWrapper level);
float getShade(EDhDirection lodDirection);
}
@@ -23,7 +23,6 @@ import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindab
import java.io.File;
//TODO: Maybe have IMCClientWrapper & IMCDedicatedWrapper extend this interface???
public interface IMinecraftSharedWrapper extends IBindable
{
boolean isDedicatedServer();
@@ -32,6 +31,6 @@ public interface IMinecraftSharedWrapper extends IBindable
int getPlayerCount();
void setPreventAutoPause(boolean preventAutoPause);
}
@@ -79,58 +79,6 @@ public abstract class AbstractOptifineAccessor implements IOptifineAccessor
// interface methods //
//===================//
//@Override
@Deprecated
public EDhApiFogDrawMode getFogDrawMode()
{
if (this.ofFogField == null)
{
// either optifine isn't installed,
// the variable name was changed, or
// the setup method wasn't called yet.
return EDhApiFogDrawMode.FOG_ENABLED;
}
int returnNum = 0;
try
{
returnNum = (int) this.ofFogField.get(this.mcOptionsObject);
}
catch (IllegalArgumentException | IllegalAccessException e)
{
LOGGER.error("Unable to get project fog draw mode from Optifine, error: ["+e.getMessage()+"].", e);
}
switch (returnNum)
{
default:
case 0: // optifine's "default" option,
// it should never be used, so default to fog Enabled
// normal options
case 1: // fast
case 2: // fancy
return EDhApiFogDrawMode.FOG_ENABLED;
case 3: // off
return EDhApiFogDrawMode.FOG_DISABLED;
}
}
@Override
public double getRenderResolutionMultiplier()
{
/*
* TODO remove comment when done, this is just here as reference
* Returns the percentage multiplier of the screen's current resolution. <br>
* 1.0 = 100% <br>
* 1.5 = 150% <br>
*/
// TODO
return 1.0;
}
public boolean getIsShaderActive()
{
@@ -27,11 +27,4 @@ import java.util.HashSet;
public interface IOptifineAccessor extends IModAccessor
{
/**
* Returns the percentage multiplier of the screen's current resolution. <br>
* 1.0 = 100% <br>
* 1.5 = 150% <br>
*/
double getRenderResolutionMultiplier();
}
@@ -385,6 +385,11 @@
"distanthorizons.config.client.advanced.graphics.culling.ignoredRenderCaveBlockCsv.@tooltip":
"A comma separated list of block resource locations that shouldn't be rendered \nif they are in a 0 sky light underground area. \nNote: air is always included in this list.",
"distanthorizons.config.client.advanced.graphics.overrideVanillaGraphicsSettings":
"Override Vanilla Settings",
"distanthorizons.config.client.advanced.graphics.overrideVanillaGraphicsSettings.@tooltip":
"If true some vanilla graphics settings will be automatically changed \nduring DH setup to provide a better experience. \n\nIE disabling vanilla clouds (which render on top of DH LODs), \nand chunk fading (DH already fades MC chunks).",
"distanthorizons.config.client.advanced.graphics.experimental":