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
Next revisionBoth sides next revision
zh_cn:tutorial:blockentityrenderers [2019/12/19 10:10] lightcolourzh_cn:tutorial:blockentityrenderers [2019/12/19 10:14] lightcolour
Line 1: Line 1:
-====== 渲染动态使用块实体渲染器块和物品 ======+====== 渲染动态使用块实体渲染器块和物品 ======
  
-//这是本教程的1.15版本。 对于1.14版本,请参见[[tutorial:1.14:blockentityrenderers |使用块实体渲染器动态渲染块和项目(1.14)]]。+这是本教程的1.15版本。 对于1.14版本,请参见[[tutorial:1.14:blockentityrenderers |使用块实体渲染器动态渲染块和项目(1.14)]]。
  
-阅读本教程之前,请确保您已[[tutorial:blockentity |添加块实体]]! +阅读本教程之前,请确保您已[[tutorial:blockentity |添加块实体]]! 
 ===== 介绍 ===== ===== 介绍 =====
-块本身并不是那么有趣,+方块本身并不是那么有趣,
 它们只是在某个位置和某个大小保持静止直到损坏。 它们只是在某个位置和某个大小保持静止直到损坏。
-我们可以使用块实体渲染器来更加动态地渲染与块实体相关联的项目和块-渲染多个不同的项目,+我们可以使用块实体渲染器来更加动态地渲染与块实体相关联的项目和块-渲染多个不同的项目,
 在不同的位置和大小,甚至更多。  在不同的位置和大小,甚至更多。 
 ===== 例子 ===== ===== 例子 =====
 在本教程中,我们将通过向其添加''BlockEntityRenderer''来构建所创建的方块实体。 在本教程中,我们将通过向其添加''BlockEntityRenderer''来构建所创建的方块实体。
-渲染器将显示一个自动点唱机,该自动点唱机漂浮在块上方,上下,旋转。+渲染器将显示一个自动点唱机,该自动点唱机漂浮在块上方,上下,旋转。
      
 我们需要做的第一件事是创建我们的“ BlockEntityRenderer”类: 我们需要做的第一件事是创建我们的“ BlockEntityRenderer”类:
Line 70: Line 70:
 </code> </code>
 然后,我们执行自动点唱机的移动(matrices.translate)和旋转(matrices.multiply)。 然后,我们执行自动点唱机的移动(matrices.translate)和旋转(matrices.multiply)。
-转换分为两部分:将其转换为高于块中心的0.5、1.25和0.5。+转换分为两部分:将其转换为高于块中心的0.5、1.25和0.5。
 第二部分是更改的部分:y值的偏移量。 偏移量是任何给定框架的项目高度。 第二部分是更改的部分:y值的偏移量。 偏移量是任何给定框架的项目高度。
 每次我们都要重新计算,因为我们希望它可以动画上下跳跃。 我们通过以下方式计算: 每次我们都要重新计算,因为我们希望它可以动画上下跳跃。 我们通过以下方式计算:
Line 90: Line 90:
     }     }
 </code> </code>
-Finally, we will get the Minecraft 'ItemRenderer' and render the jukebox item by using ''renderItem'' +最后,我们将获得Minecraft的''ItemRenderer'',并使用''renderItem''渲染自动点唱机项目。 
-We also pass ''ModelTransformation.Type.GROUND'' to ''renderItem'' because we want a similiar effect to  +我们还将''ModelTransformation.Type.GROUND''传递给''renderItem'',因为我们希望有类似的效果 
-an item lying on the ground. Try experimenting with this value and see what happens (it's an enum).  +躺在地上的物品。 尝试尝试使用此值,看看会发生什么(这是一个枚举)。 
-We also need to call ''matrices.pop();'' after these GL calls:+在这些GL调用之后,我们还需要调用''matrices.pop();''
 <code java> <code java>
     public void render(DemoBlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {     public void render(DemoBlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
Line 104: Line 104:
 </code> </code>
  
-You can try your newly created block entity renderer right now.  +您可以立即尝试新创建的方块实体渲染器。 
-However, if you didn't make your block transparent, you will notice something is amiss the floating block, the jukebox, is pitch black!   +但是,如果您没有使方块透明,您会发现有些不对劲-浮动方块,点唱机是黑色的! 
-This is because by default, //whatever you render in the block entity, will receive light as if it's in the same position as the block entity//. +这是因为默认情况下,无论您在方块实体中进行渲染的任何内容,都将接收光线,就好像它与方块实体处于同一位置一样。 
-So the floating block receives light from //inside// our opaque block, which means it receives no light!  +因此,浮动方块从不透明的方块中接收inside的光,这意味着它没有接收到光! 
-To fix this, we will tell Minecraft to receive light from //one block above// the location of the block entity.  +为了解决这个问题,我们将告诉Minecraft从上方的一个方块方块实体的位置接收光。
  
-To get the light, we call ''WorldRenderer#getLightmapCoordinates()'' on the position above our block entity,  +要获取灯光,我们在方块实体上方的位置调用''WorldRenderergetLightmapCoordinates();'' 
-and to use the light we use it in ''renderItem()'':+并使用灯光,我们在''renderItem();''中使用它:
 <code java> <code java>
     @Override     @Override
Line 124: Line 124:
 </code> </code>
  
-The jukebox should now have the proper lighting. +点唱机现在应具有适当的照明。
zh_cn/tutorial/blockentityrenderers.txt · Last modified: 2023/08/29 10:31 by wjz_p