User Tools

Site Tools



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

Link to this comparison view

Both sides previous revision Previous revision
tutorial:blockentityrenderers [2019/08/13 14:31]
jamieswhiteshirt Register block entity renderers in ClientModInitializer
tutorial:blockentityrenderers [2019/08/13 15:43] (current)
fudge added more information for client entrypoint
Line 22: Line 22:
 } }
 </​code>​ </​code>​
-And register ​it in our ClientModInitializer:​+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'':​ 
 +<code java> 
 +public class ExampleModClient implements ClientModInitializer { 
 +    @Override 
 +    public void onInitializeClient() { 
 +        // Here we will put client-only registration code 
 +    } 
 +Set this class as the ''​client''​ entrypoint in your ''​fabric.mod.json''​ (modify the path as needed): 
 +<code javascript "​fabric.mod.json">​ 
 +"​entrypoints":​ { 
 +    [...] 
 +    "​client":​ [ 
 +      { 
 +        "​value":​ "​"​ 
 +      } 
 +    ] 
 +And register ​the ''​BlockEntityRenderer'' ​in our ClientModInitializer:​
 <code java> <code java>
 @Override @Override
 public void onInitializeClient() { public void onInitializeClient() {
-    [...] 
     BlockEntityRendererRegistry.INSTANCE.register(DemoBlockEntity.class,​ new MyBlockEntityRenderer());​     BlockEntityRendererRegistry.INSTANCE.register(DemoBlockEntity.class,​ new MyBlockEntityRenderer());​
 } }
tutorial/blockentityrenderers.txt · Last modified: 2019/08/13 15:43 by fudge