diff options
Diffstat (limited to 'src')
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); |