|
| 1 | +package btw.mixces.animatium.mixins.renderer; |
| 2 | + |
| 3 | +import btw.mixces.animatium.AnimatiumClient; |
| 4 | +import btw.mixces.animatium.config.AnimatiumConfig; |
| 5 | +import btw.mixces.animatium.util.RenderUtils; |
| 6 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 7 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 8 | +import com.mojang.blaze3d.buffers.GpuBuffer; |
| 9 | +import com.mojang.blaze3d.pipeline.RenderPipeline; |
| 10 | +import com.mojang.blaze3d.systems.RenderPass; |
| 11 | +import com.mojang.blaze3d.systems.RenderSystem; |
| 12 | +import com.mojang.blaze3d.vertex.VertexFormat; |
| 13 | +import net.minecraft.client.renderer.SkyRenderer; |
| 14 | +import org.spongepowered.asm.mixin.Mixin; |
| 15 | +import org.spongepowered.asm.mixin.Unique; |
| 16 | +import org.spongepowered.asm.mixin.injection.At; |
| 17 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 18 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 19 | + |
| 20 | +@Mixin(SkyRenderer.class) |
| 21 | +public abstract class MixinSkyRenderer { |
| 22 | + @Unique |
| 23 | + private static GpuBuffer animatium$topSkyBuffer = null; |
| 24 | + |
| 25 | + @Unique |
| 26 | + private static RenderSystem.AutoStorageIndexBuffer animatium$skyIndexBuffer; |
| 27 | + |
| 28 | + @Inject(method = "<init>", at = @At("TAIL")) |
| 29 | + private void init(CallbackInfo ci) { |
| 30 | + animatium$topSkyBuffer = RenderUtils.initializeSky((builder) -> RenderUtils.buildSkyHalf(builder, 16.0F, false)); |
| 31 | + animatium$skyIndexBuffer = RenderSystem.getSequentialBuffer(VertexFormat.Mode.QUADS); |
| 32 | + } |
| 33 | + |
| 34 | + @WrapOperation(method = "renderSkyDisc", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderPass;setPipeline(Lcom/mojang/blaze3d/pipeline/RenderPipeline;)V")) |
| 35 | + private void animatium$planarFogPipeline$skyDisc(RenderPass instance, RenderPipeline renderPipeline, Operation<Void> original) { |
| 36 | + RenderPipeline pipeline = renderPipeline; |
| 37 | + if (AnimatiumClient.isEnabled() && AnimatiumConfig.instance().planarSkyFog) { |
| 38 | + pipeline = AnimatiumClient.LEGACY_SKY_PLANAR_FOG_PIPELINE; |
| 39 | + } |
| 40 | + |
| 41 | + original.call(instance, pipeline); |
| 42 | + } |
| 43 | + |
| 44 | + @WrapOperation(method = "renderSkyDisc", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderPass;setVertexBuffer(ILcom/mojang/blaze3d/buffers/GpuBuffer;)V", ordinal = 0)) |
| 45 | + private void animatium$planarFogPipeline$skyDisc$vertexBuffer(RenderPass instance, int index, GpuBuffer gpuBuffer, Operation<Void> original) { |
| 46 | + GpuBuffer buffer = gpuBuffer; |
| 47 | + if (AnimatiumClient.isEnabled() && AnimatiumConfig.instance().planarSkyFog) { |
| 48 | + buffer = animatium$topSkyBuffer; |
| 49 | + instance.setIndexBuffer(animatium$skyIndexBuffer.getBuffer(6), animatium$skyIndexBuffer.type()); |
| 50 | + } |
| 51 | + |
| 52 | + original.call(instance, index, buffer); |
| 53 | + } |
| 54 | + |
| 55 | + @WrapOperation(method = "renderDarkDisc", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderPass;setPipeline(Lcom/mojang/blaze3d/pipeline/RenderPipeline;)V")) |
| 56 | + private void animatium$planarFogPipeline$darkSkyDisc(RenderPass instance, RenderPipeline renderPipeline, Operation<Void> original) { |
| 57 | + RenderPipeline pipeline = renderPipeline; |
| 58 | + if (AnimatiumClient.isEnabled() && AnimatiumConfig.instance().planarSkyFog) { |
| 59 | + pipeline = AnimatiumClient.LEGACY_SKY_PLANAR_FOG_PIPELINE; |
| 60 | + } |
| 61 | + |
| 62 | + original.call(instance, pipeline); |
| 63 | + } |
| 64 | + |
| 65 | + @WrapOperation(method = "renderSkyDisc", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderPass;draw(II)V", ordinal = 0)) |
| 66 | + private void animatium$planarFogPipeline$skyDisc$draw(RenderPass instance, int i, int j, Operation<Void> original) { |
| 67 | + if (AnimatiumClient.isEnabled() && AnimatiumConfig.instance().planarSkyFog) { |
| 68 | + instance.drawIndexed(i, 1014); |
| 69 | + } else { |
| 70 | + original.call(instance, i, j); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + @WrapOperation(method = "renderDarkDisc", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderPass;setVertexBuffer(ILcom/mojang/blaze3d/buffers/GpuBuffer;)V", ordinal = 0)) |
| 75 | + private void animatium$planarFogPipeline$darkSkyDisc$vertexBuffer(RenderPass instance, int index, GpuBuffer gpuBuffer, Operation<Void> original) { |
| 76 | + GpuBuffer buffer = gpuBuffer; |
| 77 | + if (AnimatiumClient.isEnabled() && AnimatiumConfig.instance().planarSkyFog) { |
| 78 | + buffer = RenderUtils.getBlueVoidBuffer(); |
| 79 | + instance.setIndexBuffer(animatium$skyIndexBuffer.getBuffer(6), animatium$skyIndexBuffer.type()); |
| 80 | + } |
| 81 | + |
| 82 | + original.call(instance, index, buffer); |
| 83 | + } |
| 84 | + |
| 85 | + @WrapOperation(method = "renderDarkDisc", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderPass;draw(II)V", ordinal = 0)) |
| 86 | + private void animatium$planarFogPipeline$darkSkyDisc$draw(RenderPass instance, int i, int j, Operation<Void> original) { |
| 87 | + if (AnimatiumClient.isEnabled() && AnimatiumConfig.instance().planarSkyFog) { |
| 88 | + instance.drawIndexed(i, 1014); |
| 89 | + } else { |
| 90 | + original.call(instance, i, j); |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments