1,849 bytes added
, 05:49, 6 December 2021
<code>BlockEntityWithoutLevelRenderer</code> is a class that allows custom usages of <code>PoseStack</code>s and <code>MultiBufferSource</code>s to render items.
== Using <tt>BlockEntityWithoutLevelRenderer</tt> ==
<code>BlockEntityWithoutLevelRenderer</code> allows you to render your item by extending the class and overriding <code><nowiki>BlockEntityWithoutLevelRenderer#renderByItem</nowiki></code>.
In order to use a BEWLR, the Item must first return true for <code><nowiki>BakedModel#isCustomRenderer</nowiki></code>. Once that returns true, the Item’s BEWLR will be accessed for rendering. If it does not have one, it will use the default <code>ItemRenderer#getBlockEntityRenderer</code>.
To set the BEWLR for an Item, an anonymous instance of <code>IItemRenderProperties</code> must be consumed within <code>Item#initializeClient</code>. Within the anonymous instance, <code>IItemRenderProperties#getItemStackRenderer</code> should be overridden to return the instance of your BEWLR:
<syntaxhighlight lang="java">
// In your item class
@Override
public void initializeClient(Consumer<IItemRenderProperties> consumer) {
consumer.accept(new IItemRenderProperties() {
@Override
public BlockEntityWithoutLevelRenderer getItemStackRenderer() {
return myBEWLRInstance;
}
});
}
</syntaxhighlight>
That’s it, no additional setup is necessary to use a BEWLR.
{{Tip/Important|Each mod should only have one instance of a BEWLR to render all of their dynamic items.}}
If you need to access the <code>TransformType</code> for rendering, you can store the one passed through <code><nowiki>BakedModel#handlePerspective</nowiki></code> and use it during rendering. This method will always be called before <code><nowiki>BlockEntityWithoutLevelRenderer#renderByItem</nowiki></code>.
[[Category:Items/1.17|Category:Items]]