Skip to content

Update README.md #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,93 @@
# MenuAPI

MenuAPI is a Java library designed for creating and managing interactive and dynamic menus in applications using Minecraft. This API includes advanced features such as pagination, decorators, editors, and interactive items.

## Key Features

- **Pagination**: Efficiently manage large numbers of items with a paging system.
- **Decorators**: Add aesthetic elements to your menus.
- **Editors**: Dynamically modify menu content.
- **Interactive Slots**: Create slots linked to another inventory or interactive items.

## Examples

### Example of a menu with pagination, decoration, and interactive slots

The following example demonstrates a menu utilizing multiple features of the API.

```java
private static class ExampleMenu extends Menu {

public ExampleMenu(Inventory inventory) {
super(Component.text("Example menu"), 5);

// Adding decoration to the menu
decorate(MenuDecoration.flat(new ItemStack(Material.GRAY_STAINED_GLASS_PANE)));

// Setting up pagination
MenuPagination pagination = MenuPagination.full(this);
for (int i = 0; i < 100; i++) {
ItemStack itemStack = new ItemStack(Material.STONE, i + 1);
itemStack.setData(DataComponentTypes.MAX_STACK_SIZE, Math.min(99, i + 1));
pagination.addItem(new ForbiddenSlot(itemStack));
}
registerEditor(pagination);

// Slots linked to another inventory
setSlot(4, new InventorySlot(inventory, 0));
setSlot(5, new InventorySlot(inventory, 1));

// Interactive item
setSlot(9 * 4 - 1, new MenuItem(new ItemStack(Material.BARRIER)) {
@Override
public void click(Click click) {
click.player().closeInventory();
}
});
}
}
```

### Decorators

Decorators allow you to add aesthetic elements to your menus. In the example above, `MenuDecoration.flat` is used to fill menu slots with gray stained glass panes.

```java
decorate(MenuDecoration.flat(new ItemStack(Material.GRAY_STAINED_GLASS_PANE)));
```

### Pagination

Pagination simplifies the management of a large number of items in a menu. It automatically divides items into multiple pages.

```java
MenuPagination pagination = MenuPagination.full(this);
for (int i = 0; i < 100; i++) {
ItemStack itemStack = new ItemStack(Material.STONE, i + 1);
itemStack.setData(DataComponentTypes.MAX_STACK_SIZE, Math.min(99, i + 1));
pagination.addItem(new ForbiddenSlot(itemStack));
}
registerEditor(pagination);
```

### Slots Linked to Another Inventory

Slots can be linked to specific positions in another inventory, allowing direct interaction between multiple menus or inventories.

```java
setSlot(4, new InventorySlot(inventory, 0));
setSlot(5, new InventorySlot(inventory, 1));
```

### Interactive Items

Interactive items define actions to be executed upon interaction, such as a button to close an inventory:

```java
setSlot(9 * 4 - 1, new MenuItem(new ItemStack(Material.BARRIER)) {
@Override
public void click(Click click) {
click.player().closeInventory();
}
});
```