aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java22
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java40
2 files changed, 60 insertions, 2 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java b/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
index 272d251..cbefb7a 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
@@ -336,6 +336,28 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr
}
/**
+ * Creates a player inventory widget from this panel's {@linkplain #playerInventory player inventory}.
+ *
+ * @param hasTitle whether the "Inventory" title should be displayed
+ * @return the created inventory widget
+ * @since 2.0.0
+ */
+ public WPlayerInvPanel createPlayerInventoryPanel(boolean hasTitle) {
+ return new WPlayerInvPanel(this.playerInventory, hasTitle);
+ }
+
+ /**
+ * Creates a player inventory widget from this panel's {@linkplain #playerInventory player inventory}.
+ *
+ * @param title the inventory title widget
+ * @return the created inventory widget
+ * @since 2.0.0
+ */
+ public WPlayerInvPanel createPlayerInventoryPanel(WWidget title) {
+ return new WPlayerInvPanel(this.playerInventory, title);
+ }
+
+ /**
* Gets the block inventory at the context.
*
* <p>If no inventory is found, returns {@link EmptyInventory#INSTANCE}.
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java
index 47df88f..198c708 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java
@@ -5,6 +5,8 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.entity.player.PlayerInventory;
+import javax.annotation.Nullable;
+
/**
* A player inventory widget that has a visually separate hotbar.
*/
@@ -12,11 +14,45 @@ public class WPlayerInvPanel extends WPlainPanel {
private final WItemSlot inv;
private final WItemSlot hotbar;
+ /**
+ * Constructs a player inventory panel with a title.
+ *
+ * @param playerInventory the player inventory
+ */
public WPlayerInvPanel(PlayerInventory playerInventory) {
+ this(playerInventory, true);
+ }
+
+ /**
+ * Constructs a player inventory panel.
+ *
+ * @param playerInventory the player inventory
+ * @param hasTitle whether there should be an "Inventory" title
+ * @since 2.0.0
+ */
+ public WPlayerInvPanel(PlayerInventory playerInventory, boolean hasTitle) {
+ this(playerInventory, hasTitle ? new WLabel(playerInventory.getDisplayName()) : null);
+ }
+
+ /**
+ * Constructs a player inventory panel.
+ *
+ * @param playerInventory the player inventory
+ * @param title the title widget, can be null
+ * @since 2.0.0
+ */
+ public WPlayerInvPanel(PlayerInventory playerInventory, @Nullable WWidget title) {
+ int y = 0;
+
+ if (title != null) {
+ this.add(title, 0, 0, 9*18, 11);
+ y += title.getHeight();
+ }
+
inv = WItemSlot.ofPlayerStorage(playerInventory);
hotbar = WItemSlot.of(playerInventory, 0, 9, 1);
- this.add(inv, 0, 0);
- this.add(hotbar, 0, 58);
+ this.add(inv, 0, y);
+ this.add(hotbar, 0, y + 58);
}
/**