Class SyncedGuiDescription

java.lang.Object
net.minecraft.screen.ScreenHandler
io.github.cottonmc.cotton.gui.SyncedGuiDescription
All Implemented Interfaces:
GuiDescription
Direct Known Subclasses:
ItemSyncedGuiDescription

public class SyncedGuiDescription extends ScreenHandler implements GuiDescription
A screen handler-based GUI description for GUIs with slots.
  • Field Details

    • blockInventory

      protected Inventory blockInventory
    • playerInventory

      protected PlayerInventory playerInventory
    • world

      protected World world
    • propertyDelegate

      protected PropertyDelegate propertyDelegate
    • rootPanel

      protected WPanel rootPanel
    • titleColor

      protected int titleColor
    • darkTitleColor

      protected int darkTitleColor
    • fullscreen

      protected boolean fullscreen
    • titleVisible

      protected boolean titleVisible
    • titleAlignment

      protected HorizontalAlignment titleAlignment
    • focus

      protected WWidget focus
  • Constructor Details

    • SyncedGuiDescription

      public SyncedGuiDescription(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory)
      Constructs a new synced GUI description without a block inventory or a property delegate.
      Parameters:
      type - the ScreenHandlerType of this GUI description
      syncId - the current sync ID
      playerInventory - the player inventory of the player viewing this screen
    • SyncedGuiDescription

      public SyncedGuiDescription(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, @Nullable @Nullable Inventory blockInventory, @Nullable @Nullable PropertyDelegate propertyDelegate)
      Constructs a new synced GUI description.
      Parameters:
      type - the ScreenHandlerType of this GUI description
      syncId - the current sync ID
      playerInventory - the player inventory of the player viewing this screen
      blockInventory - the block inventory of a corresponding container block, or null if not found or applicable
      propertyDelegate - a property delegate whose properties, if any, will automatically be added
  • Method Details

    • getRootPanel

      public WPanel getRootPanel()
      Specified by:
      getRootPanel in interface GuiDescription
    • getTitleColor

      public int getTitleColor()
      Specified by:
      getTitleColor in interface GuiDescription
    • setRootPanel

      public SyncedGuiDescription setRootPanel(WPanel panel)
      Specified by:
      setRootPanel in interface GuiDescription
    • setTitleColor

      public SyncedGuiDescription setTitleColor(int color)
      Description copied from interface: GuiDescription
      Sets the title color of this GUI.

      The dark-mode title color will also be set by this method. If the specified color is WLabel.DEFAULT_TEXT_COLOR, the dark-mode color will be WLabel.DEFAULT_DARKMODE_TEXT_COLOR; otherwise it will be the specified color.

      Specified by:
      setTitleColor in interface GuiDescription
      Parameters:
      color - the new title color
      Returns:
      this GUI
    • setTitleColor

      public SyncedGuiDescription setTitleColor(int lightColor, int darkColor)
      Description copied from interface: GuiDescription
      Sets the light and dark title colors of this GUI.
      Specified by:
      setTitleColor in interface GuiDescription
      Parameters:
      lightColor - the light-mode color
      darkColor - the dark-mode color
      Returns:
      this GUI
    • addPainters

      @Environment(CLIENT) public void addPainters()
      Description copied from interface: GuiDescription
      Guis should use this method to add clientside styles and BackgroundPainters to their controls
      Specified by:
      addPainters in interface GuiDescription
    • addSlotPeer

      public void addSlotPeer(ValidatedSlot slot)
      Description copied from interface: GuiDescription
      Typical users won't call this. This adds a Slot to Container/Controller-based guis, and does nothing on lightweight guis.
      Specified by:
      addSlotPeer in interface GuiDescription
    • quickMove

      public ItemStack quickMove(PlayerEntity player, int index)
      Specified by:
      quickMove in class ScreenHandler
    • getPropertyDelegate

      @Nullable public @Nullable PropertyDelegate getPropertyDelegate()
      Description copied from interface: GuiDescription
      Gets the object which manages the integer properties used by WBars and such.
      Specified by:
      getPropertyDelegate in interface GuiDescription
    • setPropertyDelegate

      public GuiDescription setPropertyDelegate(PropertyDelegate delegate)
      Description copied from interface: GuiDescription
      Sets the object which manages the integer properties used by WBars
      Specified by:
      setPropertyDelegate in interface GuiDescription
    • createPlayerInventoryPanel

      public WPlayerInvPanel createPlayerInventoryPanel()
      Creates a player inventory widget from this panel's player inventory.
      Returns:
      the created inventory widget
    • createPlayerInventoryPanel

      public WPlayerInvPanel createPlayerInventoryPanel(boolean hasLabel)
      Creates a player inventory widget from this panel's player inventory.
      Parameters:
      hasLabel - whether the "Inventory" label should be displayed
      Returns:
      the created inventory widget
      Since:
      2.0.0
    • createPlayerInventoryPanel

      public WPlayerInvPanel createPlayerInventoryPanel(WWidget label)
      Creates a player inventory widget from this panel's player inventory.
      Parameters:
      label - the inventory label widget
      Returns:
      the created inventory widget
      Since:
      2.0.0
    • getBlockInventory

      public static Inventory getBlockInventory(ScreenHandlerContext ctx)
      Gets the block inventory at the context.

      If no inventory is found, returns EmptyInventory.INSTANCE.

      Searches for these implementations in the following order:

      1. Blocks implementing InventoryProvider
      2. Block entities implementing InventoryProvider
      3. Block entities implementing Inventory
      Parameters:
      ctx - the context
      Returns:
      the found inventory
    • getBlockInventory

      public static Inventory getBlockInventory(ScreenHandlerContext ctx, int size)
      Gets the block inventory at the context.

      If no inventory is found, returns a simple mutable inventory with the specified number of slots.

      Searches for these implementations in the following order:

      1. Blocks implementing InventoryProvider
      2. Block entities implementing InventoryProvider
      3. Block entities implementing Inventory
      Parameters:
      ctx - the context
      size - the fallback inventory size
      Returns:
      the found inventory
      Since:
      2.0.0
    • getBlockPropertyDelegate

      public static PropertyDelegate getBlockPropertyDelegate(ScreenHandlerContext ctx)
      Gets the property delegate at the context.

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

      Searches for block entities implementing PropertyDelegateHolder.

      Parameters:
      ctx - the context
      Returns:
      the found property delegate
    • getBlockPropertyDelegate

      public static PropertyDelegate getBlockPropertyDelegate(ScreenHandlerContext ctx, int size)
      Gets the property delegate at the context.

      If no property delegate is found, returns an array property delegate with the specified number of properties.

      Searches for block entities implementing PropertyDelegateHolder.

      Parameters:
      ctx - the context
      size - the number of properties
      Returns:
      the found property delegate
      Since:
      2.0.0
    • canUse

      public boolean canUse(PlayerEntity entity)
      Specified by:
      canUse in class ScreenHandler
    • onClosed

      public void onClosed(PlayerEntity player)
      Overrides:
      onClosed in class ScreenHandler
    • isFocused

      public boolean isFocused(WWidget widget)
      Description copied from interface: GuiDescription
      Tests whether the widget is the currently-focused one.
      Specified by:
      isFocused in interface GuiDescription
    • getFocus

      public WWidget getFocus()
      Description copied from interface: GuiDescription
      Gets the currently-focused WWidget. May be null.
      Specified by:
      getFocus in interface GuiDescription
    • requestFocus

      public void requestFocus(WWidget widget)
      Description copied from interface: GuiDescription
      Notifies this gui that the widget wants to acquire focus.
      Specified by:
      requestFocus in interface GuiDescription
    • releaseFocus

      public void releaseFocus(WWidget widget)
      Description copied from interface: GuiDescription
      Notifies this gui that the widget wants to give up its hold over focus.
      Specified by:
      releaseFocus in interface GuiDescription
    • isFullscreen

      public boolean isFullscreen()
      Description copied from interface: GuiDescription
      Gets whether this GUI is fullscreen.

      Fullscreen GUIs have no default background painter and have the root panel stretched to fit the entire screen on the client.

      Specified by:
      isFullscreen in interface GuiDescription
      Returns:
      true if this GUI is fullscreen, false otherwise
    • setFullscreen

      public void setFullscreen(boolean fullscreen)
      Description copied from interface: GuiDescription
      Sets whether this GUI is fullscreen.
      Specified by:
      setFullscreen in interface GuiDescription
      Parameters:
      fullscreen - true if this GUI is fullscreen, false otherwise
    • isTitleVisible

      public boolean isTitleVisible()
      Description copied from interface: GuiDescription
      Gets whether the title of this GUI should be rendered by the screen.

      Modders can disable this to render the title themselves with a widget.

      Specified by:
      isTitleVisible in interface GuiDescription
      Returns:
      true if the title is visible, false otherwise
    • setTitleVisible

      public void setTitleVisible(boolean titleVisible)
      Description copied from interface: GuiDescription
      Sets whether the title of this GUI should be rendered by the screen.
      Specified by:
      setTitleVisible in interface GuiDescription
      Parameters:
      titleVisible - true if the title is visible, false otherwise
    • getTitleAlignment

      public HorizontalAlignment getTitleAlignment()
      Description copied from interface: GuiDescription
      Gets the horizontal alignment of the GUI title.
      Specified by:
      getTitleAlignment in interface GuiDescription
      Returns:
      the alignment
    • setTitleAlignment

      public void setTitleAlignment(HorizontalAlignment titleAlignment)
      Description copied from interface: GuiDescription
      Sets the horizontal alignment of the GUI title.
      Specified by:
      setTitleAlignment in interface GuiDescription
      Parameters:
      titleAlignment - the new alignment
    • getTitlePos

      public Vec2i getTitlePos()
      Description copied from interface: GuiDescription
      Gets the position of the screen title.
      Specified by:
      getTitlePos in interface GuiDescription
      Returns:
      the title position
    • setTitlePos

      public void setTitlePos(Vec2i titlePos)
      Description copied from interface: GuiDescription
      Sets the position of the screen title.
      Specified by:
      setTitlePos in interface GuiDescription
      Parameters:
      titlePos - the new title position
    • getWorld

      public World getWorld()
      Returns the world of this GUI description's player.
      Returns:
      the world of this GUI description's player
      Since:
      10.0.0
    • getNetworkSide

      public final NetworkSide getNetworkSide()
      Gets the network side this GUI description runs on.
      Returns:
      this GUI's network side
      Since:
      3.3.0
    • getPacketSender

      public final net.fabricmc.fabric.api.networking.v1.PacketSender getPacketSender()
      Gets the packet sender corresponding to this GUI's network side.
      Returns:
      the packet sender
      Since:
      3.3.0