Skip to content

Commit

Permalink
Simplified event
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte authored and Technici4n committed Jan 9, 2025
1 parent 02a1ea2 commit f62e417
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 56 deletions.
8 changes: 4 additions & 4 deletions patches/com/mojang/blaze3d/pipeline/MainTarget.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
public MainTarget(int p_166137_, int p_166138_) {
- super(true);
- this.createFrameBuffer(p_166137_, p_166138_);
+ this(net.neoforged.neoforge.client.ClientHooks.configureMainRenderTarget(true, p_166137_, p_166138_));
+ this(p_166137_, p_166138_, false);
+ }
+
+ private MainTarget(net.neoforged.neoforge.client.event.ConfigureMainRenderTargetEvent e) {
+ super(e.useDepth(), e.useStencil());
+ this.createFrameBuffer(e.width(), e.height());
+ public MainTarget(int width, int height, boolean useStencil) {
+ super(true, useStencil);
+ this.createFrameBuffer(width, height);
}

private void createFrameBuffer(int p_166142_, int p_166143_) {
Expand Down
3 changes: 2 additions & 1 deletion patches/net/minecraft/client/Minecraft.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
this.keyboardHandler = new KeyboardHandler(this);
- this.keyboardHandler.setup(this.window.getWindow());
RenderSystem.initRenderer(this.options.glDebugVerbosity, false);
- this.mainRenderTarget = new MainTarget(this.window.getWidth(), this.window.getHeight());
+ net.neoforged.neoforge.client.loading.ClientModLoader.begin(this);
this.mainRenderTarget = new MainTarget(this.window.getWidth(), this.window.getHeight());
+ this.mainRenderTarget = net.neoforged.neoforge.client.ClientHooks.createMainRenderTarget(this.window.getWidth(), this.window.getHeight());
this.mainRenderTarget.setClearColor(0.0F, 0.0F, 0.0F, 0.0F);
this.mainRenderTarget.clear();
this.resourceManager = new ReloadableResourceManager(PackType.CLIENT_RESOURCES);
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/net/neoforged/neoforge/client/ClientHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableMap;
import com.mojang.blaze3d.framegraph.FrameGraphBuilder;
import com.mojang.blaze3d.pipeline.MainTarget;
import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.resource.RenderTargetDescriptor;
Expand Down Expand Up @@ -1101,9 +1102,9 @@ public static FrameGraphSetupEvent fireFrameGraphSetup(FrameGraphBuilder builder
return NeoForge.EVENT_BUS.post(new FrameGraphSetupEvent(builder, targets, renderTargetDescriptor, frustum, camera, modelViewMatrix, projectionMatrix, deltaTracker, profiler));
}

public static ConfigureMainRenderTargetEvent configureMainRenderTarget(boolean useDepth, int width, int height) {
var e = new ConfigureMainRenderTargetEvent(useDepth, width, height);
ModLoader.postEvent(e);
return e;
@ApiStatus.Internal
public static MainTarget createMainRenderTarget(int width, int height) {
var e = ModLoader.postEventWithReturn(new ConfigureMainRenderTargetEvent());
return new MainTarget(width, height, e.useStencil());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,30 @@
package net.neoforged.neoforge.client.event;

import com.mojang.blaze3d.pipeline.MainTarget;
import com.mojang.blaze3d.pipeline.RenderTarget;
import net.neoforged.bus.api.Event;
import net.neoforged.bus.api.ICancellableEvent;
import net.neoforged.fml.LogicalSide;
import net.neoforged.fml.event.IModBusEvent;
import org.jetbrains.annotations.ApiStatus;

/**
* Fired when configuring the main {@linkplain RenderTarget render target}.
* <p>
* This event fires during startup when the {@link MainTarget} is constructed.
* Fired when configuring the {@linkplain MainTarget main render target} during startup.
* <p>
* This event is not {@linkplain ICancellableEvent cancellable}.
* <p>
* This event is fired on the mod-speciffic event bus, only on the {@linkplain LogicalSide#CLIENT logical client}.
* This event is fired on the mod-specific event bus, only on the {@linkplain LogicalSide#CLIENT logical client}.
*/
public class ConfigureMainRenderTargetEvent extends Event implements IModBusEvent {
private final boolean useDepth;
private boolean useStencil;

private final int width;
private final int height;

@ApiStatus.Internal
public ConfigureMainRenderTargetEvent(boolean useDepth, int width, int height) {
this.useDepth = useDepth;
this.useStencil = false;

this.width = width;
this.height = height;
}

/**
* Returns whether the depth buffer is enabled.
*
* @return <code>true</code>, if the depth buffer is enabled, or <code>false</code> otherwise.
*/
public boolean useDepth() {
return this.useDepth;
}

/**
* Returns whether the stencil buffer is enabled.
* Returns whether enabling the stencil buffer on the main render target was requested.
*
* @return <code>true</code>, if the stencil buffer is enabled, or <code>false</code> otherwise.
*/
public boolean useStencil() {
return this.useStencil;
}

/**
* Returns the preferred width of the framebuffer.
*
* @return The width, in pixels, to attempt to use for the framebuffer.
*/
public int width() {
return this.width;
}

/**
* Returns the preferred height of the framebuffer.
*
* @return The height, in pixels, to attempt to use for the framebuffer.
*/
public int height() {
return this.height;
}

/**
* Enable the stencil buffer for the main render target.
*
Expand Down

0 comments on commit f62e417

Please sign in to comment.