Skip to main content
Version: 1.20.x

BlockEntityWithoutLevelRenderer

BlockEntityWithoutLevelRenderer是一种处理物品的动态渲染的方法。这个系统比旧的ItemStack系统简单得多,旧的ItemStack系统需要BlockEntity,并且不允许访问ItemStack

使用BlockEntityWithoutLevelRenderer

BlockEntityWithoutLevelRenderer允许你使用public void renderByItem(ItemStack itemStack, ItemDisplayContext ctx, PoseStack poseStack, MultiBufferSource bufferSource, int combinedLight, int combinedOverlay)来渲染物品。

为了使用BEWLR,Item必须首先满足其模型的BakedModel#isCustomRenderer返回true。如果没有,它将使用默认的ItemRenderer#getBlockEntityRenderer。一旦返回true,将访问该Item的BEWLR进行渲染。

!!! 注意 如果Block#getRenderShape设置为RenderShape#ENTITYBLOCK_ANIMATEDBlock也会使用BEWLR进行渲染。

若要设置物品的BEWLR,必须在Item#initializeClient中使用IClientItemExtensions的一个匿名实例。在该匿名实例中,应重写IClientItemExtensions#getCustomRenderer以返回你的BEWLR的实例:

// 在你的物品类中
@Override
public void initializeClient(Consumer<IClientItemExtensions> consumer) {
consumer.accept(new IClientItemExtensions() {

@Override
public BlockEntityWithoutLevelRenderer getCustomRenderer() {
return myBEWLRInstance;
}
});
}

!!! 重要 每个模组都应该只有一个自定义BEWLR的实例。

这就行了,使用BEWLR不需要额外的设置。