Class SyncedGuiDescription
- All Implemented Interfaces:
GuiDescription
- Direct Known Subclasses:
ItemSyncedGuiDescription
-
Nested Class Summary
Nested classes/interfaces inherited from interface GuiDescription
GuiDescription.FocusChangeListener -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @Nullable net.minecraft.world.Containerprotected intprotected booleanprotected net.minecraft.world.entity.player.Inventoryprotected @Nullable net.minecraft.world.inventory.ContainerDataDeprecated, for removal: This API element is subject to removal in a future version.protected WPanelprotected HorizontalAlignmentprotected intprotected booleanprotected net.minecraft.world.level.LevelDeprecated, for removal: This API element is subject to removal in a future version.Use the methodgetLevel()instead.Fields inherited from class net.minecraft.world.inventory.AbstractContainerMenu
CARRIED_SLOT_SIZE, containerId, QUICKCRAFT_HEADER_CONTINUE, QUICKCRAFT_HEADER_END, QUICKCRAFT_HEADER_START, QUICKCRAFT_TYPE_CHARITABLE, QUICKCRAFT_TYPE_CLONE, QUICKCRAFT_TYPE_GREEDY, SLOT_CLICKED_OUTSIDE, SLOT_SIZE, slots, SLOTS_PER_ROW -
Constructor Summary
ConstructorsConstructorDescriptionSyncedGuiDescription(net.minecraft.world.inventory.MenuType<?> type, int syncId, net.minecraft.world.entity.player.Inventory playerInventory) Constructs a new synced GUI description without a block inventory or a property delegate.SyncedGuiDescription(net.minecraft.world.inventory.MenuType<?> type, int syncId, net.minecraft.world.entity.player.Inventory playerInventory, @Nullable net.minecraft.world.Container blockInventory, @Nullable net.minecraft.world.inventory.ContainerData containerData) Constructs a new synced GUI description. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a listener that is called when the focused widget changes.voidGuis should use this method to add clientside styles and BackgroundPainters to their controlsvoidaddSlotPeer(ValidatedSlot slot) Typical users won't call this.voidCreates 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.world.ContainergetBlockInventory(net.minecraft.world.inventory.ContainerLevelAccess ctx) Gets the block inventory at the context.static net.minecraft.world.ContainergetBlockInventory(net.minecraft.world.inventory.ContainerLevelAccess ctx, int size) Gets the block inventory at the context.static net.minecraft.world.inventory.ContainerDatagetBlockPropertyDelegate(net.minecraft.world.inventory.ContainerLevelAccess ctx) Gets the property delegate at the context.static net.minecraft.world.inventory.ContainerDatagetBlockPropertyDelegate(net.minecraft.world.inventory.ContainerLevelAccess ctx, int size) Gets the property delegate at the context.@Nullable net.minecraft.world.inventory.ContainerDataGets the object which manages the integer properties used by WBars and such.getFocus()Gets the currently-focused WWidget.net.minecraft.world.level.LevelgetLevel()Returns the level of this GUI description's player.final ScreenNetworkinggetNetworking(NetworkSide side) Gets a networking handler for the GUI description that is active on the specified side.final NetworkSideGets the network side this GUI description runs on.final PacketSenderGets the packet sender corresponding to this GUI's network side.Gets the horizontal alignment of the GUI title.intGets the position of the screen title.booleanTests whether the root panel should get a vanilla background in the defaultGuiDescription.addPainters()implementations.net.minecraft.world.level.LevelgetWorld()Deprecated, for removal: This API element is subject to removal in a future version.Replaced withgetLevel().booleanTests whether the widget is the currently-focused one.booleanGets whether this GUI is fullscreen.booleanGets whether the title of this GUI should be rendered by the screen.net.minecraft.world.item.ItemStackquickMoveStack(net.minecraft.world.entity.player.Player player, int index) <T> DataSlot<T> registerDataSlot(ScreenMessageKey<T> key, T initialValue) Registers an S2C data slot.<T> DataSlot<T> registerDataSlot(ScreenMessageKey<T> key, T initialValue, NetworkDirection networkDirection) Registers a data slot.voidreleaseFocus(WWidget widget) Notifies this gui that the widget wants to give up its hold over focus.voidremoved(net.minecraft.world.entity.player.Player player) voidrequestFocus(WWidget widget) Notifies this gui that the widget wants to acquire focus.voidChecks for and sends data slot content updates.setContainerData(net.minecraft.world.inventory.ContainerData data) Sets the object which manages the integer properties used by WBars.voidsetFullscreen(boolean fullscreen) Sets whether this GUI is fullscreen.setRootPanel(WPanel panel) voidsetTitleAlignment(HorizontalAlignment titleAlignment) 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.voidsetTitlePos(Vec2i titlePos) Sets the position of the screen title.voidsetTitleVisible(boolean titleVisible) Sets whether the title of this GUI should be rendered by the screen.voidsetUseDefaultRootBackground(boolean useDefaultRootBackground) Enables or disables the default vanilla background for root panels.booleanstillValid(net.minecraft.world.entity.player.Player entity) Methods inherited from class net.minecraft.world.inventory.AbstractContainerMenu
addDataSlot, addDataSlots, addInventoryExtendedSlots, addInventoryHotbarSlots, addSlot, addSlotListener, addStandardInventorySlots, broadcastFullState, canDragTo, canItemQuickReplace, canTakeItemForPickAll, checkContainerDataCount, checkContainerSize, clearContainer, clicked, clickMenuButton, findSlot, getCarried, getItems, getQuickcraftHeader, getQuickcraftMask, getQuickCraftPlaceCount, getQuickcraftType, getRedstoneSignalFromBlockEntity, getRedstoneSignalFromContainer, getSlot, getStateId, getType, incrementStateId, initializeContents, isValidQuickcraftType, isValidSlotIndex, moveItemStackTo, removeSlotListener, resetQuickCraft, resumeRemoteUpdates, sendAllDataToRemote, setCarried, setData, setItem, setRemoteCarried, setRemoteSlot, setRemoteSlotUnsafe, setSelectedBundleItemIndex, setSynchronizer, slotsChanged, stillValid, suppressRemoteUpdates, transferStateMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface GuiDescription
getPropertyDelegate, isDarkMode, setPropertyDelegate
-
Field Details
-
blockInventory
-
playerInventory
protected net.minecraft.world.entity.player.Inventory playerInventory -
world
Deprecated, for removal: This API element is subject to removal in a future version.Use the methodgetLevel()instead. -
propertyDelegate
@Deprecated(forRemoval=true) protected @Nullable net.minecraft.world.inventory.ContainerData propertyDelegateDeprecated, for removal: This API element is subject to removal in a future version.Use the methodsgetContainerData()andsetContainerData(ContainerData)instead. -
rootPanel
-
titleColor
protected int titleColor -
darkTitleColor
protected int darkTitleColor -
fullscreen
protected boolean fullscreen -
titleVisible
protected boolean titleVisible -
titleAlignment
-
focus
-
-
Constructor Details
-
SyncedGuiDescription
public SyncedGuiDescription(net.minecraft.world.inventory.MenuType<?> type, int syncId, net.minecraft.world.entity.player.Inventory playerInventory) Constructs a new synced GUI description without a block inventory or a property delegate.- Parameters:
type- theMenuTypeof this GUI descriptionsyncId- the current sync IDplayerInventory- the player inventory of the player viewing this screen
-
SyncedGuiDescription
public SyncedGuiDescription(net.minecraft.world.inventory.MenuType<?> type, int syncId, net.minecraft.world.entity.player.Inventory playerInventory, @Nullable net.minecraft.world.Container blockInventory, @Nullable net.minecraft.world.inventory.ContainerData containerData) Constructs a new synced GUI description.- Parameters:
type- theMenuTypeof this GUI descriptionsyncId- the current sync IDplayerInventory- the player inventory of the player viewing this screenblockInventory- the block inventory of a corresponding container block, or null if not found or applicablecontainerData- a container data holder whose properties, if any, will automatically be added
-
-
Method Details
-
getRootPanel
- Specified by:
getRootPanelin interfaceGuiDescription
-
getTitleColor
public int getTitleColor()- Specified by:
getTitleColorin interfaceGuiDescription
-
setRootPanel
- Specified by:
setRootPanelin interfaceGuiDescription
-
setTitleColor
Description copied from interface:GuiDescriptionSets 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 beWLabel.DEFAULT_DARKMODE_TEXT_COLOR; otherwise it will be the specified color.- Specified by:
setTitleColorin interfaceGuiDescription- Parameters:
color- the new title color- Returns:
- this GUI
-
setTitleColor
Description copied from interface:GuiDescriptionSets the light and dark title colors of this GUI.- Specified by:
setTitleColorin interfaceGuiDescription- Parameters:
lightColor- the light-mode colordarkColor- the dark-mode color- Returns:
- this GUI
-
addPainters
@Environment(CLIENT) public void addPainters()Description copied from interface:GuiDescriptionGuis should use this method to add clientside styles and BackgroundPainters to their controls- Specified by:
addPaintersin interfaceGuiDescription
-
getUseDefaultRootBackground
public boolean getUseDefaultRootBackground()Description copied from interface:GuiDescriptionTests whether the root panel should get a vanilla background in the defaultGuiDescription.addPainters()implementations.- Specified by:
getUseDefaultRootBackgroundin interfaceGuiDescription- Returns:
trueif the default background painter is applied,falseotherwise
-
setUseDefaultRootBackground
public void setUseDefaultRootBackground(boolean useDefaultRootBackground) Description copied from interface:GuiDescriptionEnables or disables the default vanilla background for root panels.- Specified by:
setUseDefaultRootBackgroundin interfaceGuiDescription- Parameters:
useDefaultRootBackground-trueif the default background painter is applied,falseotherwise- See Also:
-
addSlotPeer
Description copied from interface:GuiDescriptionTypical users won't call this. This adds a Slot to Container/Controller-based guis, and does nothing on lightweight guis.- Specified by:
addSlotPeerin interfaceGuiDescription
-
quickMoveStack
public net.minecraft.world.item.ItemStack quickMoveStack(net.minecraft.world.entity.player.Player player, int index) - Specified by:
quickMoveStackin classnet.minecraft.world.inventory.AbstractContainerMenu
-
getContainerData
Description copied from interface:GuiDescriptionGets the object which manages the integer properties used by WBars and such.- Specified by:
getContainerDatain interfaceGuiDescription
-
setContainerData
Description copied from interface:GuiDescriptionSets the object which manages the integer properties used by WBars.- Specified by:
setContainerDatain interfaceGuiDescription
-
createPlayerInventoryPanel
Creates a player inventory widget from this panel's player inventory.- Returns:
- the created inventory widget
-
createPlayerInventoryPanel
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
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.world.Container getBlockInventory(net.minecraft.world.inventory.ContainerLevelAccess ctx) Gets the block inventory at the context.If no inventory is found, returns
EmptyInventory.INSTANCE.Searches for these implementations in the following order:
- Blocks implementing
InventoryProvider - Block entities implementing
InventoryProvider - Block entities implementing
Inventory
- Parameters:
ctx- the context- Returns:
- the found inventory
- Blocks implementing
-
getBlockInventory
public static net.minecraft.world.Container getBlockInventory(net.minecraft.world.inventory.ContainerLevelAccess 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:
- Blocks implementing
InventoryProvider - Block entities implementing
InventoryProvider - Block entities implementing
Inventory
- Parameters:
ctx- the contextsize- the fallback inventory size- Returns:
- the found inventory
- Since:
- 2.0.0
- Blocks implementing
-
getBlockPropertyDelegate
public static net.minecraft.world.inventory.ContainerData getBlockPropertyDelegate(net.minecraft.world.inventory.ContainerLevelAccess 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.world.inventory.ContainerData getBlockPropertyDelegate(net.minecraft.world.inventory.ContainerLevelAccess 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 contextsize- the number of properties- Returns:
- the found property delegate
- Since:
- 2.0.0
-
stillValid
public boolean stillValid(net.minecraft.world.entity.player.Player entity) - Specified by:
stillValidin classnet.minecraft.world.inventory.AbstractContainerMenu
-
removed
public void removed(net.minecraft.world.entity.player.Player player) - Overrides:
removedin classnet.minecraft.world.inventory.AbstractContainerMenu
-
broadcastChanges
public void broadcastChanges()- Overrides:
broadcastChangesin classnet.minecraft.world.inventory.AbstractContainerMenu
-
isFocused
Description copied from interface:GuiDescriptionTests whether the widget is the currently-focused one.- Specified by:
isFocusedin interfaceGuiDescription
-
getFocus
Description copied from interface:GuiDescriptionGets the currently-focused WWidget. May be null.- Specified by:
getFocusin interfaceGuiDescription
-
requestFocus
Description copied from interface:GuiDescriptionNotifies this gui that the widget wants to acquire focus.- Specified by:
requestFocusin interfaceGuiDescription
-
releaseFocus
Description copied from interface:GuiDescriptionNotifies this gui that the widget wants to give up its hold over focus.- Specified by:
releaseFocusin interfaceGuiDescription
-
isFullscreen
public boolean isFullscreen()Description copied from interface:GuiDescriptionGets 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:
isFullscreenin interfaceGuiDescription- Returns:
- true if this GUI is fullscreen, false otherwise
-
setFullscreen
public void setFullscreen(boolean fullscreen) Description copied from interface:GuiDescriptionSets whether this GUI is fullscreen.- Specified by:
setFullscreenin interfaceGuiDescription- Parameters:
fullscreen- true if this GUI is fullscreen, false otherwise
-
isTitleVisible
public boolean isTitleVisible()Description copied from interface:GuiDescriptionGets 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:
isTitleVisiblein interfaceGuiDescription- Returns:
- true if the title is visible, false otherwise
-
setTitleVisible
public void setTitleVisible(boolean titleVisible) Description copied from interface:GuiDescriptionSets whether the title of this GUI should be rendered by the screen.- Specified by:
setTitleVisiblein interfaceGuiDescription- Parameters:
titleVisible- true if the title is visible, false otherwise
-
getTitleAlignment
Description copied from interface:GuiDescriptionGets the horizontal alignment of the GUI title.- Specified by:
getTitleAlignmentin interfaceGuiDescription- Returns:
- the alignment
-
setTitleAlignment
Description copied from interface:GuiDescriptionSets the horizontal alignment of the GUI title.- Specified by:
setTitleAlignmentin interfaceGuiDescription- Parameters:
titleAlignment- the new alignment
-
getTitlePos
Description copied from interface:GuiDescriptionGets the position of the screen title.- Specified by:
getTitlePosin interfaceGuiDescription- Returns:
- the title position
-
setTitlePos
Description copied from interface:GuiDescriptionSets the position of the screen title.- Specified by:
setTitlePosin interfaceGuiDescription- Parameters:
titlePos- the new title position
-
getWorld
Deprecated, for removal: This API element is subject to removal in a future version.Replaced withgetLevel().Returns the world of this GUI description's player.- Returns:
- the world of this GUI description's player
- Since:
- 10.0.0
-
getLevel
public net.minecraft.world.level.Level getLevel()Returns the level of this GUI description's player.- Returns:
- the level of this GUI description's player
- Since:
- 16.0.0
-
getNetworkSide
Gets the network side this GUI description runs on.- Returns:
- this GUI's network side
- Since:
- 3.3.0
-
getPacketSender
Gets the packet sender corresponding to this GUI's network side.- Returns:
- the packet sender
- Since:
- 3.3.0
-
getNetworking
Gets a networking handler for the GUI description that is active on the specified side.If the network side doesn't match the side of this GUI, returns a no-op networking handler that is still safe to use.
- Parameters:
side- the network side, cannot be null- Returns:
- the networking handler corresponding to the side
- Since:
- 13.1.0
-
registerDataSlot
public <T> DataSlot<T> registerDataSlot(ScreenMessageKey<T> key, T initialValue, NetworkDirection networkDirection) Registers a data slot.This method must be called on both network sides in order for the data slot to sync properly.
The initial value of a data slot will not be synced.
For S2C item stack and int data slots, you should usually use vanilla/LibGui slots and property delegates, respectively.
- Type Parameters:
T- the data slot content type- Parameters:
key- the key of the sync message, cannot be nullinitialValue- the initial value of the data slotnetworkDirection- the network direction to sync, cannot be null- Returns:
- the data slot
- Since:
- 13.1.0
-
registerDataSlot
Registers an S2C data slot.This method must be called on both network sides in order for the data slot to sync properly.
The initial value of a data slot will not be synced.
For item stack and int data slots, you should usually use vanilla/LibGui slots and property delegates, respectively.
- Type Parameters:
T- the data slot content type- Parameters:
key- the key of the sync message, cannot be nullinitialValue- the initial value of the data slot- Returns:
- the data slot
- Since:
- 13.1.0
-
sendDataSlotUpdates
public void sendDataSlotUpdates()Checks for and sends data slot content updates.This method is generally called automatically. If you need to manually sync data slots from the server to the client, prefer
broadcastChanges().- Since:
- 13.1.0
-
addFocusChangeListener
Description copied from interface:GuiDescriptionAdds a listener that is called when the focused widget changes.- Specified by:
addFocusChangeListenerin interfaceGuiDescription- Parameters:
listener- the listener
-
getContainerData()andsetContainerData(ContainerData)instead.