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
Nested ClassesModifier and TypeClassDescriptionstatic interface
A rendering callback that will be invoked during chunk meshing.static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List
<AddSectionGeometryEvent.AdditionalSectionRenderer> private final net.minecraft.world.level.Level
private final net.minecraft.core.BlockPos
-
Constructor Summary
ConstructorsConstructorDescriptionAddSectionGeometryEvent
(net.minecraft.core.BlockPos sectionOrigin, net.minecraft.world.level.Level level) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a renderer which will add geometry to the chunk section.net.minecraft.world.level.Level
getLevel()
net.minecraft.core.BlockPos
-
Field Details
-
additionalRenderers
-
sectionOrigin
private final net.minecraft.core.BlockPos sectionOrigin -
level
private final net.minecraft.world.level.Level level
-
-
Constructor Details
-
AddSectionGeometryEvent
public AddSectionGeometryEvent(net.minecraft.core.BlockPos sectionOrigin, net.minecraft.world.level.Level level)
-
-
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
public net.minecraft.core.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 net.minecraft.world.level.Level getLevel()- Returns:
- the level to render in. This can differ from the current client level in case of e.g. guidebooks.
-