mirror of
https://github.com/TeamMidnightDust/CullLeaves.git
synced 2025-12-15 14:15:08 +01:00
CullLeaves 3.1.0 - Update to 1.20
- Update to 1.20 - Attempt to fix random BufferUnderflowExceptions with Sodium once and for all
This commit is contained in:
@@ -11,62 +11,44 @@ import me.jellysquid.mods.sodium.client.render.vertex.type.ChunkVertexType;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(value = RegionChunkRenderer.class, remap = false, priority = 1100)
|
||||
public abstract class MixinRegionChunkRenderer extends ShaderChunkRenderer {
|
||||
@Shadow @Final private boolean isBlockFaceCullingEnabled;
|
||||
@Shadow protected abstract void addDrawCall(ElementRange part, long baseIndexPointer, int baseVertexIndex);
|
||||
@Unique private boolean doFix = false;
|
||||
@Unique private ChunkCameraContext camera;
|
||||
@Unique private ChunkRenderBounds bounds;
|
||||
|
||||
public MixinRegionChunkRenderer(RenderDevice device, ChunkVertexType vertexType) {
|
||||
super(device, vertexType);
|
||||
}
|
||||
|
||||
@Inject(method = "buildDrawBatches", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/RenderSection;getBounds()Lme/jellysquid/mods/sodium/client/render/chunk/data/ChunkRenderBounds;", ordinal = 0))
|
||||
public void cullleaves$shouldApplyTransparentBlockFaceCullingFix(List<RenderSection> sections, BlockRenderPass pass, ChunkCameraContext camera, CallbackInfoReturnable<Boolean> cir) {
|
||||
doFix = pass.getAlphaCutoff() != 0 && CullLeavesConfig.enabled && CullLeavesConfig.sodiumBlockFaceCullingFix && this.isBlockFaceCullingEnabled;
|
||||
this.camera = camera;
|
||||
}
|
||||
@Redirect(method = "buildDrawBatches", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/RenderSection;getBounds()Lme/jellysquid/mods/sodium/client/render/chunk/data/ChunkRenderBounds;", ordinal = 0))
|
||||
public ChunkRenderBounds cullleaves$getChunkRenderBounds(RenderSection instance) {
|
||||
bounds = instance.getBounds();
|
||||
return bounds;
|
||||
}
|
||||
@Redirect(method = "buildDrawBatches", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/ChunkGraphicsState;getModelPart(Lme/jellysquid/mods/sodium/client/model/quad/properties/ModelQuadFacing;)Lme/jellysquid/mods/sodium/client/gl/util/ElementRange;", ordinal = 0))
|
||||
public ElementRange cullleaves$fixTransparentBlockFaceCulling(ChunkGraphicsState state, ModelQuadFacing facing) {
|
||||
if (doFix) {
|
||||
long indexOffset = state.getIndexSegment().getOffset();
|
||||
int baseVertex = state.getVertexSegment().getOffset() / this.vertexFormat.getStride();
|
||||
if (this.isBlockFaceCullingEnabled) {
|
||||
if (camera.posY <= bounds.y1) {
|
||||
this.addDrawCall(state.getModelPart(ModelQuadFacing.UP), indexOffset, baseVertex);
|
||||
}
|
||||
if (camera.posY >= bounds.y2) {
|
||||
this.addDrawCall(state.getModelPart(ModelQuadFacing.DOWN), indexOffset, baseVertex);
|
||||
}
|
||||
if (camera.posX <= bounds.x1) {
|
||||
this.addDrawCall(state.getModelPart(ModelQuadFacing.EAST), indexOffset, baseVertex);
|
||||
}
|
||||
if (camera.posX >= bounds.x2) {
|
||||
this.addDrawCall(state.getModelPart(ModelQuadFacing.WEST), indexOffset, baseVertex);
|
||||
}
|
||||
if (camera.posZ <= bounds.z1) {
|
||||
this.addDrawCall(state.getModelPart(ModelQuadFacing.SOUTH), indexOffset, baseVertex);
|
||||
}
|
||||
if (camera.posZ >= bounds.z2) {
|
||||
this.addDrawCall(state.getModelPart(ModelQuadFacing.NORTH), indexOffset, baseVertex);
|
||||
}
|
||||
@Inject(method = "buildDrawBatches", locals = LocalCapture.CAPTURE_FAILSOFT, at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/ChunkGraphicsState;getModelPart(Lme/jellysquid/mods/sodium/client/model/quad/properties/ModelQuadFacing;)Lme/jellysquid/mods/sodium/client/gl/util/ElementRange;", ordinal = 0))
|
||||
public void cullleaves$fixTransparentBlockFaceCulling(List<RenderSection> sections, BlockRenderPass pass, ChunkCameraContext camera, CallbackInfoReturnable<Boolean> cir, Iterator var4, RenderSection render, ChunkGraphicsState state, ChunkRenderBounds bounds, long indexOffset, int baseVertex) {
|
||||
if (pass.getAlphaCutoff() != 0 && CullLeavesConfig.enabled && CullLeavesConfig.sodiumBlockFaceCullingFix && this.isBlockFaceCullingEnabled) {
|
||||
if (camera.posY <= bounds.y1) {
|
||||
this.addDrawCall(state.getModelPart(ModelQuadFacing.UP), indexOffset, baseVertex);
|
||||
}
|
||||
if (camera.posY >= bounds.y2) {
|
||||
this.addDrawCall(state.getModelPart(ModelQuadFacing.DOWN), indexOffset, baseVertex);
|
||||
}
|
||||
if (camera.posX <= bounds.x1) {
|
||||
this.addDrawCall(state.getModelPart(ModelQuadFacing.EAST), indexOffset, baseVertex);
|
||||
}
|
||||
if (camera.posX >= bounds.x2) {
|
||||
this.addDrawCall(state.getModelPart(ModelQuadFacing.WEST), indexOffset, baseVertex);
|
||||
}
|
||||
if (camera.posZ <= bounds.z1) {
|
||||
this.addDrawCall(state.getModelPart(ModelQuadFacing.SOUTH), indexOffset, baseVertex);
|
||||
}
|
||||
if (camera.posZ >= bounds.z2) {
|
||||
this.addDrawCall(state.getModelPart(ModelQuadFacing.NORTH), indexOffset, baseVertex);
|
||||
}
|
||||
}
|
||||
return state.getModelPart(ModelQuadFacing.UNASSIGNED);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user