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