User Tools

Site Tools


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
tutorial:blockentityrenderers [2021/05/20 11:23] – the renderer of DemoBlockEntity should be DemoBlockEntity Renderer instead of MyBlockEntityRenderer solidblocktutorial:blockentityrenderers [2022/12/17 15:35] – remove vec3f references miir
Line 11: Line 11:
 The first thing we need to do is create our ''BlockEntityRenderer'' class: The first thing we need to do is create our ''BlockEntityRenderer'' class:
 <code java> <code java>
-public class DemoBlockEntityRenderer extends BlockEntityRenderer<DemoBlockEntity> {+@Environment(EnvType.CLIENT) 
 +public class DemoBlockEntityRenderer implements BlockEntityRenderer<DemoBlockEntity > {
     // A jukebox itemstack     // A jukebox itemstack
     private static ItemStack stack = new ItemStack(Items.JUKEBOX, 1);     private static ItemStack stack = new ItemStack(Items.JUKEBOX, 1);
          
-    public DemoBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) { +    public DemoBlockEntityRenderer(BlockEntityRendererFactory.Context ctx) {} 
-        super(dispatcher); +
-    +
-    +
     @Override     @Override
     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 28: Line 27:
 Create a new class next to your main class that implements ''ClientModInitializer'' (in this tutorial assume that ExampleModClient is in the same folder as the former ExampleMod is): Create a new class next to your main class that implements ''ClientModInitializer'' (in this tutorial assume that ExampleModClient is in the same folder as the former ExampleMod is):
 <code java> <code java>
 +@Environment(EnvType.CLIENT)
 public class ExampleModClient implements ClientModInitializer { public class ExampleModClient implements ClientModInitializer {
     @Override     @Override
Line 52: Line 52:
 @Override @Override
 public void onInitializeClient() { public void onInitializeClient() {
-    BlockEntityRendererRegistry.INSTANCE.register(DEMO_BLOCK_ENTITY, DemoBlockEntityRenderer::new);+    BlockEntityRendererRegistry.register(DEMO_BLOCK_ENTITY, DemoBlockEntityRenderer::new);
 } }
 </code> </code>
Line 77: Line 77:
  
         // Rotate the item         // Rotate the item
-        matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion((blockEntity.getWorld().getTime() + tickDelta) * 4));+        matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees((blockEntity.getWorld().getTime() + tickDelta) * 4));
     }     }
 </code> </code>
Line 84: Line 84:
     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) {
         [...]         [...]
-        MinecraftClient.getInstance().getItemRenderer().renderItem(stack, ModelTransformation.Mode.GROUND, light, overlay, matrices, vertexConsumers);+        MinecraftClient.getInstance().getItemRenderer().renderItem(stack, ModelTransformation.Mode.GROUND, light, overlay, matrices, vertexConsumers, 0);
  
         // Mandatory call after GL calls         // Mandatory call after GL calls
Line 101: Line 101:
                  
         int lightAbove = WorldRenderer.getLightmapCoordinates(blockEntity.getWorld(), blockEntity.getPos().up());         int lightAbove = WorldRenderer.getLightmapCoordinates(blockEntity.getWorld(), blockEntity.getPos().up());
-        MinecraftClient.getInstance().getItemRenderer().renderItem(stack, ModelTransformation.Mode.GROUND, lightAbove, OverlayTexture.DEFAULT_UV, matrices, vertexConsumers);+        MinecraftClient.getInstance().getItemRenderer().renderItem(stack, ModelTransformation.Mode.GROUND, lightAbove, OverlayTexture.DEFAULT_UV, matrices, vertexConsumers, 0);
                  
         [...]         [...]
Line 108: Line 108:
  
 The jukebox should now have the proper lighting.  The jukebox should now have the proper lighting. 
 +
 +===== Rendering according to block entity data =====
 +Sometimes you wants to render according to the block entity data (nbt), and you find they are all empty, even if you can access the data through ''/data get block'' command. That's because you did not sync data from server to client. See [[tutorial:blockentity#Sync data from server to client]].
tutorial/blockentityrenderers.txt · Last modified: 2023/02/09 13:14 by mschae23