Difference between revisions of "BlockEntityWithoutLevelRenderer"

From Forge Community Wiki
(Categorize with Category:Items by SizableShrimp#0755)
(Update to 1.17)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<code>ItemStackTileEntityRenderer</code> is a class that allows custom usages of <code>MatrixStack</code>s and <code>IRenderTypeBuffer</code>s to render items.
+
<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>ItemStackTileEntityRenderer</tt> ==
+
== Using <tt>BlockEntityWithoutLevelRenderer</tt> ==
<code>ItemStackTileEntityRenderer</code> allows you to render your item by extending the class and overriding <code><nowiki>ItemStackTileEntityRenderer#func_239207_a_</nowiki></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 ISTER, the Item must first return true for <code><nowiki>IBakedModel#isBuiltInRenderer</nowiki></code>. It is also recommended that if you are using a block that <code>AbstractBlock#getRenderType</code> returns <code>BlockRenderType#ENTITYBLOCK_ANIMATED</code> so that it will render correctly in layers and minecarts. Once that returns true, the Item’s ISTER will be accessed for rendering. If it does not have one, it will use the default <code>ItemStackTileEntityRenderer#instance</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 ISTER for an Item, use <code><nowiki>Item.Properties#setISTER</nowiki></code>. Each Item can only ever provide one ISTER, and the getter is final so that mods do not return new instances each frame.
+
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:
  
That’s it, no additional setup is necessary to use a ISTER.
+
<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>IBakedModel#handlePerspective</nowiki></code> and use it during rendering. This method will always be called before <code><nowiki>ItemStackTileEntityRenderer#func_239207_a_</nowiki></code>.
+
    @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]]
 
[[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

Each mod should only have one instance of a BEWLR to render all of their dynamic items.

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.