Skip to content

Commit

Permalink
Fix light block emission (#2474)
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Oct 4, 2024
1 parent 2255d8e commit 22bac81
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ public void beginBlock(int block, byte renderType, byte blockEmission, int local
public void endBlock() {
contextHolder.setBlockData(0, (byte) 0, (byte) 0, 0, 0, 0);
}

@Override
public void ignoreMidBlock(boolean b) {
contextHolder.setIgnoreMidBlock(b);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package net.irisshaders.iris.compat.sodium.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import net.caffeinemc.mods.sodium.client.model.quad.properties.ModelQuadFacing;
import net.caffeinemc.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers;
import net.caffeinemc.mods.sodium.client.render.chunk.compile.ChunkBuildContext;
import net.caffeinemc.mods.sodium.client.render.chunk.compile.ChunkBuildOutput;
import net.caffeinemc.mods.sodium.client.render.chunk.compile.buffers.ChunkModelBuilder;
import net.caffeinemc.mods.sodium.client.render.chunk.compile.tasks.ChunkBuilderMeshingTask;
import net.caffeinemc.mods.sodium.client.render.chunk.terrain.material.DefaultMaterials;
import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder;
import net.caffeinemc.mods.sodium.client.util.task.CancellationToken;
import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings;
import net.irisshaders.iris.vertices.BlockSensitiveBufferBuilder;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.LightBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -18,10 +23,35 @@

@Mixin(ChunkBuilderMeshingTask.class)
public class MixinChunkMeshBuildTask {
private final ChunkVertexEncoder.Vertex[] vertices = ChunkVertexEncoder.Vertex.uninitializedQuad();

@Inject(method = "execute(Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/ChunkBuildContext;Lnet/caffeinemc/mods/sodium/client/util/task/CancellationToken;)Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/ChunkBuildOutput;", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/core/BlockPos$MutableBlockPos;set(III)Lnet/minecraft/core/BlockPos$MutableBlockPos;", ordinal = 1))
private void iris$setLightBlock(ChunkBuildContext buildContext, CancellationToken cancellationToken, CallbackInfoReturnable<ChunkBuildOutput> cir, @Local ChunkBuildBuffers buffers, @Local BlockState blockState, @Local(ordinal = 0) BlockPos.MutableBlockPos blockPos) {
if (WorldRenderingSettings.INSTANCE.getBlockStateIds() == null) return;

if (WorldRenderingSettings.INSTANCE.shouldVoxelizeLightBlocks() && blockState.getBlock() instanceof LightBlock) {
ChunkModelBuilder buildBuffers = buffers.get(DefaultMaterials.CUTOUT);
((BlockSensitiveBufferBuilder) buffers).ignoreMidBlock(true);
((BlockSensitiveBufferBuilder) buffers).beginBlock(WorldRenderingSettings.INSTANCE.getBlockStateIds().getInt(blockState), (byte) 0, (byte) blockState.getLightEmission(), 0, 0, 0);
for (int i = 0; i < 4; i++) {
vertices[i].x = (float) ((blockPos.getX() & 15)) + 0.25f;
vertices[i].y = (float) ((blockPos.getY() & 15)) + 0.25f;
vertices[i].z = (float) ((blockPos.getZ() & 15)) + 0.25f;
vertices[i].u = 0;
vertices[i].v = 0;
vertices[i].color = 0;
vertices[i].light = blockState.getLightEmission() << 4 | blockState.getLightEmission() << 20;
}
buildBuffers.getVertexBuffer(ModelQuadFacing.UNASSIGNED).push(vertices, DefaultMaterials.CUTOUT);
((BlockSensitiveBufferBuilder) buffers).ignoreMidBlock(false);
}
}

@Inject(method = "execute(Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/ChunkBuildContext;Lnet/caffeinemc/mods/sodium/client/util/task/CancellationToken;)Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/ChunkBuildOutput;", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer;renderModel(Lnet/minecraft/client/resources/model/BakedModel;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Lnet/minecraft/core/BlockPos;)V"))
private void iris$onRenderModel(ChunkBuildContext buildContext, CancellationToken cancellationToken, CallbackInfoReturnable<ChunkBuildOutput> cir, @Local ChunkBuildBuffers buffers, @Local BlockState blockState, @Local(ordinal = 0) BlockPos.MutableBlockPos blockPos) {
if (WorldRenderingSettings.INSTANCE.getBlockStateIds() == null) return;

((BlockSensitiveBufferBuilder) buffers).beginBlock(WorldRenderingSettings.INSTANCE.getBlockStateIds().getInt(blockState), (byte) 0, (byte) blockState.getLightEmission(), blockPos.getX(), blockPos.getY(), blockPos.getZ());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public interface BlockSensitiveBufferBuilder {
void beginBlock(int block, byte renderType, byte blockEmission, int localPosX, int localPosY, int localPosZ);

void endBlock();

void ignoreMidBlock(boolean b);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class BlockContextHolder {
private int blockId;
private byte renderType;
private int localPosX, localPosY, localPosZ;
private boolean ignoreMidBlock;

public int getBlockId() {
return blockId;
Expand Down Expand Up @@ -40,7 +41,10 @@ public void setBlockData(int blockId, byte renderType, byte blockEmission, int l
}

public boolean ignoreMidBlock() {
// TODO ADD THIS
return false;
return ignoreMidBlock;
}

public void setIgnoreMidBlock(boolean ignoreMidBlock) {
this.ignoreMidBlock = ignoreMidBlock;
}
}

0 comments on commit 22bac81

Please sign in to comment.