Skip to main content

UI.Container

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.

More about capabilities

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.

Implements

Index

Constructors

constructor

Properties

parent

parent: any

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

slots: {}

Type declaration

  • [slotName string]: Slot

tileEntity

tileEntity: any

staticreadonlyisContainer

isContainer: boolean

Methods

_addElement

  • _addElement(element: IElement, name: string): void
  • Parameters

    Returns void

_removeElement

  • _removeElement(name: string): void
  • Parameters

    • name: string

    Returns void

addElementInstance

  • addElementInstance(element: IElement, name: string): void
  • Parameters

    Returns void

applyChanges

  • applyChanges(): void
  • That feature is obsolete

    Backwards compatibility.


    Returns void

asScriptableField

  • asScriptableField(): Slot[]
  • Returns Slot[]

    JS array of all slots.

clearSlot

  • clearSlot(name: string): void
  • Clears slot's contents.


    Parameters

    • name: string

      slot name

    Returns void

close

  • close(): void
  • Closes currently opened window.


    Returns void

dropAt

  • dropAt(x: number, y: number, z: number): void
  • Drops the contents of all the slots in the container on the specified coordinates and clears them.

    That feature is obsolete

    Client only, use BlockSource.spawnDroppedItem instead.


    Parameters

    • x: number
    • y: number
    • z: number

    Returns void

dropSlot

  • dropSlot(name: string, x: number, y: number, z: number): void
  • Drops slot's contents on the specified coordinates and clears the slot.

    That feature is obsolete

    Client only, use BlockSource.spawnDroppedItem instead.


    Parameters

    • name: string

      slot name

    • x: number
    • y: number
    • z: number

    Returns void

getBinding

  • getBinding<T>(elementName: string, bindingName: string): IElement | Rect | T
  • 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 null if the element doesn't exist.

getElement

  • Parameters

    • name: string

      element name

    Returns IElement

    Window's element by it's name.

getFieldSlot

  • getFieldSlot(slot: number): Slot
  • getFieldSlot(x: number, y: number): AbstractSlot
  • Parameters

    • slot: number

      slot index

    Returns Slot

    Workbench slot instance by slot index.

getFullSlot

  • getFullSlot(name: string): Slot
  • 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, null otherwise.

getGuiScreen

getParent

  • getParent(): any
  • Getter for UI.Container.parent field.


    Returns any

getSlot

  • getSlot(name: string): Slot
  • 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 UI.Slot object. You can modify it to change the contents of the slot.

getSlotVisualImpl

  • Parameters

    • name: string

    Returns UiVisualSlotImpl

getText

  • getText(name: string): string
  • Parameters

    • name: string

      element name

    Returns string

    Value "text" binding, usually the text displayed on the element, or null if no element with specified name exist.

getValue

  • getValue(name: string): number
  • Parameters

    • name: string

      element name

    Returns number

    Value "value" binding, e.g. scale value, or null if no element with specified name exist.

getWindow

  • Returns IWindow

    Currently opened UI.IWindow or null if no window is currently opened in the container.

getWorkbenchFieldSize

  • getWorkbenchFieldSize(): number
  • since: 2.2.1b106

    Returns number

    9 *

handleBindingDirty

  • handleBindingDirty(): void
  • Returns void

handleInventoryToSlotTransaction

  • handleInventoryToSlotTransaction(invSlot: number, slotName: string, amount: number): void
  • Parameters

    • invSlot: number
    • slotName: string
    • amount: number

    Returns void

handleSlotToInventoryTransaction

  • handleSlotToInventoryTransaction(slotName: string, amount: number): void
  • Parameters

    • slotName: string
    • amount: number

    Returns void

handleSlotToSlotTransaction

  • handleSlotToSlotTransaction(from: string, to: string, amount: number): void
  • Parameters

    • from: string
    • to: string
    • amount: number

    Returns void

invalidateUI

  • invalidateUI(onCurrentThread: boolean): void
  • invalidateUI(): void
  • 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 pass true as the parameter

    Returns void

invalidateUIDrawing

  • invalidateUIDrawing(onCurrentThread: boolean): void
  • invalidateUIDrawing(): void
  • 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 pass true as the parameter

    Returns void

invalidateUIElements

  • invalidateUIElements(onCurrentThread: boolean): void
  • invalidateUIElements(): void
  • 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 pass true as the parameter

    Returns void

isElementTouched

  • isElementTouched(name: string): boolean
  • Parameters

    • name: string

      element name

    Returns boolean

    true if the element is currently hovered.

isLegacyContainer

  • isLegacyContainer(): boolean
  • Returns boolean

    false if container supports multiplayer, true otherwise.

isOpened

  • isOpened(): boolean
  • Returns boolean

    true, if some window is opened in the container.

onWindowClosed

  • onWindowClosed(): void
  • Returns void

openAs

  • Opens UI.IWindow object in the container.


    Parameters

    Returns void

refreshSlots

  • refreshSlots(): void
  • That feature is obsolete

    Backwards compatibility.


    Returns void

sendChanges

  • sendChanges(): void
  • Returns void

setBinding

  • setBinding(elementName: string, bindingName: string, val: any): void
  • 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

    Returns void

setOnOpenListener

  • since: 2.0.4b43

    Sets an object to be notified when the window is opened.


    Parameters

    Returns void

setParent

  • setParent(parent: any): void
  • 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

  • setScale(name: string, value: number): void
  • 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

  • setSlot(name: string, id: number, count: number, data: number): void
  • setSlot(name: string, id: number, count: number, data: number, extra: ItemExtraData): void
  • 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

  • setText(name: string, value: string | number): void
  • 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

  • setWbSlotNamePrefix(wbsnp: string): void
  • 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 + slot name.


    Parameters

    • wbsnp: string

      custom workbench slot prefix

    Returns void

validateAll

  • validateAll(): void
  • Validates all the slots in the container.


    Returns void

validateSlot

  • validateSlot(name: string): void
  • Validates slot contents. If the data value is less then 0, it becomes 0, if ID is 0 or count is less then or equals to zero, slot is reset to an empty one.


    Parameters

    • name: string

      slot name

    Returns void