Difference between revisions of "BlockEntityWithoutLevelRenderer"
(Inital Import dokuwiki) |
(Update to 1.17) |
||
| (3 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
| − | <code> | + | <code>BlockEntityWithoutLevelRenderer</code> is a class that allows custom usages of <code>PoseStack</code>s and <code>MultiBufferSource</code>s to render items. |
| − | == Using < | + | == Using <tt>BlockEntityWithoutLevelRenderer</tt> == |
| − | <code> | + | <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 | + | 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 | + | 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() { | ||
| − | If you need to access the <code>TransformType</code> for rendering, you can store the one passed through <code><nowiki> | + | @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]] | ||
Latest revision as of 23:04, 30 July 2021
BlockEntityWithoutLevelRenderer is a class that allows custom usages of PoseStacks and MultiBufferSources to render items.
Using BlockEntityWithoutLevelRenderer
BlockEntityWithoutLevelRenderer allows you to render your item by extending the class and overriding BlockEntityWithoutLevelRenderer#renderByItem.
In order to use a BEWLR, the Item must first return true for BakedModel#isCustomRenderer. Once that returns true, the Item’s BEWLR will be accessed for rendering. If it does not have one, it will use the default ItemRenderer#getBlockEntityRenderer.
To set the BEWLR for an Item, an anonymous instance of IItemRenderProperties must be consumed within Item#initializeClient. Within the anonymous instance, IItemRenderProperties#getItemStackRenderer should be overridden to return the instance of your BEWLR:
// In your item class
@Override
public void initializeClient(Consumer<IItemRenderProperties> consumer) {
consumer.accept(new IItemRenderProperties() {
@Override
public BlockEntityWithoutLevelRenderer getItemStackRenderer() {
return myBEWLRInstance;
}
});
}
That’s it, no additional setup is necessary to use a BEWLR.
Important
If you need to access the TransformType for rendering, you can store the one passed through BakedModel#handlePerspective and use it during rendering. This method will always be called before BlockEntityWithoutLevelRenderer#renderByItem.