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
tutorial:blockentityrenderers [2022/01/31 00:23] – Remove Override From Render outercloudstudiotutorial:blockentityrenderers [2023/02/09 13:14] (current) – "you wants" -> "you want" mschae23
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<T extends BlockEntity> implements BlockEntityRenderer<T> {+@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);
Line 17: Line 18:
     public DemoBlockEntityRenderer(BlockEntityRendererFactory.Context ctx) {}     public DemoBlockEntityRenderer(BlockEntityRendererFactory.Context ctx) {}
  
 +    @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 25: 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 49: 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 74: Line 77:
  
         // Rotate the item         // Rotate the item
-        matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion((blockEntity.getWorld().getTime() + tickDelta) * 4));+        matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees((blockEntity.getWorld().getTime() + tickDelta) * 4));
     }     }
 </code> </code>
Line 105: 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 want 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.1643588603.txt.gz · Last modified: 2022/01/31 00:23 by outercloudstudio