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.
While the event itself is fired on the main client thread, the renderers registered using
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A rendering callback that will be invoked during chunk meshing.static final class
-
Field Summary
Modifier and TypeFieldDescriptionprivate final List
<AddSectionGeometryEvent.AdditionalSectionRenderer> private final Level
private final BlockPos
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a renderer which will add geometry to the chunk section.getLevel()
-
Field Details
-
additionalRenderers
-
sectionOrigin
-
level
-
-
Constructor Details
-
AddSectionGeometryEvent
-
-
Method Details
-
addRenderer
Adds a renderer which will add geometry to the chunk section.- Parameters:
renderer
- the renderer to add
-
getAdditionalRenderers
- Returns:
- the list of all added renderers. Do not modify the result.
-
getSectionOrigin
- Returns:
- the origin of the section to add renderers to, i.e. the block with the smallest coordinates contained in the section.
-
getLevel
- Returns:
- the level to render in. This can differ from the current client level in case of e.g. guidebooks.
-