public class BoxBlockEntity extends BlockEntity implements NamedScreenHandlerFactory, ImplementedInventory { private final DefaultedList inventory = DefaultedList.ofSize(9, ItemStack.EMPTY); public BoxBlockEntity() { super(ExampleMod.BOX_BLOCK_ENTITY); } //From the ImplementedInventory Interface @Override public DefaultedList getItems() { return inventory; } //These Methods are from the NamedScreenHandlerFactory Interface //createMenu creates the ScreenHandler itself //getDisplayName will Provide its name which is normally shown at the top @Override public ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player) { //We provide *this* to the screenHandler as our class Implements Inventory //Only the Server has the Inventory at the start, this will be synced to the client in the ScreenHandler return new BoxScreenHandler(syncId, playerInventory, this); } @Override public Text getDisplayName() { return new TranslatableText(getCachedState().getBlock().getTranslationKey()); } @Override public void fromTag(BlockState state, CompoundTag tag) { super.fromTag(state, tag); Inventories.fromTag(tag, this.inventory); } @Override public CompoundTag toTag(CompoundTag tag) { super.toTag(tag); Inventories.toTag(tag, this.inventory); return tag; } }