Skip to content

Dropdown Menu

shedaniel edited this page Jan 4, 2020 · 1 revision

Start by doing entryBuilder.startDropdownMenu(), the SelectionTopCellElement is the search bar, and SelectionCellCreator is the cells below.

Create a SelectionTopCellElement with DropdownMenuBuilder.TopCellElementBuilder.of(), which takes three parameters:

  • value: The value of the field
  • toObjectFunction: The toObject function, turning String into T, returns null if error
  • toStringFunction: The toString function, which never returns null, affects the displayed text of your value.

You can also use the premade SelectionTopCellElement for items and blocks.

Create a SelectionCellCreator with DropdownMenuBuilder.CellCreatorBuilder.of(), which defines the cell height, the cell width, and how many cells are displayed at most.

  • toStringFunction: The toString function, which never returns null, affects the displayed text of the cell.

You can also use the premade SelectionCellCreator for items and blocks as well.

You should create your own cell creator extending the DefaultSelectionCellCreator to create custom cells.

Do .setSelections() with your builder to specify the list of suggestions.

This is what you should do if you got a config for items:

entryBuilder.startDropdownMenu("Field Key", 
    DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(configItem), // This should contain your saved item instead of an apple as shown here 
    DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()
)
    .setDefaultValue(Items.APPLE) // You should define a default value here
    .setSelections(Registry.ITEM.stream().collect(Collectors.toSet()))
    .setSaveConsumer(item -> configItem = (Item) item) // You should save it here, cast the item because Java is "smart"
    .build();
Clone this wiki locally