forked from Mumfrey/WorldEditCUI
-
Notifications
You must be signed in to change notification settings - Fork 69
Add renderer mixin #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add renderer mixin #146
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6a4a639
Minor changes
beemerwt 4b6a041
Add render mixin
beemerwt 52db1f1
Updated keybinds to new namespace standard
beemerwt a4ff763
Added refmap for loom
beemerwt aaa1956
Fixed unnecessary warnings
beemerwt c5708d8
Implement START callback for consistency
beemerwt 8bae962
Removed 7.3.12 from breaking
beemerwt 12a894f
Formatting and javadoc comments
beemerwt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...-fabric/src/main/java/org/enginehub/worldeditcui/callback/BlockOutlineRenderCallback.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright (c) 2011-2024 WorldEditCUI team and contributors | ||
| * | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
| package org.enginehub.worldeditcui.callback; | ||
|
|
||
| import com.mojang.blaze3d.buffers.GpuBufferSlice; | ||
| import com.mojang.blaze3d.vertex.PoseStack; | ||
| import com.mojang.blaze3d.vertex.VertexConsumer; | ||
| import net.fabricmc.fabric.api.event.Event; | ||
| import net.fabricmc.fabric.api.event.EventFactory; | ||
| import net.minecraft.client.Camera; | ||
| import net.minecraft.client.Minecraft; | ||
| import net.minecraft.client.renderer.state.BlockOutlineRenderState; | ||
|
|
||
| public interface BlockOutlineRenderCallback { | ||
| record Context( | ||
| Minecraft client, | ||
| Camera camera, | ||
| PoseStack poseStack, | ||
| GpuBufferSlice projectionMatrixBuffer, | ||
| VertexConsumer vertexConsumer, | ||
| double camX, double camY, double camZ, | ||
| BlockOutlineRenderState state | ||
| ) {} | ||
|
|
||
| /** | ||
| * Return true to cancel vanilla outline (replace it), false to let vanilla draw after you. | ||
| */ | ||
| boolean render(Context ctx); | ||
|
|
||
| Event<BlockOutlineRenderCallback> EVENT = | ||
| EventFactory.createArrayBacked(BlockOutlineRenderCallback.class, cbs -> ctx -> { | ||
| boolean cancel = false; | ||
| for (var cb : cbs) cancel |= cb.render(ctx); | ||
| return cancel; | ||
| }); | ||
| } | ||
|
|
36 changes: 36 additions & 0 deletions
36
...editcui-fabric/src/main/java/org/enginehub/worldeditcui/callback/WorldRenderCallback.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright (c) 2011-2024 WorldEditCUI team and contributors | ||
| * | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
| package org.enginehub.worldeditcui.callback; | ||
|
|
||
| import net.fabricmc.fabric.api.event.Event; | ||
| import net.fabricmc.fabric.api.event.EventFactory; | ||
| import org.enginehub.worldeditcui.render.WecuiRenderContext; | ||
|
|
||
| /** | ||
| * A re-implementation of the old world render events for Fabric. | ||
| * Temporary until Fabric finishes their new rendering API. | ||
| */ | ||
| public interface WorldRenderCallback { | ||
| void render(WecuiRenderContext ctx); | ||
|
|
||
| /** | ||
| * Fires at the end of world rendering, after all other rendering is complete. | ||
| */ | ||
| Event<WorldRenderCallback> LAST = EventFactory.createArrayBacked(WorldRenderCallback.class, cbs -> ctx -> { | ||
| for (var cb : cbs) cb.render(ctx); | ||
| }); | ||
|
|
||
| /** | ||
| * Fires immediately after the translucent rendering pass. | ||
| */ | ||
| Event<WorldRenderCallback> AFTER_TRANSLUCENT = EventFactory.createArrayBacked(WorldRenderCallback.class, cbs -> ctx -> { | ||
| for (var cb : cbs) cb.render(ctx); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
worldeditcui-fabric/src/main/java/org/enginehub/worldeditcui/mixin/LevelRendererMixin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright (c) 2011-2024 WorldEditCUI team and contributors | ||
| * | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
| package org.enginehub.worldeditcui.mixin; | ||
|
|
||
| import com.mojang.blaze3d.buffers.GpuBufferSlice; | ||
| import com.mojang.blaze3d.resource.GraphicsResourceAllocator; | ||
| import com.mojang.blaze3d.vertex.PoseStack; | ||
| import net.minecraft.client.Camera; | ||
| import net.minecraft.client.DeltaTracker; | ||
| import net.minecraft.client.Minecraft; | ||
| import net.minecraft.client.renderer.LevelRenderer; | ||
| import org.enginehub.worldeditcui.callback.WorldRenderCallback; | ||
| import org.enginehub.worldeditcui.render.WecuiRenderContext; | ||
| import org.joml.Matrix4f; | ||
| import org.joml.Vector4f; | ||
| 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; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
|
||
| /** | ||
| * Mixin to LevelRenderer to inject our world render callbacks. | ||
| * Temporary until Fabric finishes their new rendering API. | ||
| */ | ||
| @Mixin(LevelRenderer.class) | ||
| public abstract class LevelRendererMixin { | ||
| @Shadow @Final private Minecraft minecraft; | ||
|
|
||
| // LAST (old LAST) | ||
| @Inject(method = "renderLevel", at = @At("TAIL")) | ||
| private void wecui$last( | ||
| GraphicsResourceAllocator gfx, DeltaTracker delta, boolean renderBlockOutline, | ||
| Camera camera, Matrix4f modelView, Matrix4f projection, Matrix4f inverseProjection, | ||
| GpuBufferSlice slice, Vector4f clearColor, boolean renderSky, CallbackInfo ci | ||
| ) { | ||
| PoseStack pose = new PoseStack(); | ||
| pose.last().pose().set(modelView); | ||
| WorldRenderCallback.LAST.invoker() | ||
| .render(new WecuiRenderContext(this.minecraft, camera, delta, pose, projection)); | ||
| } | ||
|
|
||
| // AFTER_TRANSLUCENT — fires immediately after translucent pass queued/executed | ||
| @Inject( | ||
| method = "renderLevel", | ||
| at = @At( | ||
| value = "INVOKE", | ||
| target = "Lnet/minecraft/client/renderer/LevelRenderer;addParticlesPass(Lcom/mojang/blaze3d/framegraph/FrameGraphBuilder;Lcom/mojang/blaze3d/buffers/GpuBufferSlice;)V" | ||
| ) | ||
| ) | ||
| private void wecui$afterTranslucent( | ||
| GraphicsResourceAllocator gfx, DeltaTracker delta, boolean renderBlockOutline, | ||
| Camera camera, Matrix4f modelView, Matrix4f projection, Matrix4f inverseProjection, | ||
| GpuBufferSlice slice, Vector4f clearColor, boolean renderSky, | ||
| CallbackInfo ci | ||
| ) { | ||
| var pose = new PoseStack(); | ||
| pose.last().pose().set(modelView); | ||
| WorldRenderCallback.AFTER_TRANSLUCENT.invoker() | ||
| .render(new WecuiRenderContext(this.minecraft, camera, delta, pose, projection)); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.