From e4ee59927279e9a7e42fa249e573408e46dfc904 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Sat, 16 May 2020 18:36:43 +0300 Subject: Docs --- .../cotton/gui/CottonInventoryController.java | 36 ++++++++++++++++++++-- .../cottonmc/cotton/gui/widget/WItemSlot.java | 9 +++++- .../cotton/gui/widget/WPlayerInvPanel.java | 16 ++++++++-- 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. + * + *

If no inventory is found, returns {@link EmptyInventory#INSTANCE}. + * + *

Searches for these implementations in the following order: + *

    + *
  1. Blocks implementing {@code InventoryProvider}
  2. + *
  3. Block entities implementing {@code InventoryProvider}
  4. + *
  5. Block entities implementing {@code Inventory}
  6. + *
+ * + * @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. + * + *

If no property delegate is found, returns an empty property delegate with no properties. + * + *

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); -- cgit