mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 19:59:42 +00:00
Add event for adding framepasses (#10612)
This commit is contained in:
9 files changed
+205
No files matched your search
@@ -884,4 +884,8 @@ public class ForgeHooksClient {
|
||||
return parent.compute(p_395456_);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addFramePass(ResourceLocation rl, FramePassManager.PassDefinition definition) {
|
||||
FramePassManager.addPass(rl, definition);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
package net.minecraftforge.client;
|
||||
|
||||
import com.mojang.blaze3d.framegraph.FrameGraphBuilder;
|
||||
import com.mojang.blaze3d.framegraph.FramePass;
|
||||
import net.minecraft.client.renderer.LevelTargetBundle;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FramePassManager {
|
||||
private static final List<PassInfo> addedPasses = new ArrayList<>();
|
||||
|
||||
protected static void addPass(ResourceLocation name, PassDefinition pass) {
|
||||
if (addedPasses.stream().noneMatch(info -> info.name.equals(name.toString()))) {
|
||||
addedPasses.add(new PassInfo(name.toString(), pass));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Cannot create a frame pass with a duplicate name: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: Pass order is determined automatically within FrameGraphBuilder. It's unclear what must be done to guarantee ordering.
|
||||
@ApiStatus.Internal
|
||||
public static void insertForgePasses(FrameGraphBuilder graphBuilder, LevelTargetBundle bundle) {
|
||||
for (PassInfo info : addedPasses) {
|
||||
FramePass pass = graphBuilder.addPass(info.name);
|
||||
PassDefinition forgePass = info.pass;
|
||||
forgePass.targets(bundle, pass);
|
||||
pass.executes(forgePass::executes);
|
||||
}
|
||||
}
|
||||
|
||||
public interface PassDefinition {
|
||||
void targets(LevelTargetBundle bundle, FramePass pass);
|
||||
void executes();
|
||||
}
|
||||
|
||||
private record PassInfo(String name, PassDefinition pass){}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.FramePassManager;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Fired after all vanilla frame passes are added into the pass list.
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain net.minecraftforge.common.MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain net.minecraftforge.fml.LogicalSide#CLIENT logical client}.
|
||||
*/
|
||||
@NullMarked
|
||||
public record AddFramePassEvent() implements RecordEvent {
|
||||
public static final EventBus<AddFramePassEvent> BUS = EventBus.create(AddFramePassEvent.class);
|
||||
/**
|
||||
* Adds a frame pass to pass list.
|
||||
* Create a new {@linkplain FramePassManager.PassDefinition} to handle render targets and render code.
|
||||
*
|
||||
* @param rl Resource location for frame pass name. Use RLs to avoid duplicate names.
|
||||
* @param definition see usages of {@linkplain com.mojang.blaze3d.framegraph.FramePass} in {@linkplain net.minecraft.client.renderer.LevelRenderer}
|
||||
* @throws IllegalArgumentException If the name is a duplicate.
|
||||
*/
|
||||
public void addPass(ResourceLocation rl, FramePassManager.PassDefinition definition) {
|
||||
ForgeHooksClient.addFramePass(rl, definition);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraftforge.client.FramePassManager;
|
||||
import net.minecraftforge.client.gui.overlay.ForgeLayeredDraw;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.Result;
|
||||
@@ -285,6 +286,10 @@ public final class ForgeEventFactoryClient {
|
||||
return fireModBus(new ModelEvent.RegisterModelStateDefinitions());
|
||||
}
|
||||
|
||||
public static void onInitLevelRenderer() {
|
||||
AddFramePassEvent.BUS.post(new AddFramePassEvent());
|
||||
}
|
||||
|
||||
public static void onComputeLayerOrder(ForgeLayeredDraw layeredDraw) {
|
||||
fireModBus(new AddGuiOverlayLayersEvent(layeredDraw));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user