User Tools

Site Tools


tutorial:extendedscreenhandler

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
tutorial:extendedscreenhandler [2020/08/14 16:27] – [Registering our ScreenHandler] manymoney2tutorial:extendedscreenhandler [2020/08/14 17:42] – [Result] manymoney2
Line 151: Line 151:
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
  
-    public static final Block BOX_BLOCK; +    [...]
-    public static final BlockItem BOX_BLOCK_ITEM; +
-    public static final BlockEntityType<BoxBlockEntity> BOX_BLOCK_ENTITY;+
     public static final ScreenHandlerType<BoxScreenHandler> BOX_SCREEN_HANDLER;     public static final ScreenHandlerType<BoxScreenHandler> BOX_SCREEN_HANDLER;
  
     static {     static {
-        BOX_BLOCK = Registry.register(Registry.BLOCK, BOX, new BoxBlock(FabricBlockSettings.copyOf(Blocks.CHEST))); +        [...] 
-        BOX_BLOCK_ITEM = Registry.register(Registry.ITEM, BOX, new BlockItem(BOX_BLOCK, new Item.Settings().group(ItemGroup.MISC))); +       
- +
-        //The parameter of build at the very end is always null, do not worry about it +
-        BOX_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, BOX, BlockEntityType.Builder.create(BoxBlockEntity::new, BOX_BLOCK).build(null)); +
-        +
         //we now use registerExtended as our screenHandler now accepts a packetByteBuf in its Constructor         //we now use registerExtended as our screenHandler now accepts a packetByteBuf in its Constructor
         BOX_SCREEN_HANDLER = ScreenHandlerRegistry.registerExtended(BOX, BoxScreenHandler::new);         BOX_SCREEN_HANDLER = ScreenHandlerRegistry.registerExtended(BOX, BoxScreenHandler::new);
Line 173: Line 167:
 } }
 </code> </code>
 +
 +====== Result ======
 +You have now seen how to transfer data when the ScreenHandler is opened. In the image you can see the result: The Blocks title is now the block position. Do note that this is just a demonstration,
 +Setting the position as the title would be possible alot easier.
 +
 +You might wonder: Can i transfer this data again even after the Screen was opened? 
 +This is possible by sending custom Packets (see: [[tutorial:networking|Networking Tutorial]]) after the Screen has been opened. \\ 
 +You might also want to have a look at the BlockEntityClientSerializable Interface from the Fabric API.
 +
 +If you only want to sync integer values you can use PropertyDelegates SEE MY NEXT TUTROIAL
 +
 +{{:tutorial:bildschirmfoto_vom_2020-08-14_18-37-51.png?nolink&400|}}
 +
  
tutorial/extendedscreenhandler.txt · Last modified: 2022/12/17 15:38 by miir