|
1 | 1 | package io.github.axolotlclient.mixin; |
2 | 2 |
|
| 3 | +import com.mojang.blaze3d.platform.GlStateManager; |
| 4 | +import com.mojang.blaze3d.systems.RenderSystem; |
| 5 | +import com.mojang.blaze3d.vertex.BufferBuilder; |
| 6 | +import com.mojang.blaze3d.vertex.BufferRenderer; |
| 7 | +import com.mojang.blaze3d.vertex.Tessellator; |
3 | 8 | import com.mojang.blaze3d.vertex.VertexBuffer; |
| 9 | +import com.mojang.blaze3d.vertex.VertexFormat; |
| 10 | +import com.mojang.blaze3d.vertex.VertexFormats; |
4 | 11 | import io.github.axolotlclient.AxolotlClient; |
5 | 12 | import io.github.axolotlclient.modules.sky.SkyboxManager; |
6 | 13 | import net.minecraft.client.MinecraftClient; |
7 | | -import net.minecraft.client.render.*; |
| 14 | +import net.minecraft.client.render.BackgroundRenderer; |
| 15 | +import net.minecraft.client.render.Camera; |
| 16 | +import net.minecraft.client.render.GameRenderer; |
| 17 | +import net.minecraft.client.render.ShaderProgram; |
| 18 | +import net.minecraft.client.render.SkyProperties; |
| 19 | +import net.minecraft.client.render.WorldRenderer; |
8 | 20 | import net.minecraft.client.util.math.MatrixStack; |
9 | 21 | import net.minecraft.client.world.ClientWorld; |
10 | 22 | import net.minecraft.util.Identifier; |
| 23 | +import net.minecraft.util.math.MathHelper; |
11 | 24 | import net.minecraft.util.math.Matrix4f; |
| 25 | +import net.minecraft.util.math.Vec3d; |
| 26 | +import net.minecraft.util.math.Vec3f; |
12 | 27 | import org.jetbrains.annotations.Nullable; |
13 | 28 | import org.spongepowered.asm.mixin.Final; |
14 | 29 | import org.spongepowered.asm.mixin.Mixin; |
@@ -39,33 +54,145 @@ public abstract class MixinWorldRenderer { |
39 | 54 |
|
40 | 55 | @Shadow @Nullable private VertexBuffer darkSkyBuffer; |
41 | 56 |
|
42 | | - @Shadow protected abstract void renderEndSky(MatrixStack matrices); |
| 57 | + @Shadow @Nullable private VertexBuffer lightSkyBuffer; |
43 | 58 |
|
44 | | - @Shadow protected abstract boolean method_43788(Camera camera); |
| 59 | + @Inject(method = "renderSky", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;disableTexture()V"), cancellable = true) |
| 60 | + public void renderSky(MatrixStack matrices, Matrix4f projectionMatrix, float tickDelta, Camera preStep, boolean bl, Runnable runnable, CallbackInfo ci){ |
| 61 | + if(AxolotlClient.CONFIG.customSky.get() && SkyboxManager.getInstance().hasSkyBoxes()) { |
| 62 | + RenderSystem.disableTexture(); |
| 63 | + Vec3d vec3d = this.world.getSkyColor(this.client.gameRenderer.getCamera().getPos(), tickDelta); |
| 64 | + float f = (float) vec3d.x; |
| 65 | + float g = (float) vec3d.y; |
| 66 | + float h = (float) vec3d.z; |
| 67 | + BackgroundRenderer.setShaderFogColor(); |
| 68 | + BufferBuilder bufferBuilder = Tessellator.getInstance().getBufferBuilder(); |
| 69 | + RenderSystem.depthMask(false); |
| 70 | + RenderSystem.setShaderColor(f, g, h, 1.0F); |
| 71 | + ShaderProgram shaderProgram = RenderSystem.getShader(); |
| 72 | + this.lightSkyBuffer.bind(); |
| 73 | + this.lightSkyBuffer.setShader(matrices.peek().getPosition(), projectionMatrix, shaderProgram); |
| 74 | + VertexBuffer.unbind(); |
45 | 75 |
|
46 | | - /*@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;renderChunkDebugInfo(Lnet/minecraft/client/render/Camera;)V")) |
47 | | - public void idkRenderMySkies(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f projectionMatrix, CallbackInfo ci){ |
48 | | - if(AxolotlClient.CONFIG.customSky.get() && SkyboxManager.getInstance().hasSkyBoxes()){ |
49 | | - MinecraftClient.getInstance().getProfiler().swap("Custom Skies"); |
50 | | - //BackgroundRenderer.clearFog(); |
| 76 | + this.client.getProfiler().push("Custom Skies"); |
51 | 77 | SkyboxManager.getInstance().renderSkyboxes(matrices); |
52 | | - //MinecraftClient.getInstance().getProfiler().pop(); |
53 | | - } |
54 | | - }*/ |
55 | | - |
56 | | - @Inject(method = "renderSky", |
57 | | - at=@At(value = "HEAD"), |
58 | | - cancellable = true) |
59 | | - public void sky(MatrixStack matrices, Matrix4f projectionMatrix, float tickDelta, Camera preStep, boolean bl, Runnable runnable, CallbackInfo ci){ |
60 | | - //runnable.run(); |
61 | | - if(AxolotlClient.CONFIG.customSky.get() && SkyboxManager.getInstance().hasSkyBoxes()){ |
62 | | - MinecraftClient.getInstance().getProfiler().swap("Custom Skies"); |
63 | | - BackgroundRenderer.clearFog(); |
64 | | - SkyboxManager.getInstance().renderSkyboxes(matrices); |
65 | | - //MinecraftClient.getInstance().getProfiler().pop(); |
| 78 | + |
| 79 | + this.client.getProfiler().pop(); |
| 80 | + |
| 81 | + RenderSystem.enableBlend(); |
| 82 | + RenderSystem.defaultBlendFunc(); |
| 83 | + float[] fs = this.world.getSkyProperties().getFogColorOverride(this.world.getSkyAngle(tickDelta), tickDelta); |
| 84 | + if (fs != null) { |
| 85 | + RenderSystem.setShader(GameRenderer::getPositionColorShader); |
| 86 | + RenderSystem.disableTexture(); |
| 87 | + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); |
| 88 | + matrices.push(); |
| 89 | + matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(90.0F)); |
| 90 | + float i = MathHelper.sin(this.world.getSkyAngleRadians(tickDelta)) < 0.0F ? 180.0F : 0.0F; |
| 91 | + matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(i)); |
| 92 | + matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(90.0F)); |
| 93 | + float j = fs[0]; |
| 94 | + float k = fs[1]; |
| 95 | + float l = fs[2]; |
| 96 | + Matrix4f matrix4f = matrices.peek().getPosition(); |
| 97 | + bufferBuilder.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR); |
| 98 | + bufferBuilder.vertex(matrix4f, 0.0F, 100.0F, 0.0F).color(j, k, l, fs[3]).next(); |
| 99 | + int m = 16; |
| 100 | + |
| 101 | + for (int n = 0; n <= 16; ++n) { |
| 102 | + float o = (float) n * (float) (Math.PI * 2) / 16.0F; |
| 103 | + float p = MathHelper.sin(o); |
| 104 | + float q = MathHelper.cos(o); |
| 105 | + bufferBuilder.vertex(matrix4f, p * 120.0F, q * 120.0F, -q * 40.0F * fs[3]).color(fs[0], fs[1], fs[2], 0.0F).next(); |
| 106 | + } |
| 107 | + |
| 108 | + BufferRenderer.drawWithShader(bufferBuilder.end()); |
| 109 | + matrices.pop(); |
| 110 | + } |
| 111 | + |
| 112 | + RenderSystem.enableTexture(); |
| 113 | + RenderSystem.blendFuncSeparate(GlStateManager.class_4535.SRC_ALPHA, GlStateManager.class_4534.ONE, GlStateManager.class_4535.ONE, GlStateManager.class_4534.ZERO); |
| 114 | + |
| 115 | + |
| 116 | + if(AxolotlClient.CONFIG.showSunMoon.get()) { |
| 117 | + matrices.push(); |
| 118 | + float i = 1.0F - this.world.getRainGradient(tickDelta); |
| 119 | + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, i); |
| 120 | + matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-90.0F)); |
| 121 | + matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(this.world.getSkyAngle(tickDelta) * 360.0F)); |
| 122 | + Matrix4f matrix4f2 = matrices.peek().getPosition(); |
| 123 | + float k = 30.0F; |
| 124 | + RenderSystem.setShader(GameRenderer::getPositionTexShader); |
| 125 | + RenderSystem.setShaderTexture(0, SUN); |
| 126 | + bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE); |
| 127 | + bufferBuilder.vertex(matrix4f2, -k, 100.0F, -k).uv(0.0F, 0.0F).next(); |
| 128 | + bufferBuilder.vertex(matrix4f2, k, 100.0F, -k).uv(1.0F, 0.0F).next(); |
| 129 | + bufferBuilder.vertex(matrix4f2, k, 100.0F, k).uv(1.0F, 1.0F).next(); |
| 130 | + bufferBuilder.vertex(matrix4f2, -k, 100.0F, k).uv(0.0F, 1.0F).next(); |
| 131 | + BufferRenderer.drawWithShader(bufferBuilder.end()); |
| 132 | + k = 20.0F; |
| 133 | + RenderSystem.setShaderTexture(0, MOON_PHASES); |
| 134 | + int r = this.world.getMoonPhase(); |
| 135 | + int s = r % 4; |
| 136 | + int m = r / 4 % 2; |
| 137 | + float t = (float) (s) / 4.0F; |
| 138 | + float o = (float) (m) / 2.0F; |
| 139 | + float p = (float) (s + 1) / 4.0F; |
| 140 | + float q = (float) (m + 1) / 2.0F; |
| 141 | + bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE); |
| 142 | + bufferBuilder.vertex(matrix4f2, -k, -100.0F, k).uv(p, q).next(); |
| 143 | + bufferBuilder.vertex(matrix4f2, k, -100.0F, k).uv(t, q).next(); |
| 144 | + bufferBuilder.vertex(matrix4f2, k, -100.0F, -k).uv(t, o).next(); |
| 145 | + bufferBuilder.vertex(matrix4f2, -k, -100.0F, -k).uv(p, o).next(); |
| 146 | + BufferRenderer.drawWithShader(bufferBuilder.end()); |
| 147 | + |
| 148 | + |
| 149 | + RenderSystem.disableTexture(); |
| 150 | + float u = this.world.getStarBrightness(tickDelta) * i; |
| 151 | + if (u > 0.0F) { |
| 152 | + RenderSystem.setShaderColor(u, u, u, u); |
| 153 | + BackgroundRenderer.clearFog(); |
| 154 | + this.starsBuffer.bind(); |
| 155 | + this.starsBuffer.setShader(matrices.peek().getPosition(), projectionMatrix, GameRenderer.getPositionShader()); |
| 156 | + VertexBuffer.unbind(); |
| 157 | + runnable.run(); |
| 158 | + } |
| 159 | + |
| 160 | + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); |
| 161 | + RenderSystem.disableBlend(); |
| 162 | + matrices.pop(); |
| 163 | + } |
| 164 | + RenderSystem.disableTexture(); |
| 165 | + RenderSystem.setShaderColor(0.0F, 0.0F, 0.0F, 1.0F); |
| 166 | + double d = this.client.player.getCameraPosVec(tickDelta).y - this.world.getLevelProperties().getSkyDarknessHeight(this.world); |
| 167 | + if (d < 0.0) { |
| 168 | + matrices.push(); |
| 169 | + matrices.translate(0.0, 12.0, 0.0); |
| 170 | + this.darkSkyBuffer.bind(); |
| 171 | + this.darkSkyBuffer.setShader(matrices.peek().getPosition(), projectionMatrix, shaderProgram); |
| 172 | + VertexBuffer.unbind(); |
| 173 | + matrices.pop(); |
| 174 | + } |
| 175 | + |
| 176 | + if (this.world.getSkyProperties().isAlternateSkyColor()) { |
| 177 | + RenderSystem.setShaderColor(f * 0.2F + 0.04F, g * 0.2F + 0.04F, h * 0.6F + 0.1F, 1.0F); |
| 178 | + } else { |
| 179 | + RenderSystem.setShaderColor(f, g, h, 1.0F); |
| 180 | + } |
| 181 | + |
| 182 | + RenderSystem.enableTexture(); |
| 183 | + RenderSystem.depthMask(true); |
66 | 184 | ci.cancel(); |
67 | 185 | } |
68 | | - } |
| 186 | + } |
| 187 | + |
| 188 | + @Redirect(method = "renderClouds(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/util/math/Matrix4f;FDDD)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/SkyProperties;getCloudsHeight()F")) |
| 189 | + public float customCloudHeight(SkyProperties instance){ |
| 190 | + |
| 191 | + if(AxolotlClient.CONFIG.customCloudHeight.get()) { |
| 192 | + return AxolotlClient.CONFIG.cloudHeight.get(); |
| 193 | + } |
| 194 | + return instance.getCloudsHeight(); |
| 195 | + } |
69 | 196 |
|
70 | 197 | /*@ModifyArg(method = "method_1380", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glLineWidth(F)V")) |
71 | 198 | public float OutlineWidth(float width){ |
@@ -101,11 +228,4 @@ public void customOutlineColor(Args args){ |
101 | 228 | } |
102 | 229 | } |
103 | 230 | } |
104 | | - |
105 | | - @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/BackgroundRenderer;applyFog(Lnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/BackgroundRenderer$FogType;FZF)V")) |
106 | | - public void noFog(Camera camera, BackgroundRenderer.FogType fogType, float viewDistance, boolean thickFog, float tickDelta){ |
107 | | - if(!AxolotlClient.CONFIG.customSky.get() || !SkyboxManager.getInstance().hasSkyBoxes()){ |
108 | | - BackgroundRenderer.applyFog(camera, fogType, viewDistance, thickFog, tickDelta); |
109 | | - } |
110 | | - } |
111 | 231 | } |
0 commit comments