public class BoxScreenHandler extends ScreenHandler { //We save the blockPos we got from the Server and provide a getter for it so the BoxScreen can read that information private BlockPos pos; 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 super constructor with an empty Inventory and the screenHandler will automatically //sync this empty inventory with the inventory on the server //NEW: The constructor of the client now gets the PacketByteBuf we filled in the BlockEntity public BoxScreenHandler(int syncId, PlayerInventory playerInventory, PacketByteBuf buf) { this(syncId, playerInventory, new SimpleInventory(9)); pos = buf.readBlockPos(); } //This constructor gets called from the BlockEntity on the server, 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) { //[...] // See first Screenhandler Tutorial for the rest of the code //Why do we use BlockPos.ORIGIN here? //This is because the packetByteBuf with our blockPosition is only availible on the Client, so we need a placeholder //value here. This is not a problem however, as the Server version of the ScreenHandler does not really need this //information. pos = BlockPos.ORIGIN; [...] } //this getter will be used by our Screen class public BlockPos getPos() { return pos; } @Override public boolean canUse(PlayerEntity player) { return this.inventory.canPlayerUse(player); } // See Screenhandler Tutorial // Shift + Player Inv Slot @Override public ItemStack transferSlot(PlayerEntity player, int invSlot); }