From a35a268670751854dc09debc907ddb709c392aca Mon Sep 17 00:00:00 2001 From: TomTheFurry Date: Fri, 9 Sep 2022 15:29:24 +0800 Subject: [PATCH] Make tint works again! Impl getting tint without level obj but with biome obj. --- .../common/wrappers/block/BiomeWrapper.java | 4 +- .../block/TintWithoutLevelOverrider.java | 91 ++++++++++++++ .../TintWithoutLevelSmoothOverrider.java | 115 ++++++++++++++++++ .../block/cache/ClientBlockStateCache.java | 15 +-- 4 files changed, 210 insertions(+), 15 deletions(-) create mode 100644 common/src/main/java/com/seibel/lod/common/wrappers/block/TintWithoutLevelOverrider.java create mode 100644 common/src/main/java/com/seibel/lod/common/wrappers/block/TintWithoutLevelSmoothOverrider.java diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/block/BiomeWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/block/BiomeWrapper.java index 1c620ea82..96c5390f5 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/block/BiomeWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/block/BiomeWrapper.java @@ -48,10 +48,10 @@ public class BiomeWrapper implements IBiomeWrapper { #if PRE_MC_1_18_2 public static final ConcurrentMap biomeWrapperMap = new ConcurrentHashMap<>(); - private final Biome biome; + public final Biome biome; #else public static final ConcurrentMap, BiomeWrapper> biomeWrapperMap = new ConcurrentHashMap<>(); - private final Holder biome; + public final Holder biome; #endif static public IBiomeWrapper getBiomeWrapper(#if PRE_MC_1_18_2 Biome #else Holder #endif biome) diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/block/TintWithoutLevelOverrider.java b/common/src/main/java/com/seibel/lod/common/wrappers/block/TintWithoutLevelOverrider.java new file mode 100644 index 000000000..a83e719fb --- /dev/null +++ b/common/src/main/java/com/seibel/lod/common/wrappers/block/TintWithoutLevelOverrider.java @@ -0,0 +1,91 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU LGPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.common.wrappers.block; + +import com.seibel.lod.common.LodCommonMain; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.Holder; +import net.minecraft.world.level.*; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.lighting.LevelLightEngine; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; +import java.util.function.Supplier; +import java.util.stream.Stream; + +public class TintWithoutLevelOverrider implements BlockAndTintGetter { + final BiomeWrapper biome; + + public TintWithoutLevelOverrider(BiomeWrapper biome) { + this.biome = biome; + } + @Override + public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver) { + return colorResolver.getColor(_unwrap(biome.biome), blockPos.getX(), blockPos.getZ()); + } + private Biome _unwrap(#if POST_MC_1_18_2 Holder #else Biome #endif biome) { + #if POST_MC_1_18_2 + return biome.value(); + #else + return biome; + #endif + } + + @Override + public float getShade(Direction direction, boolean shade) { + throw new UnsupportedOperationException("ERROR: getShade() called on TintWithoutLevelOverrider. Object is for tinting only."); + } + @Override + public LevelLightEngine getLightEngine() { + throw new UnsupportedOperationException("ERROR: getLightEngine() called on TintWithoutLevelOverrider. Object is for tinting only."); + } + @Nullable + @Override + public BlockEntity getBlockEntity(BlockPos pos) { + throw new UnsupportedOperationException("ERROR: getBlockEntity() called on TintWithoutLevelOverrider. Object is for tinting only."); + } + + @Override + public BlockState getBlockState(BlockPos pos) { + throw new UnsupportedOperationException("ERROR: getBlockState() called on TintWithoutLevelOverrider. Object is for tinting only."); + } + @Override + public FluidState getFluidState(BlockPos pos) { + throw new UnsupportedOperationException("ERROR: getFluidState() called on TintWithoutLevelOverrider. Object is for tinting only."); + } + @Override + public int getHeight() { + throw new UnsupportedOperationException("ERROR: getHeight() called on TintWithoutLevelOverrider. Object is for tinting only."); + } + @Override + public int getMinBuildHeight() { + throw new UnsupportedOperationException("ERROR: getMinBuildHeight() called on TintWithoutLevelOverrider. Object is for tinting only."); + } +} diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/block/TintWithoutLevelSmoothOverrider.java b/common/src/main/java/com/seibel/lod/common/wrappers/block/TintWithoutLevelSmoothOverrider.java new file mode 100644 index 000000000..b272e6c88 --- /dev/null +++ b/common/src/main/java/com/seibel/lod/common/wrappers/block/TintWithoutLevelSmoothOverrider.java @@ -0,0 +1,115 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU LGPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.common.wrappers.block; + +import com.seibel.lod.common.LodCommonMain; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Cursor3D; +import net.minecraft.core.Direction; +import net.minecraft.core.Holder; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.ColorResolver; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.lighting.LevelLightEngine; +import net.minecraft.world.level.material.FluidState; +import org.jetbrains.annotations.Nullable; + +public class TintWithoutLevelSmoothOverrider implements BlockAndTintGetter { + final BiomeWrapper biome; + public int smoothingRange; + + public TintWithoutLevelSmoothOverrider(BiomeWrapper biome, int smoothingRange) { + this.biome = biome; + this.smoothingRange = smoothingRange; + } + @Override + public int getBlockTint(BlockPos blockPos, ColorResolver colorResolver) { + return colorResolver.getColor(_unwrap(biome.biome), blockPos.getX(), blockPos.getZ()); + } + private Biome _unwrap(#if POST_MC_1_18_2 Holder #else Biome #endif biome) { + #if POST_MC_1_18_2 + return biome.value(); + #else + return biome; + #endif + } +// +// public int calculateBlockTint(BlockPos blockPos, ColorResolver colorResolver) +// { +// int i = smoothingRange; +// if (i == 0) +// return colorResolver.getColor(_getBiome(blockPos), blockPos.getX(), blockPos.getZ()); +// int j = (i * 2 + 1) * (i * 2 + 1); +// int k = 0; +// int l = 0; +// int m = 0; +// Cursor3D cursor3D = new Cursor3D(blockPos.getX() - i, blockPos.getY(), blockPos.getZ() - i, blockPos.getX() + i, blockPos.getY(), blockPos.getZ() + i); +// BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(); +// while (cursor3D.advance()) +// { +// mutableBlockPos.set(cursor3D.nextX(), cursor3D.nextY(), cursor3D.nextZ()); +// int n; +// if (LodCommonMain.forgeMethodCaller != null) { +// n = LodCommonMain.forgeMethodCaller.colorResolverGetColor(colorResolver, _getBiome(mutableBlockPos), +// mutableBlockPos.getX(), mutableBlockPos.getZ()); +// } else { +// n = colorResolver.getColor(_getBiome(mutableBlockPos), mutableBlockPos.getX(), mutableBlockPos.getZ()); +// } +// +// k += (n & 0xFF0000) >> 16; +// l += (n & 0xFF00) >> 8; +// m += n & 0xFF; +// } +// return (k / j & 0xFF) << 16 | (l / j & 0xFF) << 8 | m / j & 0xFF; +// } + + @Override + public float getShade(Direction direction, boolean shade) { + throw new UnsupportedOperationException("ERROR: getShade() called on TintWithoutLevelOverrider. Object is for tinting only."); + } + @Override + public LevelLightEngine getLightEngine() { + throw new UnsupportedOperationException("ERROR: getLightEngine() called on TintWithoutLevelOverrider. Object is for tinting only."); + } + @Nullable + @Override + public BlockEntity getBlockEntity(BlockPos pos) { + throw new UnsupportedOperationException("ERROR: getBlockEntity() called on TintWithoutLevelOverrider. Object is for tinting only."); + } + + @Override + public BlockState getBlockState(BlockPos pos) { + throw new UnsupportedOperationException("ERROR: getBlockState() called on TintWithoutLevelOverrider. Object is for tinting only."); + } + @Override + public FluidState getFluidState(BlockPos pos) { + throw new UnsupportedOperationException("ERROR: getFluidState() called on TintWithoutLevelOverrider. Object is for tinting only."); + } + @Override + public int getHeight() { + throw new UnsupportedOperationException("ERROR: getHeight() called on TintWithoutLevelOverrider. Object is for tinting only."); + } + @Override + public int getMinBuildHeight() { + throw new UnsupportedOperationException("ERROR: getMinBuildHeight() called on TintWithoutLevelOverrider. Object is for tinting only."); + } +} diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/block/cache/ClientBlockStateCache.java b/common/src/main/java/com/seibel/lod/common/wrappers/block/cache/ClientBlockStateCache.java index a48c2ac52..658a1b25d 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/block/cache/ClientBlockStateCache.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/block/cache/ClientBlockStateCache.java @@ -145,7 +145,7 @@ public class ClientBlockStateCache { { quads = Minecraft.getInstance().getModelManager().getBlockModelShaper(). getBlockModel(state).getQuads(state, direction, random); - if (!quads.isEmpty() && + if (quads != null && !quads.isEmpty() && !(state.getBlock() instanceof RotatedPillarBlock && direction == Direction.UP)) break; }; @@ -178,23 +178,12 @@ public class ClientBlockStateCache { isColorResolved = true; } - - - private BlockAndTintGetter wrapColorResolver(LevelReader level) { - int blendDistance = Config.Client.Graphics.Quality.lodBiomeBlending.get(); - if (blendDistance == 0) { - return new TintGetterOverrideFast(level); - } else { - return new TintGetterOverrideSmooth(level, blendDistance); - } - } - public int getAndResolveFaceColor(BiomeWrapper biome) { // FIXME: impl per-face colors if (!needPostTinting) return baseColor; int tintColor = Minecraft.getInstance().getBlockColors() - .getColor(state, wrapColorResolver(level), pos, tintIndex); //FIXME: Use biome? Hack the ColorResolver? + .getColor(state, new TintWithoutLevelOverrider(biome), pos, tintIndex); if (tintColor == -1) return baseColor; return ColorUtil.multiplyARGBwithRGB(baseColor, tintColor); }