From 2c4d650639e1319b64f212c17d62bee8eb9dc3a9 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 11 May 2021 12:34:38 -0700 Subject: [PATCH] Organize the mixins --- .../mixin/ChromaticProjectorHooksMixin.java | 35 +++++++++ .../mixin/StoreProjectionMatrixMixin.java | 74 ------------------- .../CancelTileEntityRenderMixin.java | 2 +- .../{ => flywheel}/FogColorTrackerMixin.java | 2 +- .../{ => flywheel}/RenderHooksMixin.java | 18 +---- .../{ => flywheel}/ShaderCloseMixin.java | 2 +- .../flywheel/StoreProjectionMatrixMixin.java | 37 ++++++++++ .../mixin/{ => flywheel}/TileRemoveMixin.java | 2 +- .../{ => flywheel}/TileWorldHookMixin.java | 2 +- .../light}/LightUpdateMixin.java | 2 +- .../light}/NetworkLightUpdateMixin.java | 2 +- src/main/resources/create.mixins.json | 19 ++--- 12 files changed, 90 insertions(+), 107 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/ChromaticProjectorHooksMixin.java delete mode 100644 src/main/java/com/simibubi/create/foundation/mixin/StoreProjectionMatrixMixin.java rename src/main/java/com/simibubi/create/foundation/mixin/{ => flywheel}/CancelTileEntityRenderMixin.java (96%) rename src/main/java/com/simibubi/create/foundation/mixin/{ => flywheel}/FogColorTrackerMixin.java (91%) rename src/main/java/com/simibubi/create/foundation/mixin/{ => flywheel}/RenderHooksMixin.java (75%) rename src/main/java/com/simibubi/create/foundation/mixin/{ => flywheel}/ShaderCloseMixin.java (94%) create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/flywheel/StoreProjectionMatrixMixin.java rename src/main/java/com/simibubi/create/foundation/mixin/{ => flywheel}/TileRemoveMixin.java (93%) rename src/main/java/com/simibubi/create/foundation/mixin/{ => flywheel}/TileWorldHookMixin.java (96%) rename src/main/java/com/simibubi/create/foundation/mixin/{ => flywheel/light}/LightUpdateMixin.java (96%) rename src/main/java/com/simibubi/create/foundation/mixin/{ => flywheel/light}/NetworkLightUpdateMixin.java (95%) diff --git a/src/main/java/com/simibubi/create/foundation/mixin/ChromaticProjectorHooksMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/ChromaticProjectorHooksMixin.java new file mode 100644 index 000000000..0d9669855 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/ChromaticProjectorHooksMixin.java @@ -0,0 +1,35 @@ +package com.simibubi.create.foundation.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.platform.GlStateManager; +import com.simibubi.create.foundation.render.effects.EffectsHandler; + +import net.minecraft.client.renderer.ActiveRenderInfo; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.util.math.vector.Matrix4f; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +@Mixin(WorldRenderer.class) +public class ChromaticProjectorHooksMixin { + + @Inject(method = "render", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/client/shader/ShaderGroup;render(F)V")) + private void disableTransparencyShaderDepth(MatrixStack p_228426_1_, float p_228426_2_, long p_228426_3_, boolean p_228426_5_, ActiveRenderInfo p_228426_6_, GameRenderer p_228426_7_, LightTexture p_228426_8_, Matrix4f p_228426_9_, CallbackInfo ci) { + GlStateManager.depthMask(false); + } + + @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/WorldRenderer;renderChunkDebugInfo(Lnet/minecraft/client/renderer/ActiveRenderInfo;)V")) + private void applyFilters(MatrixStack stack, float p_228426_2_, long p_228426_3_, boolean p_228426_5_, ActiveRenderInfo p_228426_6_, GameRenderer p_228426_7_, LightTexture p_228426_8_, Matrix4f p_228426_9_, CallbackInfo ci) { + EffectsHandler instance = EffectsHandler.getInstance(); + if (instance != null) + instance.render(stack.peek().getModel()); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/StoreProjectionMatrixMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/StoreProjectionMatrixMixin.java deleted file mode 100644 index 40c1b607c..000000000 --- a/src/main/java/com/simibubi/create/foundation/mixin/StoreProjectionMatrixMixin.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.simibubi.create.foundation.mixin; - -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.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import com.jozufozu.flywheel.backend.Backend; -import com.mojang.blaze3d.matrix.MatrixStack; -import com.simibubi.create.foundation.render.effects.EffectsHandler; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.ActiveRenderInfo; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.util.math.vector.Matrix4f; - -@Mixin(GameRenderer.class) -public abstract class StoreProjectionMatrixMixin { - - @Shadow - private float cameraZoom; - @Shadow - private float zoomX; - @Shadow - private float zoomY; - - @Shadow - public abstract double getFOVModifier(ActiveRenderInfo p_215311_1_, float p_215311_2_, boolean p_215311_3_); - - @Shadow - @Final - private Minecraft mc; - @Shadow - private float farPlaneDistance; - - @Unique - private boolean shouldCopy = false; - - /** - * We only want to copy the projection matrix if it is going to be used to render the world. - * We don't care about the mat for your hand. - */ - @Inject(method = "renderWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GameRenderer;loadProjectionMatrix(Lnet/minecraft/util/math/vector/Matrix4f;)V")) - private void projectionMatrixReady(float p_228378_1_, long p_228378_2_, MatrixStack p_228378_4_, CallbackInfo ci) { - shouldCopy = true; - } - - @Inject(method = "loadProjectionMatrix", at = @At("TAIL")) - private void onProjectionMatrixLoad(Matrix4f projection, CallbackInfo ci) { - if (shouldCopy) { - Backend.setProjectionMatrix(projection.copy()); - shouldCopy = false; - } - } - - @Inject(method = "getBasicProjectionMatrix", - at = @At("HEAD"), - cancellable = true) - private void overrideNearPlane(ActiveRenderInfo p_228382_1_, float p_228382_2_, boolean p_228382_3_, CallbackInfoReturnable cir) { - MatrixStack matrixstack = new MatrixStack(); - matrixstack.peek().getModel().loadIdentity(); - if (this.cameraZoom != 1.0F) { - matrixstack.translate((double) this.zoomX, (double) (-this.zoomY), 0.0D); - matrixstack.scale(this.cameraZoom, this.cameraZoom, 1.0F); - } - - matrixstack.peek().getModel().multiply(Matrix4f.perspective(this.getFOVModifier(p_228382_1_, p_228382_2_, p_228382_3_), (float) this.mc.getWindow().getFramebufferWidth() / (float) this.mc.getWindow().getFramebufferHeight(), EffectsHandler.getNearPlane(), EffectsHandler.getFarPlane())); - cir.setReturnValue(matrixstack.peek().getModel()); - } -} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/CancelTileEntityRenderMixin.java similarity index 96% rename from src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java rename to src/main/java/com/simibubi/create/foundation/mixin/flywheel/CancelTileEntityRenderMixin.java index d1efec013..4f1c95202 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/CancelTileEntityRenderMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/CancelTileEntityRenderMixin.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.mixin; +package com.simibubi.create.foundation.mixin.flywheel; import java.util.List; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/FogColorTrackerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/FogColorTrackerMixin.java similarity index 91% rename from src/main/java/com/simibubi/create/foundation/mixin/FogColorTrackerMixin.java rename to src/main/java/com/simibubi/create/foundation/mixin/flywheel/FogColorTrackerMixin.java index d3e69ecf1..87682d8f4 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/FogColorTrackerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/FogColorTrackerMixin.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.mixin; +package com.simibubi.create.foundation.mixin.flywheel; import org.lwjgl.opengl.GL11; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/RenderHooksMixin.java similarity index 75% rename from src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java rename to src/main/java/com/simibubi/create/foundation/mixin/flywheel/RenderHooksMixin.java index c1be3a2eb..e115f833e 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/RenderHooksMixin.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.mixin; +package com.simibubi.create.foundation.mixin.flywheel; import org.lwjgl.opengl.GL20; import org.spongepowered.asm.mixin.Mixin; @@ -10,8 +10,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.OptifineHandler; import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.platform.GlStateManager; -import com.simibubi.create.foundation.render.effects.EffectsHandler; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.ActiveRenderInfo; @@ -92,20 +90,6 @@ public class RenderHooksMixin { GL20.glUseProgram(0); } - // Effects system - - @Inject(method = "render", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/client/shader/ShaderGroup;render(F)V")) - private void disableTransparencyShaderDepth(MatrixStack p_228426_1_, float p_228426_2_, long p_228426_3_, boolean p_228426_5_, ActiveRenderInfo p_228426_6_, GameRenderer p_228426_7_, LightTexture p_228426_8_, Matrix4f p_228426_9_, CallbackInfo ci) { - GlStateManager.depthMask(false); - } - - @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/WorldRenderer;renderChunkDebugInfo(Lnet/minecraft/client/renderer/ActiveRenderInfo;)V")) - private void applyFilters(MatrixStack stack, float p_228426_2_, long p_228426_3_, boolean p_228426_5_, ActiveRenderInfo p_228426_6_, GameRenderer p_228426_7_, LightTexture p_228426_8_, Matrix4f p_228426_9_, CallbackInfo ci) { - EffectsHandler instance = EffectsHandler.getInstance(); - if (instance != null) - instance.render(stack.peek().getModel()); - } - // Instancing @Inject(at = @At("TAIL"), method = "scheduleBlockRerenderIfNeeded") diff --git a/src/main/java/com/simibubi/create/foundation/mixin/ShaderCloseMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/ShaderCloseMixin.java similarity index 94% rename from src/main/java/com/simibubi/create/foundation/mixin/ShaderCloseMixin.java rename to src/main/java/com/simibubi/create/foundation/mixin/flywheel/ShaderCloseMixin.java index 8da970608..cb4f05aa1 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/ShaderCloseMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/ShaderCloseMixin.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.mixin; +package com.simibubi.create.foundation.mixin.flywheel; import javax.annotation.Nullable; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/flywheel/StoreProjectionMatrixMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/StoreProjectionMatrixMixin.java new file mode 100644 index 000000000..cbe203a74 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/StoreProjectionMatrixMixin.java @@ -0,0 +1,37 @@ +package com.simibubi.create.foundation.mixin.flywheel; + +import org.spongepowered.asm.mixin.Mixin; +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.callback.CallbackInfo; + +import com.jozufozu.flywheel.backend.Backend; +import com.mojang.blaze3d.matrix.MatrixStack; + +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.util.math.vector.Matrix4f; + +@Mixin(GameRenderer.class) +public abstract class StoreProjectionMatrixMixin { + + @Unique + private boolean shouldCopy = false; + + /** + * We only want to copy the projection matrix if it is going to be used to render the world. + * We don't care about the mat for your hand. + */ + @Inject(method = "renderWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GameRenderer;loadProjectionMatrix(Lnet/minecraft/util/math/vector/Matrix4f;)V")) + private void projectionMatrixReady(float p_228378_1_, long p_228378_2_, MatrixStack p_228378_4_, CallbackInfo ci) { + shouldCopy = true; + } + + @Inject(method = "loadProjectionMatrix", at = @At("TAIL")) + private void onProjectionMatrixLoad(Matrix4f projection, CallbackInfo ci) { + if (shouldCopy) { + Backend.setProjectionMatrix(projection.copy()); + shouldCopy = false; + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/TileRemoveMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileRemoveMixin.java similarity index 93% rename from src/main/java/com/simibubi/create/foundation/mixin/TileRemoveMixin.java rename to src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileRemoveMixin.java index 4de24590a..66a6960ae 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/TileRemoveMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileRemoveMixin.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.mixin; +package com.simibubi.create.foundation.mixin.flywheel; import javax.annotation.Nullable; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/TileWorldHookMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileWorldHookMixin.java similarity index 96% rename from src/main/java/com/simibubi/create/foundation/mixin/TileWorldHookMixin.java rename to src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileWorldHookMixin.java index b39f512ea..fdf4a4705 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/TileWorldHookMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileWorldHookMixin.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.mixin; +package com.simibubi.create.foundation.mixin.flywheel; import java.util.Set; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/LightUpdateMixin.java similarity index 96% rename from src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java rename to src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/LightUpdateMixin.java index 1d1c99757..7319e0a96 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/LightUpdateMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/LightUpdateMixin.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.mixin; +package com.simibubi.create.foundation.mixin.flywheel.light; import java.util.Map; diff --git a/src/main/java/com/simibubi/create/foundation/mixin/NetworkLightUpdateMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/NetworkLightUpdateMixin.java similarity index 95% rename from src/main/java/com/simibubi/create/foundation/mixin/NetworkLightUpdateMixin.java rename to src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/NetworkLightUpdateMixin.java index 4b1d899a8..2f65f4ae9 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/NetworkLightUpdateMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/NetworkLightUpdateMixin.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.mixin; +package com.simibubi.create.foundation.mixin.flywheel.light; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 3aae131af..c6a6b7881 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -6,16 +6,17 @@ "refmap": "create.refmap.json", "client": [ "BreakProgressMixin", - "CancelTileEntityRenderMixin", + "ChromaticProjectorHooksMixin", "EntityContraptionInteractionMixin", - "FogColorTrackerMixin", - "LightUpdateMixin", - "NetworkLightUpdateMixin", - "RenderHooksMixin", - "ShaderCloseMixin", - "StoreProjectionMatrixMixin", - "TileRemoveMixin", - "TileWorldHookMixin" + "flywheel.CancelTileEntityRenderMixin", + "flywheel.FogColorTrackerMixin", + "flywheel.RenderHooksMixin", + "flywheel.ShaderCloseMixin", + "flywheel.StoreProjectionMatrixMixin", + "flywheel.TileRemoveMixin", + "flywheel.TileWorldHookMixin", + "flywheel.light.LightUpdateMixin", + "flywheel.light.NetworkLightUpdateMixin" ], "injectors": { "defaultRequire": 1