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 revisionBoth sides next revision
tutorial:containers [2020/04/02 12:57] – [Block and BlockItem] Revert BlockWithEntity change earthcomputertutorial:containers [2020/08/14 06:32] – screen handlers hell yeah. also some typo fixes leocth2
Line 113: Line 113:
  
     @Override     @Override
-    protected Container createContainer(int syncId, PlayerInventory playerInventory) {+    protected Container createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity playerEntity) {
         return new BiggerChestContainer(syncId, playerInventory, (Inventory) this);         return new BiggerChestContainer(syncId, playerInventory, (Inventory) this);
     }     }
Line 153: Line 153:
  
 ==== Container GUI and Screen ==== ==== Container GUI and Screen ====
-We need a Container Class and a ContainerScreen Class to display and sync the GUI. Container Classes are used to synchronize GUI state between the server and the client. ContainerScreen Classes are fully client-sided and are responsible for drawing GUI elements.+We need a ScreenHandler Class and a HandledScreen Class to display and sync the GUI. ScreenHandler classes are used to synchronize GUI state between the server and the client. HandledScreen classes are fully client-sided and are responsible for drawing GUI elements.
  
-<code java [enable_line_numbers="true"BiggerChestContainer.java> +<code java [enable_line_numbers="true"BiggerChestScreenHandler.java> 
-public class BiggerChestContainer extends Container {+public class BiggerChestScreenHandler extends ScreenHandler {
     private final Inventory inventory; // Chest inventory     private final Inventory inventory; // Chest inventory
     private static final int INVENTORY_SIZE = 54; // 6 rows * 9 cols     private static final int INVENTORY_SIZE = 54; // 6 rows * 9 cols
  
-    protected BiggerChestContainer(int syncId, PlayerInventory playerInventory, Inventory inventory) { +    protected BiggerChestScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory) { 
-        super(null, syncId); // Since we didn't create a ContainerType, we will place null here.+        super(null, syncId); // Since we didn't create a ScreenHandlerType, we will place null here.
         this.inventory = inventory;         this.inventory = inventory;
-        checkContainerSize(inventory, INVENTORY_SIZE); +        checkSize(inventory, INVENTORY_SIZE); 
-        inventory.onInvOpen(playerInventory.player);+        inventory.onOpen(playerInventory.player);
  
-        // Creating Slots for GUI. A Slot is essentially a correspoding from inventory itemstacks to the GUI position.+        // Creating Slots for GUI. A Slot is essentially a corresponding from inventory ItemStacks to the GUI position.
         int i;         int i;
         int j;         int j;
tutorial/containers.txt · Last modified: 2022/05/27 15:57 by solidblock