Class SyncedGuiDescription

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

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

    Fields
    Modifier and Type
    Field
    Description
    protected net.minecraft.inventory.Inventory
     
    protected int
     
    protected WWidget
     
    protected boolean
     
    protected net.minecraft.entity.player.PlayerInventory
     
    protected net.minecraft.screen.PropertyDelegate
     
    protected WPanel
     
     
    protected int
     
    protected boolean
     
    protected net.minecraft.world.World
     

    Fields inherited from class net.minecraft.screen.ScreenHandler

    EMPTY_SPACE_SLOT_INDEX, field_30731, field_30732, field_30733, field_30734, field_30735, field_30736, field_30737, slots, syncId
  • Constructor Summary

    Constructors
    Constructor
    Description
    SyncedGuiDescription(net.minecraft.screen.ScreenHandlerType<?> type, int syncId, net.minecraft.entity.player.PlayerInventory playerInventory)
    Constructs a new synced GUI description without a block inventory or a property delegate.
    SyncedGuiDescription(net.minecraft.screen.ScreenHandlerType<?> type, int syncId, net.minecraft.entity.player.PlayerInventory playerInventory, @Nullable net.minecraft.inventory.Inventory blockInventory, @Nullable net.minecraft.screen.PropertyDelegate propertyDelegate)
    Constructs a new synced GUI description.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Guis should use this method to add clientside styles and BackgroundPainters to their controls
    void
    Typical users won't call this.
    boolean
    canUse(net.minecraft.entity.player.PlayerEntity entity)
     
    void
    close(net.minecraft.entity.player.PlayerEntity player)
     
    Creates a player inventory widget from this panel's player inventory.
    createPlayerInventoryPanel(boolean hasLabel)
    Creates a player inventory widget from this panel's player inventory.
    Creates a player inventory widget from this panel's player inventory.
    static net.minecraft.inventory.Inventory
    getBlockInventory(net.minecraft.screen.ScreenHandlerContext ctx)
    Gets the block inventory at the context.
    static net.minecraft.inventory.Inventory
    getBlockInventory(net.minecraft.screen.ScreenHandlerContext ctx, int size)
    Gets the block inventory at the context.
    static net.minecraft.screen.PropertyDelegate
    getBlockPropertyDelegate(net.minecraft.screen.ScreenHandlerContext ctx)
    Gets the property delegate at the context.
    static net.minecraft.screen.PropertyDelegate
    getBlockPropertyDelegate(net.minecraft.screen.ScreenHandlerContext ctx, int size)
    Gets the property delegate at the context.
    Gets the currently-focused WWidget.
    Gets the network side this GUI description runs on.
    final net.fabricmc.fabric.api.networking.v1.PacketSender
    Gets the packet sender corresponding to this GUI's network side.
    @Nullable net.minecraft.screen.PropertyDelegate
    Gets the object which manages the integer properties used by WBars and such.
     
    Gets the horizontal alignment of the GUI title.
    int
     
    Gets the position of the screen title.
    boolean
    Tests whether the widget is the currently-focused one.
    boolean
    Gets whether this GUI is fullscreen.
    boolean
    Gets whether the title of this GUI should be rendered by the screen.
    void
    onSlotClick(int slotIndex, int button, net.minecraft.screen.slot.SlotActionType actionType, net.minecraft.entity.player.PlayerEntity player)
     
    void
    Notifies this gui that the widget wants to give up its hold over focus.
    void
    Notifies this gui that the widget wants to acquire focus.
    void
    setFullscreen(boolean fullscreen)
    Sets whether this GUI is fullscreen.
    setPropertyDelegate(net.minecraft.screen.PropertyDelegate delegate)
    Sets the object which manages the integer properties used by WBars
     
    void
    Sets the horizontal alignment of the GUI title.
    setTitleColor(int color)
    Sets the title color of this GUI.
    setTitleColor(int lightColor, int darkColor)
    Sets the light and dark title colors of this GUI.
    void
    setTitlePos(Vec2i titlePos)
    Sets the position of the screen title.
    void
    setTitleVisible(boolean titleVisible)
    Sets whether the title of this GUI should be rendered by the screen.
    net.minecraft.item.ItemStack
    transferSlot(net.minecraft.entity.player.PlayerEntity player, int index)
     

    Methods inherited from class net.minecraft.screen.ScreenHandler

    addListener, addProperties, addProperty, addSlot, calculateComparatorOutput, calculateComparatorOutput, calculateStackSize, canInsertIntoSlot, canInsertIntoSlot, canInsertItemIntoSlot, canUse, checkDataCount, checkSize, copySharedSlots, disableSyncing, dropInventory, enableSyncing, endQuickCraft, getCursorStack, getRevision, getSlot, getSlotIndex, getStacks, getType, insertItem, isValid, nextRevision, onButtonClick, onContentChanged, packQuickCraftData, removeListener, sendContentUpdates, setCursorStack, setPreviousCursorStack, setPreviousTrackedSlot, setPreviousTrackedSlotMutable, setProperty, setStackInSlot, shouldQuickCraftContinue, syncState, unpackQuickCraftButton, unpackQuickCraftStage, updateSlotStacks, updateSyncHandler, updateToClient

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.github.cottonmc.cotton.gui.GuiDescription

    cycleFocus
  • Field Details

    • blockInventory

      protected net.minecraft.inventory.Inventory blockInventory
    • playerInventory

      protected net.minecraft.entity.player.PlayerInventory playerInventory
    • world

      protected net.minecraft.world.World world
    • propertyDelegate

      protected net.minecraft.screen.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(net.minecraft.screen.ScreenHandlerType<?> type, int syncId, net.minecraft.entity.player.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(net.minecraft.screen.ScreenHandlerType<?> type, int syncId, net.minecraft.entity.player.PlayerInventory playerInventory, @Nullable @Nullable net.minecraft.inventory.Inventory blockInventory, @Nullable @Nullable net.minecraft.screen.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
    • transferSlot

      public net.minecraft.item.ItemStack transferSlot(net.minecraft.entity.player.PlayerEntity player, int index)
      Overrides:
      transferSlot in class net.minecraft.screen.ScreenHandler
    • onSlotClick

      public void onSlotClick(int slotIndex, int button, net.minecraft.screen.slot.SlotActionType actionType, net.minecraft.entity.player.PlayerEntity player)
      Overrides:
      onSlotClick in class net.minecraft.screen.ScreenHandler
    • getPropertyDelegate

      @Nullable public @Nullable net.minecraft.screen.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(net.minecraft.screen.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 net.minecraft.inventory.Inventory getBlockInventory(net.minecraft.screen.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 net.minecraft.inventory.Inventory getBlockInventory(net.minecraft.screen.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 net.minecraft.screen.PropertyDelegate getBlockPropertyDelegate(net.minecraft.screen.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 net.minecraft.screen.PropertyDelegate getBlockPropertyDelegate(net.minecraft.screen.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(net.minecraft.entity.player.PlayerEntity entity)
      Specified by:
      canUse in class net.minecraft.screen.ScreenHandler
    • close

      public void close(net.minecraft.entity.player.PlayerEntity player)
      Overrides:
      close in class net.minecraft.screen.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
    • 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