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
tutorial:blockentityrenderers [2024/08/26 09:10] – update code solidblocktutorial:blockentityrenderers [2024/08/27 04:42] (current) solidblock
Line 1: Line 1:
 ====== Rendering blocks and items dynamically using block entity renderers ====== ====== Rendering blocks and items dynamically using block entity renderers ======
  
-//This is the 1.15 & 1.16 version of this tutorial. For the 1.14 version, see [[tutorial:1.14:blockentityrenderers|Rendering blocks and items dynamically using block entity renderers (1.14)]].//+//This is the 1.15version of this tutorial. For the 1.14 version, see [[tutorial:1.14:blockentityrenderers|Rendering blocks and items dynamically using block entity renderers (1.14)]].//
  
 Make sure you [[tutorial:blockentity|added a block entity]] before reading this tutorial!  Make sure you [[tutorial:blockentity|added a block entity]] before reading this tutorial! 
 ===== Introduction ===== ===== Introduction =====
-Blocks by themselves aren't that interesting, they just stay static at a certain location and a certain size until broken. We can use block entity renderers to render items and blocks associated with a block entity far more dynamically - render multiple different items, at differing locations and sizes, and more.  +Blocks by themselves aren't that interesting, they just stay static at a certain location and a certain size until broken. We can use **block entity renderers** to render items and blocks associated with a block entity far more dynamically - render multiple different items, at differing locations and sizes, and more.  
 ===== Example ===== ===== Example =====
 In this tutorial we'll build off the block entity we created by adding a ''BlockEntityRenderer'' to it. The renderer will display a jukebox floating above the block, going up and down and spinning.   In this tutorial we'll build off the block entity we created by adding a ''BlockEntityRenderer'' to it. The renderer will display a jukebox floating above the block, going up and down and spinning.  
Line 25: Line 25:
 We're going to need to register our ''BlockEntityRenderer'', but only for the client. This wouldn't matter in a single-player setting, since the server runs in the same process as the client. However, in a multiplayer setting, where the server runs in a different process than the client, the server code has no concept of a "BlockEntityRenderer", and as a result would not accept registering one. To run initialization code only for the client, we need to setup a ''client'' entrypoint.   We're going to need to register our ''BlockEntityRenderer'', but only for the client. This wouldn't matter in a single-player setting, since the server runs in the same process as the client. However, in a multiplayer setting, where the server runs in a different process than the client, the server code has no concept of a "BlockEntityRenderer", and as a result would not accept registering one. To run initialization code only for the client, we need to setup a ''client'' entrypoint.  
  
-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):+In the entrypoint that implements ''ClientModInitializer'':
 <code java> <code java>
 @Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
Line 66: Line 66:
     }     }
 </code> </code>
-We then perform the movement of the jukebox (matrices.translate) and rotation (matrices.multiply). There are two parts to the translation: we translate it to 0.5, 1.25, and 0.5 which is above the center of our block. The second part is the part that changes: the offset in the y value. The offset is the height of the item for any given frame. We recalculate this each time because we want it to be animating bouncing up and down. We calculate this by:+We then perform the movement of the jukebox (''matrices.translate'') and rotation (''matrices.multiply''). There are two parts to the translation: we translate it to 0.5, 1.25, and 0.5 which is above the center of our block. The second part is the part that changes: the offset in the y value. The offset is the height of the item for any given frame. We recalculate this each time because we want it to be animating bouncing up and down. We calculate this by:
   * Getting the current world time, which changes over time.   * Getting the current world time, which changes over time.
   * Adding the partial ticks. (The partial ticks is a fractional value representing the amount of time that’s passed between the last full tick and now. We use this because otherwise the animation would be jittery because there are fewer ticks per second than frames per second.)   * Adding the partial ticks. (The partial ticks is a fractional value representing the amount of time that’s passed between the last full tick and now. We use this because otherwise the animation would be jittery because there are fewer ticks per second than frames per second.)
tutorial/blockentityrenderers.1724663456.txt.gz · Last modified: 2024/08/26 09:10 by solidblock