BlockEntityWithoutLevelRenderer/1.17

From Forge Community Wiki
Revision as of 05:49, 6 December 2021 by ShrimpBot (talk | contribs) (Copy BlockEntityWithoutLevelRenderer to MC1.17 archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.