Class WorldRenderEvents

java.lang.Object
net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents

public final class WorldRenderEvents extends Object
Mods should use these events to introduce custom rendering during WorldRenderer.render(net.minecraft.client.render.RenderTickCounter, boolean, net.minecraft.client.render.Camera, net.minecraft.client.render.GameRenderer, net.minecraft.client.render.LightmapTextureManager, org.joml.Matrix4f, org.joml.Matrix4f) without adding complicated and conflict-prone injections there. Using these events also enables 3rd-party renderers that make large-scale changes to rendering maintain compatibility by calling any broken event invokers directly.

The order of events each frame is as follows:

  • START
  • AFTER_SETUP
  • BEFORE_ENTITIES
  • AFTER_ENTITIES
  • BEFORE_BLOCK_OUTLINE
  • BLOCK_OUTLINE (If not cancelled in BEFORE_BLOCK_OUTLINE)
  • BEFORE_DEBUG_RENDER
  • AFTER_TRANSLUCENT
  • LAST
  • END

These events are not dependent on the Fabric rendering API or Indigo but work when those are present.

  • Field Details

    • START

      public static final Event<WorldRenderEvents.Start> START
      Called before world rendering executes. Input parameters are available but frustum is not. Use this event instead of injecting to the HEAD of WorldRenderer.render(net.minecraft.client.render.RenderTickCounter, boolean, net.minecraft.client.render.Camera, net.minecraft.client.render.GameRenderer, net.minecraft.client.render.LightmapTextureManager, org.joml.Matrix4f, org.joml.Matrix4f) to avoid compatibility problems with 3rd-party renderer implementations.

      Use for setup of state that is needed during the world render call that does not depend on the view frustum.

    • AFTER_SETUP

      public static final Event<WorldRenderEvents.AfterSetup> AFTER_SETUP
      Called after view Frustum is computed and all render chunks to be rendered are identified and rebuilt but before chunks are uploaded to GPU.

      Use for setup of state that depends on view frustum.

    • BEFORE_ENTITIES

      public static final Event<WorldRenderEvents.BeforeEntities> BEFORE_ENTITIES
      Called after the Solid, Cutout and Cutout Mipped terrain layers have been output to the framebuffer.

      Use to render non-translucent terrain to the framebuffer.

      Note that 3rd-party renderers may combine these passes or otherwise alter the rendering pipeline for sake of performance or features. This can break direct writes to the framebuffer. Use this event for cases that cannot be satisfied by FabricBakedModel, BlockEntityRenderer or other existing abstraction. If at all possible, use an existing terrain RenderLayer instead of outputting to the framebuffer directly with GL calls.

      The consumer is responsible for setup and tear down of GL state appropriate for the intended output.

      Because solid and cutout quads are depth-tested, order of output does not matter except to improve culling performance, which should not be significant after primary terrain rendering. This means mods that currently hook calls to individual render layers can simply execute them all at once when the event is called.

      This event fires before entities and block entities are rendered and may be useful to prepare them.

    • AFTER_ENTITIES

      public static final Event<WorldRenderEvents.AfterEntities> AFTER_ENTITIES
      Called after entities are rendered and solid entity layers have been drawn to the main frame buffer target, before block entity rendering begins.

      Use for global block entity render setup, or to append block-related quads to the entity consumers using the VertexConsumerProvider from the provided context. This will generally give better (if not perfect) results for non-terrain translucency vs. drawing directly later on.

    • BEFORE_BLOCK_OUTLINE

      public static final Event<WorldRenderEvents.BeforeBlockOutline> BEFORE_BLOCK_OUTLINE
      Called before default block outline rendering and before checks are done to determine if it should happen. Can optionally cancel the default rendering but all event handlers will always be called.

      Use this to decorate or replace the default block outline rendering for specific modded blocks or when the need for a block outline render would not be detected. Normally, outline rendering will not happen for entities, fluids, or other game objects that do not register a block-type hit.

      Returning false from any event subscriber will cancel the default block outline render and suppress the BLOCK_RENDER event. This has no effect on other subscribers to this event - all subscribers will always be called. Canceling here is appropriate when there is still a valid block hit (with a fluid, for example) and you don't want the block outline render to appear.

      This event should NOT be used for general-purpose replacement of the default block outline rendering because it will interfere with mod-specific renders. Mods that replace the default block outline for specific blocks should instead subscribe to BLOCK_OUTLINE.

    • BLOCK_OUTLINE

      public static final Event<WorldRenderEvents.BlockOutline> BLOCK_OUTLINE
      Called after block outline render checks are made and before the default block outline render runs. Will NOT be called if the default outline render was cancelled in BEFORE_BLOCK_OUTLINE.

      Use this to replace the default block outline rendering for specific blocks that need special outline rendering or to add information that doesn't replace the block outline. Subscribers cannot affect each other or detect if another subscriber is also handling a specific block. If two subscribers render for the same block, both renders will appear.

      Returning false from any event subscriber will cancel the default block outline render. This has no effect on other subscribers to this event - all subscribers will always be called. Canceling is appropriate when the subscriber replacing the default block outline render for a specific block.

      This event is not appropriate for mods that replace the default block outline render for all blocks because all event subscribers will always render - only the default outline render can be cancelled. That should be accomplished by mixin to the block outline render routine itself, typically by targeting WorldRenderer.drawShapeOutline(net.minecraft.client.util.math.MatrixStack, net.minecraft.client.render.VertexConsumer, net.minecraft.util.shape.VoxelShape, double, double, double, float, float, float, float, boolean).

    • BEFORE_DEBUG_RENDER

      public static final Event<WorldRenderEvents.DebugRender> BEFORE_DEBUG_RENDER
      Called before vanilla debug renderers are output to the framebuffer. This happens very soon after entities, block breaking and most other non-translucent renders but before translucency is drawn.

      Unlike most other events, renders in this event are expected to be drawn directly and immediately to the framebuffer. The OpenGL render state view matrix will be transformed to match the camera view before the event is called.

      Use to drawn lines, overlays and other content similar to vanilla debug renders.

    • AFTER_TRANSLUCENT

      public static final Event<WorldRenderEvents.AfterTranslucent> AFTER_TRANSLUCENT
      Called after entity, terrain, and particle translucent layers have been drawn to the framebuffer but before translucency combine has happened in fabulous mode.

      Use for drawing overlays or other effects on top of those targets (or the main target when fabulous isn't active) before clouds and weather are drawn. However, note that WorldRenderPostEntityCallback will offer better results in most use cases.

      Vertex consumers are not available in this event because all buffered quads are drawn before this event is called. Any rendering here must be drawn directly to the frame buffer. The render state matrix will not include camera transformation, so LAST may be preferable if that is wanted.

    • LAST

      public static final Event<WorldRenderEvents.Last> LAST
      Called after all framebuffer writes are complete but before all world rendering is torn down.

      Unlike most other events, renders in this event are expected to be drawn directly and immediately to the framebuffer. The OpenGL render state view matrix will be transformed to match the camera view before the event is called.

      Use to draw content that should appear on top of the world before hand and GUI rendering occur.

    • END

      public static final Event<WorldRenderEvents.End> END
      Called after all world rendering is complete and changes to GL state are unwound.

      Use to draw overlays that handle GL state management independently or to tear down transient state in event handlers or as a hook that precedes hand/held item and GUI rendering.