User Tools

Site Tools


zh_cn:tutorial:blockentityrenderers

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
zh_cn:tutorial:blockentityrenderers [2022/02/07 07:40] – [例子] solidblockzh_cn:tutorial:blockentityrenderers [2023/08/29 09:59] – [例子] wjz_p
Line 1: Line 1:
 ====== 使用方块实体渲染器动态渲染方块和物品 ====== ====== 使用方块实体渲染器动态渲染方块和物品 ======
 // //
-这是本教程的1.15和1.16版本。对于1.14版本,请参见[[zh_cn:tutorial:1.14:blockentityrenderers|使用方块实体渲染器动态渲染方块和物品(1.14)]]。//+这是本教程的 1.15 以上版本。对于 1.14 版本,请参见[[zh_cn:tutorial:1.14:blockentityrenderers|使用方块实体渲染器动态渲染方块和物品(1.14)]]。//
  
-阅读本教程之前,请确保您已[[zh_cn:tutorial:blockentity|添加方块实体]]!+阅读本教程之前,请确保您已[[blockentity|添加方块实体]]!
 ===== 介绍 ===== ===== 介绍 =====
 方块本身并不是那么有趣,只是在某个位置和某个大小保持静止直到损坏。我们可以使用方块实体渲染器(block entity renderer)更加动态地渲染与方块实体有关的物品和方块——在不同的位置、以不同的大小渲染多个物品。 方块本身并不是那么有趣,只是在某个位置和某个大小保持静止直到损坏。我们可以使用方块实体渲染器(block entity renderer)更加动态地渲染与方块实体有关的物品和方块——在不同的位置、以不同的大小渲染多个物品。
Line 11: Line 11:
 我们需要做的第一件事是创建我们的 ''BlockEntityRenderer'' 类: 我们需要做的第一件事是创建我们的 ''BlockEntityRenderer'' 类:
 <code java> <code java>
-public class DemoBlockEntityRenderer<T extends BlockEntity> implements BlockEntityRenderer<T> {+@Environment(EnvType.CLIENT) 
 +public class DemoBlockEntityRenderer implements BlockEntityRenderer<DemoBlockEntity> {
     // 唱片机物品堆     // 唱片机物品堆
     private static ItemStack stack = new ItemStack(Items.JUKEBOX, 1);     private static ItemStack stack = new ItemStack(Items.JUKEBOX, 1);
Line 28: Line 29:
  
 <code java> <code java>
 +@Environment(EnvType.CLIENT)
 public class ExampleModClient implements ClientModInitializer { public class ExampleModClient implements ClientModInitializer {
     @Override     @Override
Line 50: Line 52:
  
 <code java> <code java>
-@Override +    @Override 
-public void onInitializeClient() { +    public void onInitializeClient() { 
-    BlockEntityRendererRegistry.INSTANCE.register(DEMO_BLOCK_ENTITY, DemoBlockEntityRenderer::new); +        BlockEntityRendererRegistry.register(DEMO_BLOCK_ENTITY, DemoBlockEntityRenderer::new); 
-}+        //不行就试试BlockEntityRendererRegistry.INSTANCE.register(DEMO_BLOCK_ENTITY, DemoBlockEntityRenderer::new); 
 +    }
 </code> </code>
 我们重写在每一帧都会被调用的 ''render'' 方法,我们将在其中进行渲染——对于初学者,请调用 ''matrices.push();'',这在进行GL调用时是必需的(我们将在紧接之后进行): 我们重写在每一帧都会被调用的 ''render'' 方法,我们将在其中进行渲染——对于初学者,请调用 ''matrices.push();'',这在进行GL调用时是必需的(我们将在紧接之后进行):
zh_cn/tutorial/blockentityrenderers.txt · Last modified: 2023/08/29 10:31 by wjz_p