Organize the mixins

This commit is contained in:
JozsefA 2021-05-11 12:34:38 -07:00
parent 916b187aa8
commit 2c4d650639
12 changed files with 90 additions and 107 deletions

View file

@ -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());
}
}

View file

@ -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<Matrix4f> 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());
}
}

View file

@ -1,4 +1,4 @@
package com.simibubi.create.foundation.mixin; package com.simibubi.create.foundation.mixin.flywheel;
import java.util.List; import java.util.List;

View file

@ -1,4 +1,4 @@
package com.simibubi.create.foundation.mixin; package com.simibubi.create.foundation.mixin.flywheel;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;

View file

@ -1,4 +1,4 @@
package com.simibubi.create.foundation.mixin; package com.simibubi.create.foundation.mixin.flywheel;
import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL20;
import org.spongepowered.asm.mixin.Mixin; 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.Backend;
import com.jozufozu.flywheel.backend.OptifineHandler; import com.jozufozu.flywheel.backend.OptifineHandler;
import com.mojang.blaze3d.matrix.MatrixStack; 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.block.BlockState;
import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.ActiveRenderInfo;
@ -92,20 +90,6 @@ public class RenderHooksMixin {
GL20.glUseProgram(0); 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 // Instancing
@Inject(at = @At("TAIL"), method = "scheduleBlockRerenderIfNeeded") @Inject(at = @At("TAIL"), method = "scheduleBlockRerenderIfNeeded")

View file

@ -1,4 +1,4 @@
package com.simibubi.create.foundation.mixin; package com.simibubi.create.foundation.mixin.flywheel;
import javax.annotation.Nullable; import javax.annotation.Nullable;

View file

@ -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;
}
}
}

View file

@ -1,4 +1,4 @@
package com.simibubi.create.foundation.mixin; package com.simibubi.create.foundation.mixin.flywheel;
import javax.annotation.Nullable; import javax.annotation.Nullable;

View file

@ -1,4 +1,4 @@
package com.simibubi.create.foundation.mixin; package com.simibubi.create.foundation.mixin.flywheel;
import java.util.Set; import java.util.Set;

View file

@ -1,4 +1,4 @@
package com.simibubi.create.foundation.mixin; package com.simibubi.create.foundation.mixin.flywheel.light;
import java.util.Map; import java.util.Map;

View file

@ -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.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;

View file

@ -6,16 +6,17 @@
"refmap": "create.refmap.json", "refmap": "create.refmap.json",
"client": [ "client": [
"BreakProgressMixin", "BreakProgressMixin",
"CancelTileEntityRenderMixin", "ChromaticProjectorHooksMixin",
"EntityContraptionInteractionMixin", "EntityContraptionInteractionMixin",
"FogColorTrackerMixin", "flywheel.CancelTileEntityRenderMixin",
"LightUpdateMixin", "flywheel.FogColorTrackerMixin",
"NetworkLightUpdateMixin", "flywheel.RenderHooksMixin",
"RenderHooksMixin", "flywheel.ShaderCloseMixin",
"ShaderCloseMixin", "flywheel.StoreProjectionMatrixMixin",
"StoreProjectionMatrixMixin", "flywheel.TileRemoveMixin",
"TileRemoveMixin", "flywheel.TileWorldHookMixin",
"TileWorldHookMixin" "flywheel.light.LightUpdateMixin",
"flywheel.light.NetworkLightUpdateMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1