User Tools

Site Tools


tutorial:containers

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:containers [2020/02/27 13:46] – typo mkpolitutorial:containers [2020/02/27 16:34] – adjusment mkpoli
Line 3: Line 3:
  
 ==== Block and BlockItem ==== ==== Block and BlockItem ====
-First we need to create Block and register it as well as its BlockItem.+First we need to create the Block and register it as well as its BlockItem.
  
 <code java [enable_line_numbers="true"] BiggerChestBlock.java> <code java [enable_line_numbers="true"] BiggerChestBlock.java>
Line 84: Line 84:
 } }
 </code> </code>
 +
 +You may refer to other tutorials to modify the appearance and other properties of the Block by adding models or adjusting rendering later.
  
 ==== BlockEntity ==== ==== BlockEntity ====
-BlockEntities are used for managing container inventories. Actually, it implements Inventory interface.+BlockEntity is used for managing container inventories. Actually, it implements Inventory interface. It is required to save and load the inventory.
  
 <code java [enable_line_numbers="true"] BiggerChestBlockEntity.java> <code java [enable_line_numbers="true"] BiggerChestBlockEntity.java>
Line 252: Line 254:
         [...]         [...]
         ContainerProviderRegistry.INSTANCE.registerFactory(BIGGER_CHEST, (syncId, identifier, player, buf) -> {         ContainerProviderRegistry.INSTANCE.registerFactory(BIGGER_CHEST, (syncId, identifier, player, buf) -> {
-            final BlockEntity blockEntity = player.world.getBlockEntity(buf.readBlockPos()); +            final World world = player.world
-            return((BiggerChestBlockEntityblockEntity).createContainer(syncId, player.inventory);+            final BlockPos pos = buf.readBlockPos(); 
 +            return world.getBlockState(pos).createContainerFactory(player.world, pos).createMenu(syncId, player.inventory, player);
         });         });
     }     }
Line 265: Line 268:
 </code> </code>
  
-==== Orgnizing ====+==== Organizing ====
 After all the steps, you should have your ExampleMod Class and ExampleClientMod Class as such: After all the steps, you should have your ExampleMod Class and ExampleClientMod Class as such:
  
tutorial/containers.txt · Last modified: 2022/05/27 15:57 by solidblock