44import com .llamalad7 .mixinextras .injector .wrapoperation .WrapOperation ;
55import com .mojang .blaze3d .systems .RenderSystem ;
66import net .minecraft .client .Camera ;
7+ import net .minecraft .client .Minecraft ;
8+ import net .minecraft .client .multiplayer .ClientLevel ;
79import net .minecraft .client .renderer .FogRenderer ;
810import org .spongepowered .asm .mixin .Mixin ;
11+ import org .spongepowered .asm .mixin .Unique ;
912import org .spongepowered .asm .mixin .injection .At ;
1013import org .spongepowered .asm .mixin .injection .Inject ;
1114import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
15+ import org .valkyrienskies .clockwork .util .AABBHelper ;
16+ import org .valkyrienskies .core .api .world .connectivity .SparseVoxelPosition ;
17+
18+ import java .util .Set ;
1219
1320@ Mixin (FogRenderer .class )
1421public class MixinFogRenderer {
15- /*
22+ /*
1623 private static Camera clockwork$capturedCamera = null;
1724
1825 @Inject(method = "setupFog", at = @At(value = "HEAD"))
19- private static void clockwork$submarineFogCapture(Camera activeRenderInfo, FogRenderer.FogMode fogType , float farPlaneDistance, boolean nearFog, CallbackInfo ci){
26+ private static void clockwork$submarineFogCapture(Camera activeRenderInfo, FogRenderer.FogMode fogMode , float farPlaneDistance, boolean nearFog, float f , CallbackInfo ci){
2027 clockwork$capturedCamera = activeRenderInfo;
2128 }
2229
@@ -38,21 +45,31 @@ public class MixinFogRenderer {
3845 }
3946 }
4047
41- @Inject(method = "setupFog", at = @At(value = "HEAD"))
42- private static void d(Camera activeRenderInfo, FogRenderer.FogMode fogType, float farPlaneDistance, boolean nearFog, CallbackInfo ci){
48+ @Unique
49+ private static void vs$scissorEach(Camera activeRenderInfo, FogRenderer.FogMode fogType, float farPlaneDistance, boolean nearFog, float f, Set<SparseVoxelPosition> voxels) {
50+ for (SparseVoxelPosition voxel : voxels) {
51+ var excludeAABB = AABBHelper.INSTANCE.toAABBic(voxel);
52+ if (excludeAABB != null) {
53+ int minX = (int) excludeAABB.minX;
54+ int minY = (int) excludeAABB.minY;
55+ int maxX = (int) excludeAABB.maxX;
56+ int maxY = (int) excludeAABB.maxY;
4357
44- var excludeAABB = activeRenderInfo.getEntity().getBoundingBox().inflate(10);
58+ // Adjust scissor box if needed (for example, convert coordinates to screen space)
59+
60+ // Enable scissor test
61+ RenderSystem.enableScissor(minX, minY, maxX - minX, maxY - minY);
62+ }
63+ }
64+ }
65+
66+ @Inject(method = "setupFog", at = @At(value = "HEAD"))
67+ private static void d(Camera activeRenderInfo, FogRenderer.FogMode fogType, float farPlaneDistance, boolean nearFog, float f, CallbackInfo ci){
4568
46- if (excludeAABB != null) {
47- int minX = (int) excludeAABB.minX;
48- int minY = (int) excludeAABB.minY;
49- int maxX = (int) excludeAABB.maxX;
50- int maxY = (int) excludeAABB.maxY;
69+ if (Minecraft.getInstance() != null && Minecraft.getInstance().level != null) {
70+ ClientLevel level = Minecraft.getInstance().level;
5171
52- // Adjust scissor box if needed (for example, convert coordinates to screen space)
5372
54- // Enable scissor test
55- RenderSystem.enableScissor(minX, minY, maxX - minX, maxY - minY);
5673 }
5774
5875 // Render the scene (fog will be applied, but excluded in the scissor box if specified)
@@ -61,9 +78,9 @@ private static void d(Camera activeRenderInfo, FogRenderer.FogMode fogType, floa
6178
6279 }
6380 @Inject(method = "setupFog", at = @At(value = "TAIL"))
64- private static void e(Camera activeRenderInfo, FogRenderer.FogMode fogType, float farPlaneDistance, boolean nearFog, CallbackInfo ci){
81+ private static void e(Camera activeRenderInfo, FogRenderer.FogMode fogType, float farPlaneDistance, boolean nearFog, float f, CallbackInfo ci){
6582 RenderSystem.disableScissor();
6683 }
6784
68- */
85+ */
6986}
0 commit comments