mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 19:59:42 +00:00
[1.19.x] Added RenderLevelStageEvent to replace RenderLevelLastEvent (#8820)
* Ported RenderLevelStageEvent from 1.18.2 * Updated to fix merge conflicts
This commit is contained in:
1 parent
8a67be4afd
commit
03202a8ab4
7 files changed
+410
-22
No files matched your search
@@ -55,6 +55,7 @@ import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.client.renderer.Sheets;
|
||||
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.culling.Frustum;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.language.I18n;
|
||||
@@ -121,6 +122,7 @@ import net.minecraftforge.client.event.RenderBlockScreenEffectEvent;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderHighlightEvent;
|
||||
import net.minecraftforge.client.event.RenderLevelLastEvent;
|
||||
import net.minecraftforge.client.event.RenderLevelStageEvent;
|
||||
import net.minecraftforge.client.event.RenderTooltipEvent;
|
||||
import net.minecraftforge.client.event.ScreenEvent;
|
||||
import net.minecraftforge.client.event.ScreenshotEvent;
|
||||
@@ -259,11 +261,28 @@ public class ForgeHooksClient
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.19")
|
||||
public static void dispatchRenderLast(LevelRenderer context, PoseStack poseStack, float partialTick, Matrix4f projectionMatrix, long finishTimeNano)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new RenderLevelLastEvent(context, poseStack, partialTick, projectionMatrix, finishTimeNano));
|
||||
}
|
||||
|
||||
public static void dispatchRenderStage(RenderLevelStageEvent.Stage stage, LevelRenderer levelRenderer, PoseStack poseStack, Matrix4f projectionMatrix, int renderTick, Camera camera, Frustum frustum)
|
||||
{
|
||||
var mc = Minecraft.getInstance();
|
||||
var profiler = mc.getProfiler();
|
||||
profiler.push(stage.toString());
|
||||
MinecraftForge.EVENT_BUS.post(new RenderLevelStageEvent(stage, levelRenderer, poseStack, projectionMatrix, renderTick, mc.getPartialTick(), camera, frustum));
|
||||
profiler.pop();
|
||||
}
|
||||
|
||||
public static void dispatchRenderStage(RenderType renderType, LevelRenderer levelRenderer, PoseStack poseStack, Matrix4f projectionMatrix, int renderTick, Camera camera, Frustum frustum)
|
||||
{
|
||||
RenderLevelStageEvent.Stage stage = RenderLevelStageEvent.Stage.fromRenderType(renderType);
|
||||
if (stage != null)
|
||||
dispatchRenderStage(stage, levelRenderer, poseStack, projectionMatrix, renderTick, camera, frustum);
|
||||
}
|
||||
|
||||
public static boolean renderSpecificFirstPersonHand(InteractionHand hand, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, float partialTick, float interpPitch, float swingProgress, float equipProgress, ItemStack stack)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new RenderHandEvent(hand, poseStack, bufferSource, packedLight, partialTick, interpPitch, swingProgress, equipProgress, stack));
|
||||
|
||||
@@ -32,7 +32,8 @@ public enum ForgeRenderTypes
|
||||
ITEM_LAYERED_TRANSLUCENT(()-> getItemLayeredTranslucent(TextureAtlas.LOCATION_BLOCKS)),
|
||||
ITEM_UNSORTED_TRANSLUCENT(()-> getUnsortedTranslucent(TextureAtlas.LOCATION_BLOCKS)),
|
||||
ITEM_UNLIT_TRANSLUCENT(()-> getUnlitTranslucent(TextureAtlas.LOCATION_BLOCKS)),
|
||||
ITEM_UNSORTED_UNLIT_TRANSLUCENT(()-> getUnlitTranslucent(TextureAtlas.LOCATION_BLOCKS, false));
|
||||
ITEM_UNSORTED_UNLIT_TRANSLUCENT(()-> getUnlitTranslucent(TextureAtlas.LOCATION_BLOCKS, false)),
|
||||
TRANSLUCENT_ON_PARTICLES_TARGET(() -> getTranslucentParticlesTarget(TextureAtlas.LOCATION_BLOCKS));
|
||||
|
||||
public static boolean enableTextTextureLinearFiltering = false;
|
||||
|
||||
@@ -151,6 +152,14 @@ public enum ForgeRenderTypes
|
||||
return Internal.TEXT_INTENSITY_SEETHROUGH.apply(locationIn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A variation of {@link RenderType#translucent()} that uses {@link OutputStateShard#PARTICLES_TARGET} to allow fabulous transparency sorting when using {@link RenderLevelStageEvent}
|
||||
*/
|
||||
public static RenderType getTranslucentParticlesTarget(ResourceLocation locationIn)
|
||||
{
|
||||
return Internal.TRANSLUCENT_PARTICLES_TARGET.apply(locationIn);
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// Implementation details below this line
|
||||
// ----------------------------------------
|
||||
@@ -340,6 +349,18 @@ public enum ForgeRenderTypes
|
||||
.createCompositeState(false);
|
||||
return create("forge_text_see_through", DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, VertexFormat.Mode.QUADS, 256, false, true, rendertype$state);
|
||||
}
|
||||
|
||||
public static Function<ResourceLocation, RenderType> TRANSLUCENT_PARTICLES_TARGET = Util.memoize(Internal::getTranslucentParticlesTarget);
|
||||
private static RenderType getTranslucentParticlesTarget(ResourceLocation locationIn) {
|
||||
RenderType.CompositeState rendertype$state = RenderType.CompositeState.builder()
|
||||
.setShaderState(RENDERTYPE_TRANSLUCENT_SHADER)
|
||||
.setTextureState(new RenderStateShard.TextureStateShard(locationIn, false, true))
|
||||
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
|
||||
.setLightmapState(LIGHTMAP)
|
||||
.setOutputState(PARTICLES_TARGET)
|
||||
.createCompositeState(true);
|
||||
return create("forge_translucent_particles_target", DefaultVertexFormat.BLOCK, VertexFormat.Mode.QUADS, 2097152, true, true, rendertype$state);
|
||||
}
|
||||
}
|
||||
|
||||
private static class CustomizableTextureState extends TextureStateShard
|
||||
|
||||
@@ -23,9 +23,12 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*
|
||||
* @deprecated Use {@link RenderLevelStageEvent} instead for more flexibility and improved compatibility with translucent objects.
|
||||
* There is no {@link RenderLevelStageEvent.Stage} that directly replaces this event, instead you must decide which Stage best fits your use case.
|
||||
* @see GameRenderer
|
||||
* @see LevelRenderer
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.19")
|
||||
public class RenderLevelLastEvent extends net.minecraftforge.eventbus.api.Event
|
||||
{
|
||||
private final LevelRenderer levelRenderer;
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Matrix4f;
|
||||
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.culling.Frustum;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.ForgeRenderTypes;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
|
||||
/**
|
||||
* Fires at various times during LevelRenderer.renderLevel.
|
||||
* Check {@link #getStage} to render during the appropriate time for your use case.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public class RenderLevelStageEvent extends Event
|
||||
{
|
||||
private final Stage stage;
|
||||
private final LevelRenderer levelRenderer;
|
||||
private final PoseStack poseStack;
|
||||
private final Matrix4f projectionMatrix;
|
||||
private final int renderTick;
|
||||
private final float partialTick;
|
||||
private final Camera camera;
|
||||
private final Frustum frustum;
|
||||
|
||||
public RenderLevelStageEvent(Stage stage, LevelRenderer levelRenderer, PoseStack poseStack, Matrix4f projectionMatrix, int renderTick, float partialTick, Camera camera, Frustum frustum)
|
||||
{
|
||||
this.stage = stage;
|
||||
this.levelRenderer = levelRenderer;
|
||||
this.poseStack = poseStack;
|
||||
this.projectionMatrix = projectionMatrix;
|
||||
this.renderTick = renderTick;
|
||||
this.partialTick = partialTick;
|
||||
this.camera = camera;
|
||||
this.frustum = frustum;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the current {@linkplain Stage stage} that is being rendered. Check this before doing rendering to ensure
|
||||
* that rendering happens at the appropriate time.}
|
||||
*/
|
||||
public Stage getStage()
|
||||
{
|
||||
return stage;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the level renderer}
|
||||
*/
|
||||
public LevelRenderer getLevelRenderer()
|
||||
{
|
||||
return levelRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack()
|
||||
{
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the projection matrix}
|
||||
*/
|
||||
public Matrix4f getProjectionMatrix()
|
||||
{
|
||||
return projectionMatrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the current "ticks" value in the {@linkplain LevelRenderer level renderer}}
|
||||
*/
|
||||
public int getRenderTick()
|
||||
{
|
||||
return renderTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the current partialTick value used for rendering}
|
||||
*/
|
||||
public float getPartialTick()
|
||||
{
|
||||
return partialTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the camera}
|
||||
*/
|
||||
public Camera getCamera()
|
||||
{
|
||||
return camera;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the frustum}
|
||||
*/
|
||||
public Frustum getFrustum()
|
||||
{
|
||||
return frustum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use to create a custom {@linkplain RenderLevelStageEvent.Stage stages}.
|
||||
* Fired after the LevelRenderer has been created.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class RegisterStageEvent extends Event implements IModBusEvent
|
||||
{
|
||||
/**
|
||||
* @param name The name of your Stage.
|
||||
* @param renderType
|
||||
* If not null, called automatically by LevelRenderer.renderChunkLayer if the RenderType passed into it matches this one.
|
||||
* If null, needs to be called manually by whoever implements it.
|
||||
*
|
||||
* @throws IllegalArgumentException if the RenderType passed is already mapped to a Stage.
|
||||
*/
|
||||
public Stage register(ResourceLocation name, @Nullable RenderType renderType) throws IllegalArgumentException
|
||||
{
|
||||
return Stage.register(name, renderType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A time during level rendering for you to render custom things into the world.
|
||||
* @see RegisterStageEvent
|
||||
*/
|
||||
public static class Stage
|
||||
{
|
||||
private static final Map<RenderType, Stage> RENDER_TYPE_STAGES = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Use this to render custom objects into the skybox.
|
||||
* Called regardless of if they sky actually renders or not.
|
||||
*/
|
||||
public static final Stage AFTER_SKY = register("after_sky", null);
|
||||
/**
|
||||
* Use this to render custom block-like geometry into the world.
|
||||
*/
|
||||
public static final Stage AFTER_SOLID_BLOCKS = register("after_solid_blocks", RenderType.solid());
|
||||
/**
|
||||
* Use this to render custom block-like geometry into the world.
|
||||
*/
|
||||
public static final Stage AFTER_CUTOUT_MIPPED_BLOCKS_BLOCKS = register("after_cutout_mipped_blocks", RenderType.cutoutMipped());
|
||||
/**
|
||||
* Use this to render custom block-like geometry into the world.
|
||||
*/
|
||||
public static final Stage AFTER_CUTOUT_BLOCKS = register("after_cutout_blocks", RenderType.cutout());
|
||||
/**
|
||||
* Use this to render custom block-like geometry into the world.
|
||||
* Due to how transparency sorting works, this stage may not work properly with translucency. If you intend to render translucency,
|
||||
* try using {@link #AFTER_TRIPWIRE_BLOCKS} or {@link #AFTER_PARTICLES}.
|
||||
* Although this is called within a fabulous graphics target, it does not function properly in many cases.
|
||||
*/
|
||||
public static final Stage AFTER_TRANSLUCENT_BLOCKS = register("after_translucent_blocks", RenderType.translucent());
|
||||
/**
|
||||
* Use this to render custom block-like geometry into the world.
|
||||
*/
|
||||
public static final Stage AFTER_TRIPWIRE_BLOCKS = register("after_tripwire_blocks", RenderType.tripwire());
|
||||
/**
|
||||
* Use this to render custom effects into the world, such as custom entity-like objects or special rendering effects.
|
||||
* Called within a fabulous graphics target.
|
||||
* Happens after entities render.
|
||||
*
|
||||
* @see ForgeRenderTypes#TRANSLUCENT_ON_PARTICLES_TARGET
|
||||
*/
|
||||
public static final Stage AFTER_PARTICLES = register("after_particles", null);
|
||||
/**
|
||||
* Use this to render custom weather effects into the world.
|
||||
* Called within a fabulous graphics target.
|
||||
*/
|
||||
public static final Stage AFTER_WEATHER = register("after_weather", null);
|
||||
|
||||
private final String name;
|
||||
|
||||
private Stage(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private static Stage register(ResourceLocation name, @Nullable RenderType renderType) throws IllegalArgumentException
|
||||
{
|
||||
Stage stage = new Stage(name.toString());
|
||||
if (renderType != null && RENDER_TYPE_STAGES.putIfAbsent(renderType, stage) != null)
|
||||
throw new IllegalArgumentException("Attempted to replace an existing RenderLevelStageEvent.Stage for a RenderType: Stage = " + stage + ", RenderType = " + renderType);
|
||||
return stage;
|
||||
}
|
||||
|
||||
private static Stage register(String name, @Nullable RenderType renderType) throws IllegalArgumentException
|
||||
{
|
||||
return register(new ResourceLocation(name), renderType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the {@linkplain Stage stage} bound to the {@linkplain RenderType render type}, or null if no value is present}
|
||||
*/
|
||||
@Nullable
|
||||
public static Stage fromRenderType(RenderType renderType)
|
||||
{
|
||||
return RENDER_TYPE_STAGES.get(renderType);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user