From 2884094dee331d4f553c570d04961acf0e8f38d7 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Thu, 14 May 2026 07:49:32 -0500 Subject: [PATCH] refactoring and cleanup --- .../common/wrappers/McObjectConverter.java | 4 +- .../gui/classicConfig/DhConfigScreen.java | 1 + .../minecraft/MinecraftClientWrapper.java | 13 ++++- .../minecraft/MinecraftRenderWrapper.java | 29 +++++----- .../wrappers/minecraft/ProfilerWrapper.java | 4 ++ .../wrappers/misc/ServerPlayerWrapper.java | 1 + .../wrappers/world/ClientLevelWrapper.java | 56 +++++++++++++++---- .../BatchGenerationEnvironment.java | 4 ++ 8 files changed, 82 insertions(+), 30 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/McObjectConverter.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/McObjectConverter.java index b6e050174..aa08f77db 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/McObjectConverter.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/McObjectConverter.java @@ -63,7 +63,7 @@ public class McObjectConverter FloatBuffer buffer = FloatBuffer.allocate(16); storeMatrix(mcMatrix, buffer); Mat4f matrix = new Mat4f(buffer); - #if MC_VER < MC_1_19_4 && MC_VER > MC_1_12_2 + #if MC_VER > MC_1_12_2 && MC_VER < MC_1_19_4 matrix.transpose(); // In 1.19.3 and later, we no longer need to transpose it #endif return matrix; @@ -109,7 +109,9 @@ public class McObjectConverter static { EDhDirection[] lodDirs = EDhDirection.values(); + directions = new #if MC_VER <= MC_1_12_2 EnumFacing #else Direction #endif[lodDirs.length]; + lodDirections = new EDhDirection[lodDirs.length]; for (EDhDirection lodDir : lodDirs) { diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/classicConfig/DhConfigScreen.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/classicConfig/DhConfigScreen.java index 7c2bc6867..073b6b242 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/classicConfig/DhConfigScreen.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/classicConfig/DhConfigScreen.java @@ -170,6 +170,7 @@ class DhConfigScreen extends DhScreen #else super.init(); #endif + if (!this.reload) { ConfigHandler.INSTANCE.configFileHandler.loadFromFile(); diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftClientWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftClientWrapper.java index ddffdd7a6..f1ada541e 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftClientWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftClientWrapper.java @@ -143,8 +143,13 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra } else { - ServerData server = MINECRAFT.#if MC_VER <= MC_1_12_2 getCurrentServerData() #else getCurrentServer() #endif; - return (server != null) ? server.#if MC_VER <= MC_1_12_2 serverName #else name #endif : "NULL"; + #if MC_VER <= MC_1_12_2 + ServerData server = MINECRAFT.getCurrentServerData(); + return (server != null) ? server.serverName : "NULL"; + #else + ServerData server = MINECRAFT.getCurrentServer(); + return (server != null) ? server.name : "NULL"; + #endif } } @Override @@ -382,11 +387,13 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra public void disableVanillaChunkFadeIn() { - LOGGER.info("Disabling vanilla chunk fade in... This is done to prevent vanilla chunks from flashing on the Distant Horizons boarder when moving (which is distracting)."); + String message = "Disabling vanilla chunk fade in... This is done to prevent vanilla chunks from flashing on the Distant Horizons boarder when moving (which is distracting)."; #if MC_VER <= MC_1_21_10 // chunk fade in was added MC 1.21.11 #else + LOGGER.info(message); + MINECRAFT.options.chunkSectionFadeInTime().set(0.0); #endif } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java index fb3c295b9..b3e34ef94 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java @@ -173,26 +173,27 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper { return false; } + #if MC_VER <= MC_1_12_2 - else if (MC.player.getActivePotionMap() == null) - #else - else if (MC.player.getActiveEffectsMap() == null) - #endif + if (MC.player.getActivePotionMap() == null) { return false; } - else + + return MC.player.getActivePotionEffect(MobEffects.BLINDNESS) != null; + #else + if (MC.player.getActiveEffectsMap() == null) { - #if MC_VER <= MC_1_12_2 - return MC.player.getActivePotionEffect(MobEffects.BLINDNESS) != null; - #else - return MC.player.getActiveEffectsMap().get(MobEffects.BLINDNESS) != null - #if MC_VER >= MC_1_19_2 - || MC.player.getActiveEffectsMap().get(MobEffects.DARKNESS) != null // Deep dark effect - #endif - ; - #endif + return false; } + + return MC.player.getActiveEffectsMap().get(MobEffects.BLINDNESS) != null + #if MC_VER >= MC_1_19_2 + || MC.player.getActiveEffectsMap().get(MobEffects.DARKNESS) != null // Deep dark effect + #endif + ; + #endif + } @Override diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/ProfilerWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/ProfilerWrapper.java index 4d29a7f76..89c4e4b4b 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/ProfilerWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/ProfilerWrapper.java @@ -35,6 +35,8 @@ public class ProfilerWrapper implements IProfilerWrapper public ProfilerFiller profiler; #endif + + #if MC_VER <= MC_1_12_2 public ProfilerWrapper(Profiler newProfiler) #else @@ -42,6 +44,8 @@ public class ProfilerWrapper implements IProfilerWrapper #endif { this.profiler = newProfiler; } + + @Override public IProfileBlock push(String newSection) { diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/ServerPlayerWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/ServerPlayerWrapper.java index dd9665aaf..91b052577 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/ServerPlayerWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/ServerPlayerWrapper.java @@ -107,6 +107,7 @@ public class ServerPlayerWrapper implements IServerPlayerWrapper #else ServerLevel level = ((IMixinServerPlayer) this.getServerPlayer()).distantHorizons$getDimensionChangeDestination(); #endif + if (level == null) { #if MC_VER <= MC_1_12_2 diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/world/ClientLevelWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/world/ClientLevelWrapper.java index cdfaa5cc8..7da7629a5 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/world/ClientLevelWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/world/ClientLevelWrapper.java @@ -6,6 +6,7 @@ import com.seibel.distanthorizons.common.wrappers.block.BiomeWrapper; import com.seibel.distanthorizons.common.wrappers.block.BlockStateWrapper; import com.seibel.distanthorizons.common.wrappers.block.ClientBlockStateColorCache; import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; +import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftClientWrapper; import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2; import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; import com.seibel.distanthorizons.core.level.*; @@ -76,17 +77,31 @@ public class ClientLevelWrapper implements IClientLevelWrapper * where, upon world closure, some levels aren't shutdown/removed properly * and/or for servers were the level object isn't consistent */ - private static final Map<#if MC_VER <= MC_1_12_2 WorldClient #else ClientLevel #endif, WeakReference> LEVEL_WRAPPER_REF_BY_CLIENT_LEVEL = Collections.synchronizedMap(new WeakHashMap<>()); + private static final Map< + #if MC_VER <= MC_1_12_2 WorldClient #else ClientLevel #endif, + WeakReference> LEVEL_WRAPPER_REF_BY_CLIENT_LEVEL = Collections.synchronizedMap(new WeakHashMap<>()); private static final IKeyedClientLevelManager KEYED_CLIENT_LEVEL_MANAGER = SingletonInjector.INSTANCE.get(IKeyedClientLevelManager.class); - private static final Minecraft MINECRAFT = Minecraft.#if MC_VER <= MC_1_12_2 getMinecraft() #else getInstance() #endif; + #if MC_VER <= MC_1_12_2 + private static final Minecraft MINECRAFT = Minecraft.getMinecraft(); + #else + private static final Minecraft MINECRAFT = Minecraft.getInstance(); + #endif + + #if MC_VER <= MC_1_12_2 + private final WorldClient level; + private final ConcurrentHashMap blockColorCacheByBlockState = new ConcurrentHashMap<>(); + #else + private final ClientLevel level; + private final ConcurrentHashMap blockColorCacheByBlockState = new ConcurrentHashMap<>(); + #endif - private final #if MC_VER <= MC_1_12_2 WorldClient #else ClientLevel #endif level; - private final ConcurrentHashMap<#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif, ClientBlockStateColorCache> blockColorCacheByBlockState = new ConcurrentHashMap<>(); /** cached method reference to reduce GC overhead */ - private final Function<#if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif, ClientBlockStateColorCache> createCachedBlockColorCacheFunc - = (blockState) -> new ClientBlockStateColorCache(blockState, this); + private final Function< + #if MC_VER <= MC_1_12_2 IBlockState #else BlockState #endif, + ClientBlockStateColorCache> createCachedBlockColorCacheFunc + = (blockState) -> new ClientBlockStateColorCache(blockState, this); private boolean cloudColorFailLogged = false; @@ -117,7 +132,9 @@ public class ClientLevelWrapper implements IClientLevelWrapper * IE rendering. */ @Nullable - public static IClientLevelWrapper getWrapperIfDifferent(@Nullable IClientLevelWrapper levelWrapper, @NotNull #if MC_VER <= MC_1_12_2 WorldClient #else ClientLevel #endif level) + public static IClientLevelWrapper getWrapperIfDifferent( + @Nullable IClientLevelWrapper levelWrapper, + @NotNull #if MC_VER <= MC_1_12_2 WorldClient #else ClientLevel #endif level) { if (KEYED_CLIENT_LEVEL_MANAGER.isEnabled() && KEYED_CLIENT_LEVEL_MANAGER.getServerKeyedLevel() != levelWrapper) { @@ -135,10 +152,13 @@ public class ClientLevelWrapper implements IClientLevelWrapper } @Nullable - public static IClientLevelWrapper getWrapper(@NotNull #if MC_VER <= MC_1_12_2 WorldClient #else ClientLevel #endif level) { return getWrapper(level, false); } + public static IClientLevelWrapper getWrapper( + @NotNull #if MC_VER <= MC_1_12_2 WorldClient #else ClientLevel #endif level) + { return getWrapper(level, false); } @Nullable - public static IClientLevelWrapper getWrapper(@Nullable #if MC_VER <= MC_1_12_2 WorldClient #else ClientLevel #endif level, boolean bypassLevelKeyManager) + public static IClientLevelWrapper getWrapper( + @Nullable #if MC_VER <= MC_1_12_2 WorldClient #else ClientLevel #endif level, boolean bypassLevelKeyManager) { if (!bypassLevelKeyManager) { @@ -197,7 +217,7 @@ public class ClientLevelWrapper implements IClientLevelWrapper #if MC_VER <= MC_1_12_2 WorldServer[] serverLevels = MINECRAFT.getIntegratedServer().worlds; #else - Iterable<#if MC_VER <= MC_1_12_2 WorldServer #else ServerLevel #endif> serverLevels = MINECRAFT.getSingleplayerServer().getAllLevels(); + Iterable serverLevels = MINECRAFT.getSingleplayerServer().getAllLevels(); #endif // attempt to find the server level with the same dimension type @@ -457,10 +477,20 @@ public class ClientLevelWrapper implements IClientLevelWrapper public Color getCloudColor(float tickDelta) { #if MC_VER < MC_1_21_3 - #if MC_VER <= MC_1_12_2 Vec3d #else Vec3 #endif colorVec3 = null; + + #if MC_VER <= MC_1_12_2 + Vec3d colorVec3 = null; + #else + Vec3 colorVec3 = null; + #endif try { - colorVec3 = this.level.#if MC_VER <= MC_1_12_2 getCloudColour #else getCloudColor #endif (tickDelta); + #if MC_VER <= MC_1_12_2 + colorVec3 = this.level.getCloudColour(tickDelta); + #else + colorVec3 = this.level.getCloudColor(tickDelta); + #endif + return new Color((float)colorVec3.x, (float)colorVec3.y, (float)colorVec3.z); } catch (Exception e) @@ -544,4 +574,6 @@ public class ClientLevelWrapper implements IClientLevelWrapper //endregion + + } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java index ad3958f74..01b7d919e 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java @@ -198,6 +198,7 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm this.updateManager = WorldChunkUpdateManager.INSTANCE.getByLevelWrapper(this.dhServerLevel.getServerLevelWrapper()); this.globalParams = new GlobalWorldGenParams(dhServerLevel); this.internalServerGenerator = new InternalServerGenerator(this.globalParams, this.dhServerLevel); + #if MC_VER > MC_1_12_2 this.chunkFileReader = new ChunkFileReader(this.globalParams); @@ -327,8 +328,11 @@ public final class BatchGenerationEnvironment implements IBatchGeneratorEnvironm //================// // variable setup // //================// + #if MC_VER <= MC_1_12_2 + // MC 1.12 can only run world gen on the main thread this.internalServerGenerator.generateChunksViaInternalServer(genEvent); + #else int borderSize = MAX_WORLD_GEN_CHUNK_BORDER_NEEDED; // genEvent.size - 1 converts the even width size to an odd number for MC compatability