Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna0x01 committed Jan 2, 2025
2 parents 75d74a2 + 06693ef commit d82b62b
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 169 deletions.
1 change: 1 addition & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies {
modCompileOnly("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:1.9.4+1.8.9")

implementation("io.waterwave.Legacy-LWJGL3:lwjgl:3.3.2-5")
runtimeOnly("org.lwjgl", "lwjgl", version = "3.3.2", classifier = "natives-linux")
runtimeOnly("org.lwjgl", "lwjgl", version = "3.3.2", classifier = "natives-windows")

// We need to be careful during pre-launch that we don't touch any Minecraft classes, since other mods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,25 @@

import it.unimi.dsi.fastutil.objects.Reference2ReferenceMap;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
import net.caffeinemc.mods.sodium.client.model.quad.ModelQuadView;
import net.caffeinemc.mods.sodium.client.model.quad.blender.BlendedColorProvider;
import net.caffeinemc.mods.sodium.client.world.LevelSlice;
import net.minecraft.block.AbstractFluidBlock;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.util.math.BlockPos;

import java.util.Arrays;

public class ColorProviderRegistry {
private final Reference2ReferenceMap<Block, ColorProvider> blocks = new Reference2ReferenceOpenHashMap<>();
private final Reference2ReferenceMap<Block, ColorProvider> fluids = new Reference2ReferenceOpenHashMap<>();

class WaterColors extends BlendedColorProvider {
@Override
protected int getColor(LevelSlice slice, BlockPos pos) {
return BiomeColors.getWaterColor(slice, pos) | 0xFF000000;
}
}

class WaterBlockColors implements ColorProvider {
@Override
public void getColors(LevelSlice slice, BlockPos pos, ModelQuadView quad, int[] output) {
Arrays.fill(output, BiomeColors.getWaterColor(slice, pos) | 0xFF000000);
}
//@Override
//protected int getColor(LevelSlice slice, BlockState state, BlockPos pos) {
// return BiomeColors.getWaterColor(slice, pos) | 0xFF000000;
//}
}


public ColorProviderRegistry() {
this.installOverrides();
this.blocks.defaultReturnValue(DefaultColorProviders.BLOCK);
}

// TODO: Allow mods to install their own color resolvers here
private void installOverrides() {
this.registerBlocks(DefaultColorProviders.GRASS, Blocks.GRASS, Blocks.SUGARCANE, Blocks.TALLGRASS, Blocks.DOUBLE_PLANT);
this.registerBlocks(DefaultColorProviders.FOLIAGE, Blocks.LEAVES, Blocks.LEAVES2, Blocks.VINE);
this.registerBlocks(new WaterBlockColors(), Blocks.WATER);
this.registerFluids(new WaterBlockColors(), Blocks.WATER, Blocks.FLOWING_WATER);
this.registerBlocks(DefaultColorProviders.WATER, Blocks.WATER);
this.registerFluids(DefaultColorProviders.WATER, Blocks.WATER, Blocks.FLOWING_WATER);
}

private void registerBlocks(ColorProvider provider, Block... blocks) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
package net.caffeinemc.mods.sodium.client.model.color;

import dev.vexor.radium.compat.mojang.minecraft.IBlockColor;
import net.caffeinemc.mods.sodium.client.model.quad.ModelQuadView;
import net.caffeinemc.mods.sodium.client.model.quad.blender.BlendedColorProvider;
import net.caffeinemc.mods.sodium.client.world.LevelSlice;
import net.caffeinemc.mods.sodium.client.world.biome.BiomeColorSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.block.BlockState;

import java.util.Arrays;

public class DefaultColorProviders {
public static ColorProvider adapt(IBlockColor color) {
return new VanillaAdapter(color);
}

public static final BlockColorProvider BLOCK = new BlockColorProvider();
public static final WaterColorProvider WATER = new WaterColorProvider();
public static final GrassColorProvider GRASS = new GrassColorProvider();
public static final FoliageColorProvider FOLIAGE = new FoliageColorProvider();

public static class BlockColorProvider implements ColorProvider {
@Override
public void getColors(LevelSlice slice, BlockPos pos, ModelQuadView quad, int[] output) {
var block = slice.getBlockState(pos).getBlock();
for (int i = 0; i < output.length; i++) {
output[i] = block.getBlockColor(slice, pos, i);
}
}
}

public static class WaterColorProvider extends BlendedColorProvider {
@Override
protected int getColor(LevelSlice slice, BlockPos pos) {
Expand All @@ -39,17 +42,4 @@ protected int getColor(LevelSlice slice, BlockPos pos) {
return slice.getColor(BiomeColorSource.FOLIAGE, pos.getX(), pos.getY(), pos.getZ());
}
}

private static class VanillaAdapter implements ColorProvider {
private final IBlockColor color;

private VanillaAdapter(IBlockColor color) {
this.color = color;
}

@Override
public void getColors(LevelSlice slice, BlockPos pos, ModelQuadView quad, int[] output) {
Arrays.fill(output, this.color.colorMultiplier(slice, pos, quad.getTintIndex()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void renderQuadList(BlockRenderContext ctx, Material material, LightPipe

private QuadLightData getVertexLight(BlockRenderContext ctx, LightPipeline lighter, Direction cullFace, BakedQuadView quad) {
QuadLightData light = this.quadLightData;
lighter.calculate(quad, ctx.pos(), light, cullFace, quad.getLightFace(), quad.hasShade(), true);
lighter.calculate(quad, ctx.pos(), light, cullFace, quad.getLightFace(), quad.hasShade(), false);

return light;
}
Expand All @@ -148,11 +148,8 @@ private int[] getVertexColors(BlockRenderContext ctx, ColorProvider colorProvide

if (colorProvider != null && quad.hasColor()) {
colorProvider.getColors(ctx.slice(), ctx.pos(), quad, vertexColors);
for (int i = 0; i < 4; i++) {
vertexColors[i] = ColorARGB.toABGR(vertexColors[i]);
}
} else {
Arrays.fill(vertexColors, 0xFFFFFFFF);
Arrays.fill(vertexColors, 0xFFFFFF);
}

return vertexColors;
Expand All @@ -179,7 +176,7 @@ private void writeGeometry(BlockRenderContext ctx,
out.y = ctx.origin().y() + quad.getY(srcIndex) + (float) offset.y;
out.z = ctx.origin().z() + quad.getZ(srcIndex) + (float) offset.z;

out.color = colors[srcIndex];
out.color = ColorARGB.toABGR(colors[srcIndex]) | 0xFF000000;
out.ao = light.br[srcIndex];

out.u = quad.getTexU(srcIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.apache.commons.lang3.mutable.MutableFloat;
import org.apache.commons.lang3.mutable.MutableInt;

import java.util.Arrays;

public class DefaultFluidRenderer {
// TODO: allow this to be changed by vertex format, WARNING: make sure TranslucentGeometryCollector knows about EPSILON
// TODO: move fluid rendering to a separate render pass and control glPolygonOffset and glDepthFunc to fix this properly
Expand Down Expand Up @@ -373,12 +375,16 @@ private void updateQuad(ModelQuadViewMutable quad, LevelSlice level, BlockPos po

lighter.calculate(quad, pos, light, null, dir, false, false);

colorProvider.getColors(level, pos, quad, this.quadColors);
if (colorProvider != null && quad.hasColor()) {
colorProvider.getColors(level, pos, quad, this.quadColors);
} else {
Arrays.fill(this.quadColors, 0xFFFFFF);
}

// multiply the per-vertex color against the combined brightness
// the combined brightness is the per-vertex brightness multiplied by the block's brightness
for (int i = 0; i < 4; i++) {
this.quadColors[i] = ColorARGB.toABGR(this.quadColors[i]);
this.quadColors[i] = ColorARGB.toABGR(this.quadColors[i]) | 0xFF000000;
this.brightness[i] = light.br[i] * brightness;
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
public class FluidRendererImpl extends FluidRenderer {
private final ColorProviderRegistry colorProviderRegistry;
private final DefaultFluidRenderer defaultRenderer;
private final DefaultRenderContext defaultContext;

private final FluidSprites sprites;

public FluidRendererImpl(ColorProviderRegistry colorProviderRegistry, LightPipelineProvider lighters) {
this.colorProviderRegistry = colorProviderRegistry;
defaultRenderer = new DefaultFluidRenderer(lighters);
defaultContext = new DefaultRenderContext();
sprites = FluidSprites.create();
}

Expand All @@ -32,34 +30,6 @@ public void render(LevelSlice level, BlockState blockState, BlockState fluidStat
var meshBuilder = buffers.get(material);
var fluid = WorldUtil.getFluid(fluidState);

defaultContext.setUp(this.colorProviderRegistry, false);

defaultRenderer.render(level, blockState, blockPos, offset, collector, meshBuilder, material, defaultContext.getColorProvider(fluid), sprites.forFluid(fluid));

defaultContext.clear();
}

private static class DefaultRenderContext {
private ColorProviderRegistry colorProviderRegistry;
private boolean hasModOverride;

public void setUp(ColorProviderRegistry colorProviderRegistry, boolean hasModOverride) {
this.colorProviderRegistry = colorProviderRegistry;
this.hasModOverride = hasModOverride;
}

public void clear() {
this.hasModOverride = false;
}

public ColorProvider getColorProvider(AbstractFluidBlock fluid) {
var override = this.colorProviderRegistry.getColorProvider(fluid);

if (!hasModOverride && override != null) {
return override;
}

return FabricColorProvider.adapt();
}
defaultRenderer.render(level, blockState, blockPos, offset, collector, meshBuilder, material, colorProviderRegistry.getColorProvider(fluid), sprites.forFluid(fluid));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,18 @@ public ChunkBuildOutput execute(ChunkBuildContext buildContext, CancellationToke

for (int z = minZ; z < maxZ; z++) {
for (int x = minX; x < maxX; x++) {
BlockState blockState = slice.getBlockState(x, y, z);
var blockType = blockState.getBlock().getBlockType();
blockPos.setPosition(x, y, z);

var blockState = slice.getBlockState(blockPos);
var block = blockState.getBlock();
var blockType = block.getBlockType();


if (BlockRenderType.isInvisible(blockType) && !blockState.getBlock().hasBlockEntity()) {
if (BlockRenderType.isInvisible(blockType) && block.hasBlockEntity()) {
continue;
}

blockPos.setPosition(x, y, z);

blockState = blockState.getBlock().getBlockState(blockState, slice, blockPos);
blockState = block.getBlockState(blockState, slice, blockPos);

modelOffset.setPosition(x & 15, y & 15, z & 15);

Expand All @@ -117,14 +119,13 @@ public ChunkBuildOutput execute(ChunkBuildContext buildContext, CancellationToke
context.update(blockPos, modelOffset, blockState, model);
cache.getBlockRenderer()
.renderModel(context, buffers);
//blockRenderer.renderModel(model, blockState, blockPos, modelOffset);
}

if (BlockRenderType.isLiquid(blockType)) {
cache.getFluidRenderer().render(slice, blockState, blockState, blockPos, modelOffset, collector, buffers);
}

if (blockState.getBlock().hasBlockEntity()) {
if (block.hasBlockEntity()) {
BlockEntity entity = slice.getBlockEntity(blockPos);

if (entity != null) {
Expand All @@ -136,8 +137,7 @@ public ChunkBuildOutput execute(ChunkBuildContext buildContext, CancellationToke
}
}

// todo: is hasTransparency in oldium
if (blockState.getBlock().isTranslucent()) {
if (block.hasTransparency()) {
occluder.markClosed(blockPos);
}
}
Expand Down
Loading

0 comments on commit d82b62b

Please sign in to comment.