UI.Container
Implements
Index
Constructors
Properties
Methods
- _addElement
- _removeElement
- addElementInstance
- applyChanges
- asScriptableField
- clearSlot
- close
- dropAt
- dropSlot
- getBinding
- getElement
- getFieldSlot
- getFullSlot
- getGuiContent
- getGuiScreen
- getParent
- getSlot
- getSlotVisualImpl
- getText
- getValue
- getWindow
- getWorkbenchFieldSize
- handleBindingDirty
- handleInventoryToSlotTransaction
- handleSlotToInventoryTransaction
- handleSlotToSlotTransaction
- invalidateUI
- invalidateUIDrawing
- invalidateUIElements
- isElementTouched
- isLegacyContainer
- isOpened
- onWindowClosed
- openAs
- refreshSlots
- sendChanges
- setBinding
- setOnCloseListener
- setOnOpenListener
- setParent
- setScale
- setSlot
- setText
- setWbSlotNamePrefix
- validateAll
- validateSlot
Constructors
constructor
Creates a new instance of UI.Container.
Returns Container
Properties
parent
If container is a part of TileEntity, this field stores reference to it, otherwise null. You can also assign any value of any type to it using UI.Container.setParent method or using constructor parameter. Consider using UI.Container.getParent instead of direct field access.
slots
Type declaration
[slotName string]: Slot
tileEntity
Same as UI.Container.parent.
staticreadonlyisContainer
Methods
_addElement
Parameters
element: IElement
name: string
Returns void
_removeElement
Parameters
name: string
Returns void
addElementInstance
Parameters
element: IElement
name: string
Returns void
applyChanges
- That feature is obsolete
Backwards compatibility.
Returns void
asScriptableField
Returns Slot[]
JS array of all slots.
clearSlot
Clears slot's contents.
Parameters
name: string
slot name
Returns void
close
Closes currently opened window.
Returns void
dropAt
Drops the contents of all the slots in the container on the specified coordinates and clears them.
That feature is obsoleteClient only, use BlockSource.spawnDroppedItem instead.
Parameters
x: number
y: number
z: number
Returns void
dropSlot
Drops slot's contents on the specified coordinates and clears the slot.
That feature is obsoleteClient only, use BlockSource.spawnDroppedItem instead.
Parameters
name: string
slot name
x: number
y: number
z: number
Returns void
getBinding
Gets any value from the element.
Type parameters
- T = any
Parameters
elementName: string
element name
bindingName: string
binding name, you can access the value from the element by this name. Some binding names are reserved for additional element information, e.g. "element_obj" contains pointer to the current object and "element_rect" contains android.graphics.Rect object containing drawing rectangle
Returns IElement | Rect | T
Value that was get from the element or
nullif the element doesn't exist.
getElement
Parameters
name: string
element name
Returns IElement
Window's element by it's name.
getFieldSlot
Parameters
slot: number
slot index
Returns Slot
Workbench slot instance by slot index.
getFullSlot
Gets the slot by it's name. If a slot with specified name doesn't exists, creates an empty one with specified name.
Parameters
name: string
slot name
Returns Slot
Contents of the slot in a FullSlot object containing more useful methods for slot manipulation.
getGuiContent
Returns WindowContent
Window's content object (usually specified in the window's constructor) if a window was opened in the container,
nullotherwise.
getGuiScreen
Same as getWindow.
Returns IWindow
getParent
Getter for UI.Container.parent field.
Returns any
getSlot
getSlotVisualImpl
Parameters
name: string
Returns UiVisualSlotImpl
getText
Parameters
name: string
element name
Returns string
Value "text" binding, usually the text displayed on the element, or
nullif no element with specified name exist.
getValue
Parameters
name: string
element name
Returns number
Value "value" binding, e.g. scale value, or
nullif no element with specified name exist.
getWindow
Returns IWindow
Currently opened UI.IWindow or
nullif no window is currently opened in the container.
getWorkbenchFieldSize
- since: 2.2.1b106
Returns number
9*
handleBindingDirty
Returns void
handleInventoryToSlotTransaction
Parameters
invSlot: number
slotName: string
amount: number
Returns void
handleSlotToInventoryTransaction
Parameters
slotName: string
amount: number
Returns void
handleSlotToSlotTransaction
Parameters
from: string
to: string
amount: number
Returns void
invalidateUI
Forces ui elements and drawables of the window to refresh.
Parameters
onCurrentThread: boolean
if
true, the drawables will be refreshed immediately, otherwise refresh event will be posted; ensure you are in the UI thread if you passtrueas the parameter
Returns void
invalidateUIDrawing
Forces ui drawables of the window to refresh.
Parameters
onCurrentThread: boolean
if
true, the drawables will be refreshed immediately, otherwise refresh event will be posted; ensure you are in the UI thread if you passtrueas the parameter
Returns void
invalidateUIElements
Forces ui elements of the window to refresh.
Parameters
onCurrentThread: boolean
if
true, the drawables will be refreshed immediately, otherwise refresh event will be posted; ensure you are in the UI thread if you passtrueas the parameter
Returns void
isElementTouched
Parameters
name: string
element name
Returns boolean
trueif the element is currently hovered.
isLegacyContainer
Returns boolean
falseif container supports multiplayer,trueotherwise.
isOpened
Returns boolean
true, if some window is opened in the container.
onWindowClosed
Returns void
openAs
Opens UI.IWindow object in the container.
Parameters
win: IWindow
UI.IWindow object to be opened
Returns void
refreshSlots
- That feature is obsolete
Backwards compatibility.
Returns void
sendChanges
Returns void
setBinding
Passes any value to the element.
Parameters
elementName: string
element name
bindingName: string
binding name, you can access the value from the element by this name
val: any
value to be passed to the element
Returns void
setOnCloseListener
Sets an object to be notified when the window is closed.
Parameters
listener: OnOpenCloseListener
object to be notified when the window is closed
Returns void
setOnOpenListener
- since: 2.0.4b43
Sets an object to be notified when the window is opened.
Parameters
listener: OnOpenCloseListener
object to be notified when the window is opened
Returns void
setParent
Sets container's parent object, for TileEntity's container it should be a TileEntity reference, otherwise you can pass any value to be used in your code later.
Parameters
parent: any
an object to be set as container's parent
Returns void
setScale
Sets "value" binding value for the element. Used to set scales values.
Parameters
name: string
element name
value: number
value to be set for the element
Returns void
setSlot
Set slot's content by it's name. If a slot with specified name doesn't exists, creates an empty one with specified name and item.
Parameters
name: string
slot name
id: number
count: number
data: number
Returns void
setText
Sets "text" binding value for the element. Used to set element's text.
Parameters
name: string
element name
value: string | number
value to be set for the element
Returns void
setWbSlotNamePrefix
If the container is a custom workbench, you can set the slot prefix via this method call. UI.Container.getFieldSlot will get field slot by
prefix + slotname.Parameters
wbsnp: string
custom workbench slot prefix
Returns void
validateAll
Validates all the slots in the container.
Returns void
validateSlot
Validates slot contents. If the data value is less then
0, it becomes0, if ID is0or count is less then or equals to zero, slot is reset to an empty one.Parameters
name: string
slot name
Returns void
Containers are used to properly manipulate windows and save slots contents and windows state between window opens. Every TileEntity has a built-in container that can be accessed as TileEntity.container.
This is a legacy container that does not synchronize between clients and server. It should be used to store data on one side either server or client.