generated from VulpixelMC/MDK-1.21-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(day 2, Na compat): disable biome blending and modify block tint
- Loading branch information
Showing
10 changed files
with
227 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/gay/sylv/legacy_landscape/mixin/client/sodium/Mixin_BlockRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package gay.sylv.legacy_landscape.mixin.client.sodium; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import gay.sylv.legacy_landscape.data_attachment.LegacyAttachments; | ||
import gay.sylv.legacy_landscape.util.TintUtil; | ||
import net.caffeinemc.mods.sodium.client.model.color.ColorProvider; | ||
import net.caffeinemc.mods.sodium.client.model.color.ColorProviderRegistry; | ||
import net.caffeinemc.mods.sodium.client.model.color.DefaultColorProviders; | ||
import net.caffeinemc.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.BiomeColors; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.chunk.LevelChunk; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
import java.util.Arrays; | ||
|
||
@Mixin(BlockRenderer.class) | ||
@Pseudo | ||
public class Mixin_BlockRenderer { | ||
@WrapOperation( | ||
method = "renderModel", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/caffeinemc/mods/sodium/client/model/color/ColorProviderRegistry;getColorProvider(Lnet/minecraft/world/level/block/Block;)Lnet/caffeinemc/mods/sodium/client/model/color/ColorProvider;" | ||
) | ||
) | ||
private ColorProvider<BlockState> hijackColorProvider(ColorProviderRegistry instance, Block block, Operation<ColorProvider<BlockState>> original, @Local(argsOnly = true, ordinal = 0) BlockPos pos) { | ||
Minecraft client = Minecraft.getInstance(); | ||
assert client.level != null; | ||
LevelChunk chunk = client.level.getChunkAt(pos); | ||
ColorProvider<BlockState> colorProvider = original.call(instance, block); | ||
if (chunk.getData(LegacyAttachments.LEGACY_CHUNK)) { | ||
return (levelSlice, blockPos, mutableBlockPos, blockState, modelQuadView, ints) -> { | ||
if (colorProvider.equals(DefaultColorProviders.GrassColorProvider.BLOCKS)) { | ||
Arrays.fill(ints, TintUtil.saturateTint(BiomeColors.getAverageGrassColor(levelSlice, blockPos))); | ||
} else if (colorProvider.equals(DefaultColorProviders.FoliageColorProvider.BLOCKS)) { | ||
Arrays.fill(ints, TintUtil.saturateTint(BiomeColors.getAverageFoliageColor(levelSlice, blockPos))); | ||
} | ||
}; | ||
} else { | ||
return colorProvider; | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/gay/sylv/legacy_landscape/mixin/client/sodium/Mixin_ColorProviderRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package gay.sylv.legacy_landscape.mixin.client.sodium; | ||
|
||
import gay.sylv.legacy_landscape.data_attachment.LegacyAttachments; | ||
import gay.sylv.legacy_landscape.util.TintUtil; | ||
import net.caffeinemc.mods.sodium.client.model.color.ColorProvider; | ||
import net.caffeinemc.mods.sodium.client.model.color.ColorProviderRegistry; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.world.level.chunk.LevelChunk; | ||
import net.minecraft.world.level.material.Fluid; | ||
import net.minecraft.world.level.material.FluidState; | ||
import net.minecraft.world.level.material.Fluids; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.Arrays; | ||
|
||
@Mixin(ColorProviderRegistry.class) | ||
@Pseudo | ||
public abstract class Mixin_ColorProviderRegistry { | ||
@Shadow | ||
protected abstract void registerFluids(ColorProvider<FluidState> provider, Fluid... fluids); | ||
|
||
@Shadow | ||
public abstract ColorProvider<FluidState> getColorProvider(Fluid fluid); | ||
|
||
private Mixin_ColorProviderRegistry() {} | ||
|
||
@Inject( | ||
method = "installOverrides", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/caffeinemc/mods/sodium/client/model/color/ColorProviderRegistry;registerFluids(Lnet/caffeinemc/mods/sodium/client/model/color/ColorProvider;[Lnet/minecraft/world/level/material/Fluid;)V", | ||
shift = At.Shift.AFTER | ||
) | ||
) | ||
private void installWaterOverride(CallbackInfo ci) { | ||
var colorProvider = this.getColorProvider(Fluids.WATER); | ||
this.registerFluids((levelSlice, blockPos, mutableBlockPos, fluidState, modelQuadView, ints) -> { | ||
Minecraft client = Minecraft.getInstance(); | ||
assert client.level != null; | ||
LevelChunk chunk = client.level.getChunkAt(blockPos); | ||
if (chunk.getData(LegacyAttachments.LEGACY_CHUNK)) { | ||
Arrays.fill(ints, TintUtil.WATER_COLOR); | ||
} else { | ||
colorProvider.getColors(levelSlice, blockPos, mutableBlockPos, fluidState, modelQuadView, ints); | ||
} | ||
}, Fluids.WATER, Fluids.FLOWING_WATER); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/gay/sylv/legacy_landscape/mixin/client/sodium/Mixin_LevelColorCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package gay.sylv.legacy_landscape.mixin.client.sodium; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import gay.sylv.legacy_landscape.data_attachment.LegacyAttachments; | ||
import net.caffeinemc.mods.sodium.client.util.color.BoxBlur; | ||
import net.caffeinemc.mods.sodium.client.world.biome.LevelColorCache; | ||
import net.caffeinemc.mods.sodium.client.world.cloned.ChunkRenderContext; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.world.level.chunk.LevelChunk; | ||
import org.spongepowered.asm.mixin.*; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(LevelColorCache.class) | ||
public final class Mixin_LevelColorCache { | ||
@Mutable | ||
@Shadow | ||
@Final | ||
private int blendRadius; | ||
|
||
@Unique | ||
private int legacy_landscape$previousBlendRadius; | ||
|
||
@Unique | ||
private boolean legacy_landscape$isLegacyChunk; | ||
|
||
private Mixin_LevelColorCache() {} | ||
|
||
@Inject( | ||
method = "update", | ||
at = @At("HEAD") | ||
) | ||
private void disableBiomeBlending(ChunkRenderContext context, CallbackInfo ci) { | ||
Minecraft client = Minecraft.getInstance(); | ||
assert client.level != null; | ||
LevelChunk chunk = client.level.getChunk(context.getOrigin().x(), context.getOrigin().z()); | ||
if (chunk.getData(LegacyAttachments.LEGACY_CHUNK)) { | ||
legacy_landscape$previousBlendRadius = this.blendRadius; | ||
this.blendRadius = 0; | ||
legacy_landscape$isLegacyChunk = true; | ||
} else { | ||
legacy_landscape$isLegacyChunk = false; | ||
} | ||
} | ||
|
||
@Inject( | ||
method = "update", | ||
at = @At("TAIL") | ||
) | ||
private void enableBiomeBlending(ChunkRenderContext context, CallbackInfo ci) { | ||
if (this.blendRadius == 0) { | ||
this.blendRadius = legacy_landscape$previousBlendRadius; | ||
} | ||
} | ||
|
||
@WrapOperation( | ||
method = "updateColorBuffers", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/caffeinemc/mods/sodium/client/util/color/BoxBlur;blur(Lnet/caffeinemc/mods/sodium/client/util/color/BoxBlur$ColorBuffer;Lnet/caffeinemc/mods/sodium/client/util/color/BoxBlur$ColorBuffer;I)V" | ||
) | ||
) | ||
private void disableBoxBlur(BoxBlur.ColorBuffer buf, BoxBlur.ColorBuffer tmp, int radius, Operation<Void> original) { | ||
if (!legacy_landscape$isLegacyChunk) { | ||
original.call(buf, tmp, radius); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/gay/sylv/legacy_landscape/util/TintUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package gay.sylv.legacy_landscape.util; | ||
|
||
public final class TintUtil { | ||
public static final int WATER_COLOR = 0xFF334FDD; | ||
|
||
private TintUtil() {} | ||
|
||
public static int saturateTint(int tint) { | ||
int red = ((tint & 0x00FF0000)) >> 16; | ||
red += 0x28; | ||
red = Math.clamp(red, 0, 0x98); | ||
int green = ((tint & 0x0000FF00)) >> 8; | ||
green += 0x28; | ||
green = Math.clamp(green, 0, 0xFF); // prevent overflow/underflow | ||
tint = (tint & 0xFF0000FF) | green << 8 | red << 16; // clear green channel and set new green | ||
return tint; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
public net.minecraft.client.renderer.RenderType$CompositeRenderType | ||
public net.caffeinemc.mods.sodium.neoforge.render.FluidRendererImpl$DefaultRenderContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters