Class AddSectionGeometryEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.client.event.AddSectionGeometryEvent

public class AddSectionGeometryEvent extends net.neoforged.bus.api.Event
This event can be used to add static geometry to chunk sections. The event is fired on the main client thread whenever a section is queued for (re)building. A rebuild can be triggered manually using e.g. LevelRenderer.setSectionDirty(int, int, int).
While the event itself is fired on the main client thread, the renderers registered using addRenderer(net.neoforged.neoforge.client.event.AddSectionGeometryEvent.AdditionalSectionRenderer) while be executed on the thread performing the rebuild, which will typically not be the main thread. Therefore, any data from non-thread-safe data structures need to be retrieved during the event handler itself rather than the renderer. A typical usage would look like
 
 @SubscribeEvent
 public static void addChunkGeometry(AddSectionGeometryEvent ev) {
     if (shouldAddGeometryTo(ev.getLevel(), ev.getSectionOrigin())) {
         final var renderingData = getDataOnMainThread(ev.getLevel(), ev.getSectionOrigin());
         ev.addRenderer(context -> renderThreadsafe(renderingData, context));
     }
 }
 
 
Note that the renderer is only added if something will actually be rendered in this example. This structure should be replicated whenever the event is used, to allow for optimizations related to entirely empty sections.

This event is not cancellable

This event is fired on the main Forge event bus, only on the logical client.

  • Field Details

  • Constructor Details

    • AddSectionGeometryEvent

      public AddSectionGeometryEvent(BlockPos sectionOrigin, Level level)
  • Method Details

    • addRenderer

      public void addRenderer(AddSectionGeometryEvent.AdditionalSectionRenderer renderer)
      Adds a renderer which will add geometry to the chunk section.
      Parameters:
      renderer - the renderer to add
    • getAdditionalRenderers

      public List<AddSectionGeometryEvent.AdditionalSectionRenderer> getAdditionalRenderers()
      Returns:
      the list of all added renderers. Do not modify the result.
    • getSectionOrigin

      public BlockPos getSectionOrigin()
      Returns:
      the origin of the section to add renderers to, i.e. the block with the smallest coordinates contained in the section.
    • getLevel

      public Level getLevel()
      Returns:
      the level to render in. This can differ from the current client level in case of e.g. guidebooks.