Skip to content

Commit

Permalink
add inventory api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Charismara committed Sep 5, 2024
1 parent 4236719 commit 6cffde9
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
File renamed without changes.
59 changes: 59 additions & 0 deletions docs/inventory/02-creating-a-tab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Tabs
Tabs are a great way to make your Containers available to players by showing a CreativeTab-like Button in the Players Inventory.

## Creating a Tab
To create a Tab, your need to create a new class that extends `AbstractInventoryTab`.

```java
public class TestInventoryTab extends AbstractInventoryTab {
private final ItemStack iconStack;

public TestInventoryTab(Item icon) {
super(Tooltip.create(Component.literal("Test Tab - " + index)));
this.iconStack = icon.getDefaultInstance();
}

@Override
protected void renderIcon(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
var isTopRow = this.getCurrentTabIndex() < TABS_PER_ROW;
guiGraphics.renderFakeItem(this.iconStack, this.getX() + 5, this.getY() + 8 + (isTopRow ? 1 : -1));
}

@Override
public void sendOpenContainerPacket() {
// Send a packet to the server to request the container to be opened
}
}
```

The newly created Tab now needs to be registered.

### Architectury
```java
ClientLifecycleEvent.CLIENT_SETUP.register(instance -> InventoryTabsTest.init(19));
```
### Fabric
```java
ClientLifecycleEvents.CLIENT_STARTED.register(minecraft -> InventoryTabs.registerTab(new InventoryTabsTest.TestInventoryTab(Items.DIAMOND)));
```
### NeoForge
```java
// On NeoForge
private void clientInit(FMLClientSetupEvent e) {
InventoryTabs.registerTab(new InventoryTabsTest.TestInventoryTab(Items.DIAMOND));
}
```

## Showing Tabs in your Container
To show the Tab in your Container, you need to implement the `InventoryTabScreen` in your ContainerScreen class.

```java
public class CustomContainerScreen<T> extends AbstractContainerScreen<T> implements InventoryTabScreen {
private static final Class<TestInventoryTab> TAB_CLASS = TestInventoryTab.class;

@Override
public Class<TestInventoryTab> getTabClass() {
return TAB_CLASS;
}
}
```
4 changes: 4 additions & 0 deletions docs/inventory/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Inventory",
"position": 1
}
11 changes: 11 additions & 0 deletions docs/network/01-Installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Architectury

tbd

## Fabric

tbd

## NeoForge

tbd
4 changes: 0 additions & 4 deletions docs/network/getting-started/_category_.json

This file was deleted.

0 comments on commit 6cffde9

Please sign in to comment.