Skip to content

Scroll GUI

A Scroll GUI allows you to scroll through a list of items line by line. This can be done both vertically and horizontally.

Control Items

Before creating the Scroll GUI itself, you first need to create the Items for navigating it.

This would be an example for an Item that scrolls down:

class ScrollDownItem : ScrollItem(1) {

    override fun getItemProvider(gui: ScrollGui<*>): ItemProvider {
        val builder = ItemBuilder(Material.GREEN_STAINED_GLASS_PANE)
        builder.setDisplayName("Scroll down")
        if (!gui.canScroll(1))
            builder.addLoreLines("You can't scroll further down")
        return builder
    }

}
public class ScrollDownItem extends ScrollItem {

    public ScrollDownItem() {
        super(1);
    }

    @Override
    public ItemProvider getItemProvider(ScrollGui<?> gui) {
        ItemBuilder builder = new ItemBuilder(Material.GREEN_STAINED_GLASS_PANE);
        builder.setDisplayName("Scroll down");
        if (!gui.canScroll(1))
            builder.addLoreLines("You can't scroll further down");

        return builder;
    }

}

And this Item scrolls up:

class ScrollUpItem : ScrollItem(-1) {

    override fun getItemProvider(gui: ScrollGui<*>): ItemProvider {
        val builder = ItemBuilder(Material.RED_STAINED_GLASS_PANE)
        builder.setDisplayName("Scroll up")
        if (!gui.canScroll(-1))
            builder.addLoreLines("You've reached the top")
        return builder
    }

}
    public class ScrollUpItem extends ScrollItem {

    public ScrollUpItem() {
        super(-1);
    }

    @Override
    public ItemProvider getItemProvider(ScrollGui<?> gui) {
        ItemBuilder builder = new ItemBuilder(Material.RED_STAINED_GLASS_PANE);
        builder.setDisplayName("Scroll up");
        if (!gui.canScroll(-1))
            builder.addLoreLines("You've reached the top");

        return builder;
    }

}

Info

You also might want to register these Items as global ingredients.

Creating the GUI

Scroll Items

Now that we've created the ControlItems, let's make the actual GUI:

val border = SimpleItem(ItemBuilder(Material.BLACK_STAINED_GLASS_PANE).setDisplayName(""))

// an example list of items to display
val items = Material.values()
    .filter { !it.isAir && it.isItem }
    .map { SimpleItem(ItemBuilder(it)) }

val gui = ScrollGui.items()
    .setStructure(
        "x x x x x x x x u",
        "x x x x x x x x #",
        "x x x x x x x x #",
        "x x x x x x x x #",
        "x x x x x x x x d")
    .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
    .addIngredient('#', border)
    .addIngredient('u', ScrollUpItem())
    .addIngredient('d', ScrollDownItem())
    .setContent(items)
    .build()
Item border = new SimpleItem(new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE).setDisplayName(""));

// an example list of items to display
List<Item> items = Arrays.stream(Material.values())
    .filter(material -> !material.isAir() && material.isItem())
    .map(material -> new SimpleItem(new ItemBuilder(material)))
    .collect(Collectors.toList());

Gui gui = ScrollGui.items()
    .setStructure(
        "x x x x x x x x u",
        "x x x x x x x x #",
        "x x x x x x x x #",
        "x x x x x x x x #",
        "x x x x x x x x d")
    .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
    .addIngredient('#', border)
    .addIngredient('u', new ScrollUpItem())
    .addIngredient('d', new ScrollDownItem())
    .setContent(items)
    .build();

And this is how it looks in-game:

You can also change the scroll direction by using Markers.CONTENT_LIST_SLOT_VERTICAL instead of Markers.CONTENT_LIST_SLOT_HORIZONTAL. This would result in the gui scrolling from left to right:

Info

If you need even more control over the scroll direction, you'll need to set the itemListSlots yourself by calling the ScrollGui.of method.

ScrollGui<Gui> & ScrollGui<VirtualInventory>

There are two additional Scroll GUI types available: ScrollGui.guis() and ScrollGui.inventories(). They behave in a very similar way to ScrollGui.items(), but instead of Items, they accept GUIs or Inventories. For the case of ScrollGui<Gui>, you'll want to make sure that the width of the GUIs matches the line size of your Scroll GUI.