auto disable clouds/chunk fading and fix sodium crash

This commit is contained in:
James Seibel
2025-12-10 18:51:13 -06:00
parent e1c3da59db
commit 01e78f249f
7 changed files with 165 additions and 219 deletions
@@ -20,18 +20,8 @@
package com.seibel.distanthorizons.common.wrappers.minecraft;
import java.io.File;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Objects;
import java.util.UUID;
import com.mojang.blaze3d.platform.NativeImage;
import com.seibel.distanthorizons.api.enums.config.EDhApiLodShading;
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.enums.EDhDirection;
import com.seibel.distanthorizons.core.file.structure.ClientOnlySaveStructure;
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
@@ -40,25 +30,25 @@ import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import com.seibel.distanthorizons.core.logging.DhLogger;
import net.minecraft.CrashReport;
import net.minecraft.client.CloudStatus;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.ChunkPos;
import org.jetbrains.annotations.Nullable;
#if MC_VER < MC_1_19_2
import net.minecraft.network.chat.TextComponent;
#endif
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.ChunkPos;
import com.seibel.distanthorizons.core.logging.DhLogger;
import org.jetbrains.annotations.Nullable;
#if MC_VER < MC_1_21_3
#else
@@ -78,82 +68,13 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
public static final MinecraftClientWrapper INSTANCE = new MinecraftClientWrapper();
/**
* The lightmap for the current:
* Time, dimension, brightness setting, etc.
*/
private NativeImage lightMap = null;
private ProfilerWrapper profilerWrapper;
private MinecraftClientWrapper()
{
}
//================//
// 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.
*/
@Override
public void clearFrameObjectCache() { this.lightMap = null; }
//=================//
// method wrappers //
//=================//
@Override
public float getShade(EDhDirection lodDirection)
{
EDhApiLodShading lodShading = Config.Client.Advanced.Graphics.Quality.lodShading.get();
switch (lodShading)
{
default:
case AUTO:
if (MINECRAFT.level != null)
{
Direction mcDir = McObjectConverter.Convert(lodDirection);
return MINECRAFT.level.getShade(mcDir, true);
}
else
{
return 0.0f;
}
case ENABLED:
switch (lodDirection)
{
case DOWN:
return 0.5F;
default:
case UP:
return 1.0F;
case NORTH:
case SOUTH:
return 0.8F;
case WEST:
case EAST:
return 0.6F;
}
case DISABLED:
return 1.0F;
}
}
//======================//
// multiplayer handling //
//======================//
@Override
public boolean hasSinglePlayerServer() { return MINECRAFT.hasSingleplayerServer(); }
@@ -183,7 +104,6 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
return (server != null) ? server.name : "NULL";
}
}
@Override
public String getCurrentServerIp()
{
@@ -197,7 +117,6 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
return (server != null) ? server.ip : "NA";
}
}
@Override
public String getCurrentServerVersion()
{
@@ -205,21 +124,17 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
return (server != null) ? server.version.getString() : "UNKOWN";
}
//=============//
// Simple gets //
//=============//
//=================//
// player handling //
//=================//
public LocalPlayer getPlayer() { return MINECRAFT.player; }
@Override
public boolean playerExists() { return MINECRAFT.player != null; }
@Override
public UUID getPlayerUUID() { return this.getPlayer().getUUID(); }
@Override
public String getUsername() { return MINECRAFT.getUser().getName(); }
@Override
public DhBlockPos getPlayerBlockPos()
{
@@ -250,6 +165,12 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
return new DhChunkPos(playerPos.x, playerPos.z);
}
//================//
// level handling //
//================//
@Nullable
@Override
public IClientLevelWrapper getWrappedClientLevel() { return this.getWrappedClientLevel(false); }
@@ -267,44 +188,11 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
return ClientLevelWrapper.getWrapper(level, bypassLevelKeyManager);
}
@Override
public IProfilerWrapper getProfiler()
{
ProfilerFiller profiler;
#if MC_VER < MC_1_21_3
profiler = MINECRAFT.getProfiler();
#else
profiler = Profiler.get();
#endif
if (this.profilerWrapper == null)
{
this.profilerWrapper = new ProfilerWrapper(profiler);
}
else if (profiler != this.profilerWrapper.profiler)
{
this.profilerWrapper.profiler = profiler;
}
return this.profilerWrapper;
}
/** Returns all worlds available to the server */
@Override
public ArrayList<ILevelWrapper> getAllServerWorlds()
{
ArrayList<ILevelWrapper> worlds = new ArrayList<ILevelWrapper>();
Iterable<ServerLevel> serverWorlds = MINECRAFT.getSingleplayerServer().getAllLevels();
for (ServerLevel world : serverWorlds)
{
worlds.add(ServerLevelWrapper.getWrapper(world));
}
return worlds;
}
//===========//
// messaging //
//===========//
@Override
public void sendChatMessage(String string)
@@ -350,14 +238,58 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
#endif
}
/**
* Crashes Minecraft, displaying the given errorMessage <br> <br>
* In the following format: <br>
*
* The game crashed whilst <strong>errorMessage</strong> <br>
* Error: <strong>ExceptionClass: exceptionErrorMessage</strong> <br>
* Exit Code: -1 <br>
*/
//==========================//
// vanilla option overrides //
//==========================//
public void disableVanillaClouds()
{
#if MC_VER <= MC_1_18_2
MINECRAFT.options.renderClouds = CloudStatus.OFF;
#else
MINECRAFT.options.cloudStatus().set(CloudStatus.OFF);
#endif
}
public void disableVanillaChunkFadeIn()
{
#if MC_VER <= MC_1_21_10
// chunk fade in was added MC 1.21.11
#else
MINECRAFT.options.chunkSectionFadeInTime().set(0.0);
#endif
}
//======//
// misc //
//======//
@Override
public IProfilerWrapper getProfiler()
{
ProfilerFiller profiler;
#if MC_VER < MC_1_21_3
profiler = MINECRAFT.getProfiler();
#else
profiler = Profiler.get();
#endif
if (this.profilerWrapper == null)
{
this.profilerWrapper = new ProfilerWrapper(profiler);
}
else if (profiler != this.profilerWrapper.profiler)
{
this.profilerWrapper.profiler = profiler;
}
return this.profilerWrapper;
}
@Override
public void crashMinecraft(String errorMessage, Throwable exception)
{
@@ -366,22 +298,31 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
#if MC_VER < MC_1_20_4
Minecraft.crash(report);
#else
Minecraft.getInstance().delayCrash(report);
MINECRAFT.delayCrash(report);
#endif
}
//=============//
// mod support //
//=============//
@Override
public Object getOptionsObject() { return MINECRAFT.options; }
//========//
// shared //
//========//
@Override
public boolean isDedicatedServer() { return false; }
@Override
public File getInstallationDirectory() { return MINECRAFT.gameDirectory; }
@Override
public void executeOnRenderThread(Runnable runnable) { MINECRAFT.execute(runnable); }
@Override
public int getPlayerCount()
{
@@ -396,10 +337,6 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
}
}
@Override
public void setPreventAutoPause(boolean preventAutoPause)
{
throw new UnsupportedOperationException();
}
}
@@ -25,9 +25,13 @@ import java.util.concurrent.ConcurrentHashMap;
import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.platform.NativeImage;
import com.seibel.distanthorizons.api.enums.config.EDhApiLodShading;
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
import com.seibel.distanthorizons.common.wrappers.misc.LightMapWrapper;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.enums.EDhDirection;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.util.ColorUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.ILightMapWrapper;
@@ -52,13 +56,12 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.world.IDimensionTypeWra
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.core.util.math.Vec3d;
import com.seibel.distanthorizons.core.util.math.Vec3f;
import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IOptifineAccessor;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.phys.Vec3;
@@ -96,8 +99,6 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
private static final Minecraft MC = Minecraft.getInstance();
private static final IOptifineAccessor OPTIFINE_ACCESSOR = ModAccessorInjector.INSTANCE.get(IOptifineAccessor.class);
/**
* In the case of immersive portals multiple levels may be active at once, causing conflicting lightmaps. <br>
* Requiring the use of multiple {@link LightMapWrapper}.
@@ -136,8 +137,11 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
#endif
}
/**
* Unless you really need to know if the player is blind,
* use {@link MinecraftRenderWrapper#isFogStateSpecial()} or {@link IMinecraftRenderWrapper#isFogStateSpecial()} instead
*/
@Override
/** Unless you really need to know if the player is blind, use {@link MinecraftRenderWrapper#isFogStateSpecial()}/{@link IMinecraftRenderWrapper#isFogStateSpecial()} instead */
public boolean playerHasBlindingEffect()
{
if (MC.player == null)
@@ -251,7 +255,6 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
);
#endif
}
// getSpecialFogColor() is the same as getFogColor()
@Override
public Color getSkyColor()
@@ -290,10 +293,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
}
@Override
public double getFov(float partialTicks)
{
return MC.gameRenderer.getFov(MC.gameRenderer.getMainCamera(), partialTicks, true);
}
public double getFov(float partialTicks) { return MC.gameRenderer.getFov(MC.gameRenderer.getMainCamera(), partialTicks, true); }
/** Measured in chunks */
@Override
@@ -307,41 +307,6 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
#endif
}
@Override
public int getScreenWidth()
{
// alternate ways of getting the window's resolution,
// using one of these methods may fix the optifine render resolution bug
// TODO: test these once we can run with Optifine again
// int[] heightArray = new int[1];
// int[] widthArray = new int[1];
//
// long window = GLProxy.getInstance().minecraftGlContext;
// GLFW.glfwGetWindowSize(window, widthArray, heightArray); // option 1
// GLFW.glfwGetFramebufferSize(window, widthArray, heightArray); // option 2
int width = MC.getWindow().getWidth();
if (OPTIFINE_ACCESSOR != null)
{
// TODO remove comment after testing:
// this should fix the issue where different optifine render resolutions screw up the LOD rendering
width *= OPTIFINE_ACCESSOR.getRenderResolutionMultiplier();
}
return width;
}
@Override
public int getScreenHeight()
{
int height = MC.getWindow().getHeight();
if (OPTIFINE_ACCESSOR != null)
{
height *= OPTIFINE_ACCESSOR.getRenderResolutionMultiplier();
}
return height;
}
protected RenderTarget getRenderTarget() { return MC.getMainRenderTarget(); }
@Override
@@ -510,4 +475,45 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
wrapper.setLightmapId(tetxureId);
}
@Override
public float getShade(EDhDirection lodDirection)
{
EDhApiLodShading lodShading = Config.Client.Advanced.Graphics.Quality.lodShading.get();
switch (lodShading)
{
default:
case AUTO:
if (MC.level != null)
{
Direction mcDir = McObjectConverter.Convert(lodDirection);
return MC.level.getShade(mcDir, true);
}
else
{
return 0.0f;
}
case ENABLED:
switch (lodDirection)
{
case DOWN:
return 0.5F;
default:
case UP:
return 1.0F;
case NORTH:
case SOUTH:
return 0.8F;
case WEST:
case EAST:
return 0.6F;
}
case DISABLED:
return 1.0F;
}
}
}
@@ -2,16 +2,18 @@ package com.seibel.distanthorizons.common.wrappers.minecraft;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
import net.minecraft.server.dedicated.DedicatedServer;
import org.jetbrains.annotations.Nullable;
import java.io.File;
//@Environment(EnvType.SERVER)
public class MinecraftServerWrapper implements IMinecraftSharedWrapper
{
public static final MinecraftServerWrapper INSTANCE = new MinecraftServerWrapper();
/** set during server startup */
@Nullable
public DedicatedServer dedicatedServer = null;
public boolean preventAutoPause = false;
//=============//
@@ -34,7 +36,7 @@ public class MinecraftServerWrapper implements IMinecraftSharedWrapper
{
if (this.dedicatedServer == null)
{
throw new IllegalStateException("Trying to get Installation Direction before Dedicated server completed initialization!");
throw new IllegalStateException("Trying to get Installation Direction before dedicated server completed initialization!");
}
#if MC_VER < MC_1_21_1
@@ -45,15 +47,16 @@ public class MinecraftServerWrapper implements IMinecraftSharedWrapper
}
@Override
public int getPlayerCount()
public int getPlayerCount()
{
return this.dedicatedServer.getPlayerCount();
if (this.dedicatedServer == null)
{
throw new IllegalStateException("Trying to get player count before dedicated server completed initialization!");
}
return this.dedicatedServer.getPlayerCount();
}
@Override
public void setPreventAutoPause(boolean preventAutoPause)
{
this.preventAutoPause = preventAutoPause;
}
}
@@ -28,9 +28,6 @@ public class OptifineAccessor extends AbstractOptifineAccessor
{
@Override
public String getModName()
{
return "Optifine-Fabric-1.18.X";
}
public String getModName() { return "Optifine-Fabric"; }
}
@@ -26,6 +26,7 @@ import java.lang.invoke.MethodType;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
import net.minecraft.client.Minecraft;
#if MC_VER < MC_1_20_1
@@ -50,9 +51,11 @@ public class SodiumAccessor implements ISodiumAccessor
*/
public static final boolean isSodiumV5OrLess;
#if MC_VER >= MC_1_20_1
#if MC_VER <= MC_1_19_4
#elif MC_VER <= MC_1_21_10
private static MethodHandle setFogOcclusionMethod;
private static Object sodiumPerformanceOptions;
#else
#endif
static {
@@ -78,7 +81,8 @@ public class SodiumAccessor implements ISodiumAccessor
@Override
public void setFogOcclusion(boolean occlusionEnabled)
{
#if MC_VER >= MC_1_20_1
#if MC_VER <= MC_1_19_4
#elif MC_VER <= MC_1_21_10
try
{
if (sodiumPerformanceOptions == null)
@@ -122,6 +126,8 @@ public class SodiumAccessor implements ISodiumAccessor
{
throw new RuntimeException(e);
}
#else
// in newer versions of Sodium this doesn't appear to be an issue so it can probably just be ignored
#endif
}
@@ -28,9 +28,6 @@ public class OptifineAccessor extends AbstractOptifineAccessor
{
@Override
public String getModName()
{
return "Optifine-Forge-1.18.X";
}
public String getModName() { return "Optifine-Forge"; }
}