Skip to content

Commit

Permalink
render state modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Feb 6, 2025
1 parent 2948e60 commit 97bb02e
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions docs/entities/renderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,37 @@ That's literally it. Extend the class, add your field, change the generic type i
### Render State Modifications
:::info
This section is a work in progress.
In addition to being able to define new entity render states, NeoForge introduces a system that allows modifying existing render states.
To do so, a `ContextKey<T>` (where `T` is the type of the data you want to change) can be created and stored in a static field. Then, you can use it in an event handler for the `RegisterRenderStateModifiersEvent` like so:
```java
public static final ContextKey<String> EXAMPLE_CONTEXT = new ContextKey<>(
// The id of your context key. Used for distinguishing between keys internally.
ResourceLocation.fromNamespaceAndPath("examplemod", "example_context"));
@SubscribeEvent
public static void registerRenderStateModifiers(RegisterRenderStateModifiersEvent event) {
event.registerEntityModifier(
// The renderer class this modifier should target.
HumanoidMobRenderer.class,
// The modifier itself. This is a BiConsumer of the entity and the entity render state.
// Exact generic types are inferred from the generics in the renderer class used.
(entity, state) -> state.setRenderData(EXAMPLE_CONTEXT, "Hello World!");
)
}
```
:::tip
By passing `null` as the second parameter to `EntityRenderState#setRenderData`, the value can be cleared. For example:
```java
state.setRenderData(EXAMPLE_CONTEXT, null);
```
:::
This data can then be retrieved via `EntityRenderState#getRenderData` where needed. Helper methods `#getRenderDataOrThrow` and `#getRenderDataOrDefault` are available as well.
## Hierarchy
Like entities themselves, entity renderers have a class hierarchy, though not as layered. The most important classes of the hierarchy are related like this (red classes are `abstract`, blue classes are not):
Expand Down

1 comment on commit 97bb02e

@neoforged-pages-deployments
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploying with Cloudflare Pages

Name Result
Last commit: 97bb02eb91521b614443052adb9c7770cdcdfbe9
Status: ✅ Deploy successful!
Preview URL: https://65a80425.neoforged-docs-previews.pages.dev
PR Preview URL: https://pr-171.neoforged-docs-previews.pages.dev

Please sign in to comment.