-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4236719
commit 6cffde9
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"label": "Inventory", | ||
"position": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Architectury | ||
|
||
tbd | ||
|
||
## Fabric | ||
|
||
tbd | ||
|
||
## NeoForge | ||
|
||
tbd |
This file was deleted.
Oops, something went wrong.