aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2020-05-16 18:36:43 +0300
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2020-05-16 18:36:43 +0300
commite4ee59927279e9a7e42fa249e573408e46dfc904 (patch)
tree438c2f84ab7e8a3db880373be64212dedb22a12e
parent6193eed0443598782e053e3d14f1e5bcdbe81485 (diff)
downloadLibGui-e4ee59927279e9a7e42fa249e573408e46dfc904.tar.gz
LibGui-e4ee59927279e9a7e42fa249e573408e46dfc904.tar.bz2
LibGui-e4ee59927279e9a7e42fa249e573408e46dfc904.zip
Docs
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java36
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java9
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WPlayerInvPanel.java16
3 files changed, 55 insertions, 6 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 21a1dcb..272d251 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java
@@ -325,11 +325,31 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr
this.propertyDelegate = delegate;
return this;
}
-
+
+ /**
+ * Creates a player inventory widget from this panel's {@linkplain #playerInventory player inventory}.
+ *
+ * @return the created inventory widget
+ */
public WPlayerInvPanel createPlayerInventoryPanel() {
return new WPlayerInvPanel(this.playerInventory);
}
-
+
+ /**
+ * Gets the block inventory at the context.
+ *
+ * <p>If no inventory is found, returns {@link EmptyInventory#INSTANCE}.
+ *
+ * <p>Searches for these implementations in the following order:
+ * <ol>
+ * <li>Blocks implementing {@code InventoryProvider}</li>
+ * <li>Block entities implementing {@code InventoryProvider}</li>
+ * <li>Block entities implementing {@code Inventory}</li>
+ * </ol>
+ *
+ * @param ctx the context
+ * @return the found inventory
+ */
public static Inventory getBlockInventory(ScreenHandlerContext ctx) {
return ctx.run((world, pos) -> {
BlockState state = world.getBlockState(pos);
@@ -357,7 +377,17 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr
return EmptyInventory.INSTANCE;
}).orElse(EmptyInventory.INSTANCE);
}
-
+
+ /**
+ * Gets the property delegate at the context.
+ *
+ * <p>If no property delegate is found, returns an empty property delegate with no properties.
+ *
+ * <p>Searches for blocks and block entities implementing {@link PropertyDelegateHolder}.
+ *
+ * @param ctx the context
+ * @return the found property delegate
+ */
public static PropertyDelegate getBlockPropertyDelegate(ScreenHandlerContext ctx) {
return ctx.run((world, pos) -> {
BlockState state = world.getBlockState(pos);
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java
index 7e25cb1..06bac2e 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java
@@ -61,7 +61,14 @@ public class WItemSlot extends WWidget {
return w;
}
-
+
+ /**
+ * Creates a 9x3 slot widget from the "main" part of a player inventory.
+ *
+ * @param inventory the player inventory
+ * @return the created slot widget
+ * @see WPlayerInvPanel
+ */
public static WItemSlot ofPlayerStorage(Inventory inventory) {
WItemSlot w = new WItemSlot();
w.inventory = inventory;
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 0fda576..47df88f 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
@@ -1,11 +1,16 @@
package io.github.cottonmc.cotton.gui.widget;
import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
import net.minecraft.entity.player.PlayerInventory;
+/**
+ * A player inventory widget that has a visually separate hotbar.
+ */
public class WPlayerInvPanel extends WPlainPanel {
- private WItemSlot inv;
- private WItemSlot hotbar;
+ private final WItemSlot inv;
+ private final WItemSlot hotbar;
public WPlayerInvPanel(PlayerInventory playerInventory) {
inv = WItemSlot.ofPlayerStorage(playerInventory);
@@ -14,6 +19,13 @@ public class WPlayerInvPanel extends WPlainPanel {
this.add(hotbar, 0, 58);
}
+ /**
+ * Sets the background painter of this inventory widget's slots.
+ *
+ * @param painter the new painter
+ * @return this panel
+ */
+ @Environment(EnvType.CLIENT)
@Override
public WPanel setBackgroundPainter(BackgroundPainter painter) {
super.setBackgroundPainter(null);