private ItemStack[] getItemsForPage() {
        ItemStack[] pageItems = pages.get(Math.max(getCurrentPage(), 0));
        int pageSize = pageItems.length;
        if (pages.size() > 1 || this.getExitInventory() != null) {
            pageSize += 9;
        }
        if (!this.dynamicInventorySize || isPlayerInventory()) {
            pageSize = isPlayerInventory() ? 36 : inventorySize;
        } else {
            pageSize = (int) (((pageSize + 8) / 9) * 9);
        }
        pageItems = Arrays.copyOf(pageItems, pageSize);
        if (getCurrentPage() > 0 || getExitInventory() != null) {
            pageItems[pageItems.length - 9] = getCurrentPage() == 0 ? getExitInventory() : getBackPage();
        }
        if (pages.size() - 1 > getCurrentPage()) {
            pageItems[pageItems.length - 1] = getForwardsPage();
        }
        return pageItems;
    }