From 106d97e0a147a5561565d26966e8b96cd3f724bf Mon Sep 17 00:00:00 2001 From: James Seibel Date: Fri, 7 Nov 2025 07:02:21 -0600 Subject: [PATCH 1/8] Revert "minor AbstractDhTintGetter optimization" This reverts commit 6a418de153a2a8e7fd9023ac9a1d65f9bd2a8e01. --- .../common/wrappers/block/AbstractDhTintGetter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/AbstractDhTintGetter.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/AbstractDhTintGetter.java index 33bef432d..6efbefb1a 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/AbstractDhTintGetter.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/AbstractDhTintGetter.java @@ -39,7 +39,7 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter private static final ConcurrentHashMap> BIOME_BY_RESOURCE_STRING = new ConcurrentHashMap<>(); #endif - private static final ConcurrentHashMap COLOR_BY_BIOME_WRAPPER = new ConcurrentHashMap<>(); + private static final ConcurrentHashMap COLOR_BY_BIOME = new ConcurrentHashMap<>(); /** returned if the color cache is incomplete */ public static final int INVALID_COLOR = Integer.MIN_VALUE; @@ -185,7 +185,7 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter private int tryGetClientBiomeColor(@Nullable ColorResolver colorResolver, BiomeWrapper biomeWrapper) { // use the cached color if possible - int cachedColor = COLOR_BY_BIOME_WRAPPER.getOrDefault(biomeWrapper, INVALID_COLOR); + int cachedColor = COLOR_BY_BIOME.getOrDefault(unwrapClientBiome(biomeWrapper), INVALID_COLOR); if (cachedColor != INVALID_COLOR) { return cachedColor; @@ -199,9 +199,9 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter return INVALID_COLOR; } - return COLOR_BY_BIOME_WRAPPER.computeIfAbsent(biomeWrapper, + return COLOR_BY_BIOME.computeIfAbsent(unwrapClientBiome(biomeWrapper), // in James' testing the block position isn't needed so we can just default to (0,0) - (newBiomeWrapper) -> colorResolver.getColor(unwrapClientBiome(biomeWrapper), 0, 0)); + (unwrappedBiome) -> colorResolver.getColor(unwrappedBiome, 0, 0)); } protected static Biome unwrapClientBiome(BiomeWrapper biomeWrapper) From e05dff3fb941ebe844b1d9df3aa349669adf0eee Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 8 Nov 2025 17:51:50 -0600 Subject: [PATCH 2/8] Optimize DhTintGetter --- .../wrappers/block/AbstractDhTintGetter.java | 22 ++++++++++++------- .../block/ClientBlockStateColorCache.java | 10 +++++---- .../wrappers/block/TintGetterOverride.java | 4 ++-- .../wrappers/world/ClientLevelWrapper.java | 14 +++++++----- coreSubProjects | 2 +- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/AbstractDhTintGetter.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/AbstractDhTintGetter.java index 6efbefb1a..18be701a1 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/AbstractDhTintGetter.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/AbstractDhTintGetter.java @@ -1,6 +1,7 @@ package com.seibel.distanthorizons.common.wrappers.block; import com.seibel.distanthorizons.core.config.Config; +import com.seibel.distanthorizons.core.dataObjects.BlockBiomeWrapperPair; import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.pos.DhSectionPos; @@ -9,6 +10,7 @@ import com.seibel.distanthorizons.core.util.ColorUtil; import com.seibel.distanthorizons.core.util.FullDataPointUtil; import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; +import it.unimi.dsi.fastutil.longs.LongArrayList; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.core.BlockPos; @@ -39,13 +41,13 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter private static final ConcurrentHashMap> BIOME_BY_RESOURCE_STRING = new ConcurrentHashMap<>(); #endif - private static final ConcurrentHashMap COLOR_BY_BIOME = new ConcurrentHashMap<>(); - + private static final ConcurrentHashMap COLOR_BY_BLOCK_BIOME_PAIR = new ConcurrentHashMap<>(); /** returned if the color cache is incomplete */ public static final int INVALID_COLOR = Integer.MIN_VALUE; protected BiomeWrapper biomeWrapper; + protected BlockStateWrapper blockStateWrapper; protected FullDataSourceV2 fullDataSource; protected int smoothingRadiusInBlocks; protected IClientLevelWrapper clientLevelWrapper; @@ -62,9 +64,10 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter * Mutates this getter so we can access the necessary * variables for tint getting. */ - public void update(BiomeWrapper biomeWrapper, FullDataSourceV2 fullDataSource, IClientLevelWrapper clientLevelWrapper) + public void update(BiomeWrapper biomeWrapper, BlockStateWrapper blockStateWrapper, FullDataSourceV2 fullDataSource, IClientLevelWrapper clientLevelWrapper) { this.biomeWrapper = biomeWrapper; + this.blockStateWrapper = blockStateWrapper; this.fullDataSource = fullDataSource; this.clientLevelWrapper = clientLevelWrapper; this.smoothingRadiusInBlocks = Config.Client.Advanced.Graphics.Quality.lodBiomeBlending.get(); @@ -184,9 +187,11 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter */ private int tryGetClientBiomeColor(@Nullable ColorResolver colorResolver, BiomeWrapper biomeWrapper) { + BlockBiomeWrapperPair pair = BlockBiomeWrapperPair.get(this.blockStateWrapper, biomeWrapper); + // use the cached color if possible - int cachedColor = COLOR_BY_BIOME.getOrDefault(unwrapClientBiome(biomeWrapper), INVALID_COLOR); - if (cachedColor != INVALID_COLOR) + Integer cachedColor = COLOR_BY_BLOCK_BIOME_PAIR.get(pair); // explicit Integer return here reduces unnecessary allocations + if (cachedColor != null) { return cachedColor; } @@ -199,9 +204,10 @@ public abstract class AbstractDhTintGetter implements BlockAndTintGetter return INVALID_COLOR; } - return COLOR_BY_BIOME.computeIfAbsent(unwrapClientBiome(biomeWrapper), - // in James' testing the block position isn't needed so we can just default to (0,0) - (unwrappedBiome) -> colorResolver.getColor(unwrappedBiome, 0, 0)); + + int color = colorResolver.getColor(unwrapClientBiome(biomeWrapper), 0, 0); + COLOR_BY_BLOCK_BIOME_PAIR.put(pair, color); + return color; } protected static Biome unwrapClientBiome(BiomeWrapper biomeWrapper) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/ClientBlockStateColorCache.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/ClientBlockStateColorCache.java index 2118b5f67..79987701b 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/ClientBlockStateColorCache.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/ClientBlockStateColorCache.java @@ -94,6 +94,7 @@ public class ClientBlockStateColorCache private final IClientLevelWrapper clientLevelWrapper; private final BlockState blockState; + private final BlockStateWrapper blockStateWrapper; private boolean isColorResolved = false; private int baseColor = 0; @@ -173,10 +174,11 @@ public class ClientBlockStateColorCache // constructor // //=============// - public ClientBlockStateColorCache(BlockState blockState, IClientLevelWrapper samplingLevel) + public ClientBlockStateColorCache(BlockState blockState, IClientLevelWrapper clientLevelWrapper) { this.blockState = blockState; - this.clientLevelWrapper = samplingLevel; + this.blockStateWrapper = BlockStateWrapper.fromBlockState(blockState, clientLevelWrapper); + this.clientLevelWrapper = clientLevelWrapper; this.resolveColors(); } @@ -472,7 +474,7 @@ public class ClientBlockStateColorCache try { TintWithoutLevelOverrider tintOverride = TintWithoutLevelOverrideGetter.get(); - tintOverride.update(biomeWrapper, fullDataSource, this.clientLevelWrapper); + tintOverride.update(biomeWrapper, this.blockStateWrapper, fullDataSource, this.clientLevelWrapper); // try using DH's cached tint values first if possible tintColor = tintOverride.tryGetBlockTint(new DhBlockPosMutable(blockPos)); @@ -503,7 +505,7 @@ public class ClientBlockStateColorCache // specifically oceans don't render correctly TintGetterOverride tintOverride = TintOverrideGetter.get(); - tintOverride.update(biomeWrapper, fullDataSource, this.clientLevelWrapper); + tintOverride.update(biomeWrapper, this.blockStateWrapper, fullDataSource, this.clientLevelWrapper); tintColor = tintOverride.tryGetBlockTint(new DhBlockPosMutable(blockPos)); if (tintColor == AbstractDhTintGetter.INVALID_COLOR) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintGetterOverride.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintGetterOverride.java index 3a26bdf62..c95337978 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintGetterOverride.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/TintGetterOverride.java @@ -51,9 +51,9 @@ public class TintGetterOverride extends AbstractDhTintGetter public TintGetterOverride() { } - public void update(LevelReader parent, BiomeWrapper biomeWrapper, FullDataSourceV2 fullDataSource, IClientLevelWrapper clientLevelWrapper) + public void update(LevelReader parent, BiomeWrapper biomeWrapper, BlockStateWrapper blockStateWrapper, FullDataSourceV2 fullDataSource, IClientLevelWrapper clientLevelWrapper) { - super.update(biomeWrapper, fullDataSource, clientLevelWrapper); + super.update(biomeWrapper, blockStateWrapper, fullDataSource, clientLevelWrapper); this.parent = parent; } 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 e734fa846..2c80c5b06 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 @@ -199,13 +199,17 @@ public class ClientLevelWrapper implements IClientLevelWrapper //====================// @Override - public int getBlockColor(DhBlockPos pos, IBiomeWrapper biome, FullDataSourceV2 fullDataSource, IBlockStateWrapper blockWrapper) + public int getBlockColor(DhBlockPos blockPos, IBiomeWrapper biome, FullDataSourceV2 fullDataSource, IBlockStateWrapper blockWrapper) { - ClientBlockStateColorCache blockColorCache = this.blockColorCacheByBlockState.computeIfAbsent( - ((BlockStateWrapper) blockWrapper).blockState, - this.createCachedBlockColorCacheFunc); + ClientBlockStateColorCache blockColorCache = this.blockColorCacheByBlockState.get(((BlockStateWrapper) blockWrapper).blockState); + if (blockColorCache == null) + { + blockColorCache = this.blockColorCacheByBlockState.computeIfAbsent( + ((BlockStateWrapper) blockWrapper).blockState, + this.createCachedBlockColorCacheFunc); + } - return blockColorCache.getColor((BiomeWrapper) biome, fullDataSource, pos); + return blockColorCache.getColor((BiomeWrapper) biome, fullDataSource, blockPos); } diff --git a/coreSubProjects b/coreSubProjects index 4d4d8fd8e..f0acc73c5 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit 4d4d8fd8e9570debe6e3cedbddf658a2f5951145 +Subproject commit f0acc73c5640e967e7af688d2c5d143e0140d16b From 45efeb96fa342be6382de5fe4fccc7bea566c3e7 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 8 Nov 2025 18:08:10 -0600 Subject: [PATCH 3/8] Optimize ColumnBox building --- coreSubProjects | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreSubProjects b/coreSubProjects index f0acc73c5..b5199cfa8 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit f0acc73c5640e967e7af688d2c5d143e0140d16b +Subproject commit b5199cfa87454f01eaa1209157edecffa03695f2 From 197051747ac06eee6d58dd32c183b3c4a8fb6007 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Mon, 10 Nov 2025 07:31:14 -0600 Subject: [PATCH 4/8] put zstd version in main gradle file --- build.gradle | 2 +- gradle.properties | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0b216fbce..62a3ca144 100644 --- a/build.gradle +++ b/build.gradle @@ -248,7 +248,7 @@ subprojects { p -> // We cannot relocate this library since we call some MC classes that reference it implementation("it.unimi.dsi:fastutil:${rootProject.fastutil_version}") - forgeShadowMe("com.github.luben:zstd-jni:1.5.7-4") + forgeShadowMe("com.github.luben:zstd-jni:${rootProject.zstd_version}") // Compression forgeShadowMe("org.lz4:lz4-java:${rootProject.lz4_version}") // LZ4 diff --git a/gradle.properties b/gradle.properties index a92a7930e..b6c6fb489 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,6 +23,7 @@ manifold_version=2025.1.27 nightconfig_version=3.6.6 lz4_version=1.8.0 xz_version=1.9 +zstd_version=1.5.7-6 # Before updating, read relocate_natives/README.md sqlite_jdbc_version=3.47.2.0 # 8.2.1 is the newest version we can use since that's the version MC 1.16.5 uses From 3a0115113768938e9c9dcb85db10daffe821a103 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Mon, 10 Nov 2025 07:33:11 -0600 Subject: [PATCH 5/8] re-add GPU upload config including "none" --- coreSubProjects | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreSubProjects b/coreSubProjects index b5199cfa8..6eb24ecde 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit b5199cfa87454f01eaa1209157edecffa03695f2 +Subproject commit 6eb24ecde13ecd14ebb933faa4dd1907fe4c7801 From 70be3f9364bebfa4444ce2de82be4655c34d770e Mon Sep 17 00:00:00 2001 From: James Seibel Date: Wed, 12 Nov 2025 07:22:00 -0600 Subject: [PATCH 6/8] Add varint encoding for full data --- coreSubProjects | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreSubProjects b/coreSubProjects index 6eb24ecde..b9746381e 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit 6eb24ecde13ecd14ebb933faa4dd1907fe4c7801 +Subproject commit b9746381eb11d39197d6a7fc813abdad1e3ea108 From 506ba05b34c455fa9c23131a1c0b6d95137ff7bf Mon Sep 17 00:00:00 2001 From: James Seibel Date: Thu, 13 Nov 2025 07:18:13 -0600 Subject: [PATCH 7/8] Don't duplicate adjacent data --- coreSubProjects | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreSubProjects b/coreSubProjects index b9746381e..6fe0df7d0 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit b9746381eb11d39197d6a7fc813abdad1e3ea108 +Subproject commit 6fe0df7d0fd32c0a6e42343d6c1e104f4369726f From f67fb1758d53fc20ad52ef456df658020780ecbc Mon Sep 17 00:00:00 2001 From: James Seibel Date: Fri, 14 Nov 2025 07:46:10 -0600 Subject: [PATCH 8/8] Speed up shutdown and reduce logging --- .../BatchGenerationEnvironment.java | 20 +++++++++++++++++-- coreSubProjects | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) 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 de0552ae3..69f5155a5 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 @@ -42,6 +42,8 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.worldGeneration.Abstrac import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; import java.io.IOException; +import java.nio.channels.ClosedByInterruptException; +import java.nio.channels.ClosedChannelException; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; @@ -681,12 +683,25 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv actualThrowable = completionException.getCause(); } - CHUNK_LOAD_LOGGER.warn("DistantHorizons: Couldn't load or make chunk ["+chunkPos+"], error: ["+actualThrowable.getMessage()+"].", actualThrowable); + // interrupts mean the world generator is being shut down, no need to log that + boolean isShutdownException = + actualThrowable instanceof InterruptedException + || actualThrowable instanceof ClosedByInterruptException; + if (!isShutdownException) + { + CHUNK_LOAD_LOGGER.warn("DistantHorizons: Couldn't load or make chunk ["+chunkPos+"], error: ["+actualThrowable.getMessage()+"].", actualThrowable); + } + return null; }); } #endif } + catch (ClosedByInterruptException ignore) + { + // this just means the world generator is being shut down + return CompletableFuture.completedFuture(null); + } catch (Exception e) { CHUNK_LOAD_LOGGER.warn("DistantHorizons: Couldn't load or make chunk [" + chunkPos + "]. Error: [" + e.getMessage() + "].", e); @@ -1124,9 +1139,10 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv { regionStorage.close(); } + catch (ClosedChannelException ignore) { /* world generator is being shut down */ } catch (IOException e) { - EVENT_LOGGER.error("Failed to close region file storage cache!", e); + EVENT_LOGGER.error("Failed to close region file storage cache, error: ["+e.getMessage()+"].", e); } } diff --git a/coreSubProjects b/coreSubProjects index 6fe0df7d0..b82a59ecb 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit 6fe0df7d0fd32c0a6e42343d6c1e104f4369726f +Subproject commit b82a59ecbc5bd070eec4f22f808dceb837514f5e