More info in RenderLayerEvent

This commit is contained in:
Jozufozu 2021-07-28 14:18:24 -07:00
parent 7f58d51017
commit eded055be8
2 changed files with 26 additions and 8 deletions

View File

@ -2,9 +2,12 @@ package com.jozufozu.flywheel.event;
import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.state.RenderLayer;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.RenderTypeBuffers;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraftforge.eventbus.api.Event;
@ -12,16 +15,26 @@ import net.minecraftforge.eventbus.api.Event;
public class RenderLayerEvent extends Event {
private final ClientWorld world;
public final RenderType type;
public final MatrixStack stack;
public final Matrix4f viewProjection;
public final RenderTypeBuffers buffers;
public final double camX;
public final double camY;
public final double camZ;
public final RenderLayer layer;
public RenderLayerEvent(ClientWorld world, RenderType type, Matrix4f viewProjection, double camX, double camY, double camZ) {
public RenderLayerEvent(ClientWorld world, RenderType type, MatrixStack stack, RenderTypeBuffers buffers, double camX, double camY, double camZ) {
this.world = world;
this.type = type;
this.viewProjection = viewProjection;
this.stack = stack;
viewProjection = stack.last()
.pose()
.copy();
viewProjection.multiplyBackward(Backend.getInstance()
.getProjectionMatrix());
this.buffers = buffers;
this.camX = camX;
this.camY = camY;
this.camZ = camZ;

View File

@ -1,6 +1,7 @@
package com.jozufozu.flywheel.mixin;
import org.lwjgl.opengl.GL20;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@ -21,6 +22,7 @@ import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.RenderTypeBuffers;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos;
@ -37,6 +39,10 @@ public class RenderHooksMixin {
@Shadow
private ClientWorld level;
@Shadow
@Final
private RenderTypeBuffers renderBuffers;
@Inject(at = @At(value = "INVOKE", target = "net.minecraft.client.renderer.WorldRenderer.compileChunksUntil(J)V"), method = "renderLevel")
private void setupFrame(MatrixStack stack, float p_228426_2_, long p_228426_3_, boolean p_228426_5_, ActiveRenderInfo info, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f p_228426_9_, CallbackInfo ci) {
MinecraftForge.EVENT_BUS.post(new BeginFrameEvent(level, stack, info, gameRenderer, lightTexture));
@ -49,15 +55,14 @@ public class RenderHooksMixin {
*/
@Inject(at = @At("TAIL"), method = "renderChunkLayer")
private void renderLayer(RenderType type, MatrixStack stack, double camX, double camY, double camZ, CallbackInfo ci) {
Matrix4f view = stack.last()
.pose();
Matrix4f viewProjection = view.copy();
viewProjection.multiplyBackward(Backend.getInstance()
.getProjectionMatrix());
MinecraftForge.EVENT_BUS.post(new RenderLayerEvent(level, type, viewProjection, camX, camY, camZ));
RenderTypeBuffers renderBuffers = this.renderBuffers;
MinecraftForge.EVENT_BUS.post(new RenderLayerEvent(level, type, stack, renderBuffers, camX, camY, camZ));
if (!OptifineHandler.usingShaders()) GL20.glUseProgram(0);
renderBuffers.bufferSource().endBatch(type);
}
@Inject(at = @At("TAIL"), method = "allChanged")