public class BoxScreenHandler extends ScreenHandler { private final Inventory inventory; //This constructor gets called on the client when the server wants it to open the screenHandler, //The client will call the other constructor with an empty Inventory and the screenHandler will automatically //sync this empty inventory with the inventory on the server. public BoxScreenHandler(int syncId, PlayerInventory playerInventory) { this(syncId, playerInventory, new SimpleInventory(9)); } //This constructor gets called from the BlockEntity on the server without calling the other constructor first, the server knows the inventory of the container //and can therefore directly provide it as an argument. This inventory will then be synced to the client. public BoxScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory) { super(ExampleMod.BOX_SCREEN_HANDLER, syncId); checkSize(inventory, 9); this.inventory = inventory; //some inventories do custom logic when a player opens it. inventory.onOpen(playerInventory.player); //This will place the slot in the correct locations for a 3x3 Grid. The slots exist on both server and client! //This will not render the background of the slots however, this is the Screens job int m; int l; //Our inventory for (m = 0; m < 3; ++m) { for (l = 0; l < 3; ++l) { this.addSlot(new Slot(inventory, l + m * 3, 62 + l * 18, 17 + m * 18)); } } //The player inventory for (m = 0; m < 3; ++m) { for (l = 0; l < 9; ++l) { this.addSlot(new Slot(playerInventory, l + m * 9 + 9, 8 + l * 18, 84 + m * 18)); } } //The player Hotbar for (m = 0; m < 9; ++m) { this.addSlot(new Slot(playerInventory, m, 8 + m * 18, 142)); } } @Override public boolean canUse(PlayerEntity player) { return this.inventory.canPlayerUse(player); } // Shift + Player Inv Slot @Override public ItemStack quickMove(PlayerEntity player, int invSlot) { ItemStack newStack = ItemStack.EMPTY; Slot slot = this.slots.get(invSlot); if (slot != null && slot.hasStack()) { ItemStack originalStack = slot.getStack(); newStack = originalStack.copy(); if (invSlot < this.inventory.size()) { if (!this.insertItem(originalStack, this.inventory.size(), this.slots.size(), true)) { return ItemStack.EMPTY; } } else if (!this.insertItem(originalStack, 0, this.inventory.size(), false)) { return ItemStack.EMPTY; } if (originalStack.isEmpty()) { slot.setStack(ItemStack.EMPTY); } else { slot.markDirty(); } } return newStack; } }