146 lines
4.2 KiB
Lua
146 lines
4.2 KiB
Lua
---Version: 5.16
|
|
---@meta
|
|
|
|
---Base class used by [`StorageRef`], [`NodeMetaRef`], [`ItemStackMetaRef`],
|
|
---and [`PlayerMetaRef`].
|
|
---
|
|
---Note: If a metadata value is in the format `${k}`, an attempt to get the value
|
|
---will return the value associated with key `k`. There is a low recursion limit.
|
|
---This behavior is **deprecated** and will be removed in a future version. Usage
|
|
---of the `${k}` syntax in formspecs is not deprecated.
|
|
---
|
|
---@class MetaDataRef
|
|
MetaDataRef = {}
|
|
|
|
---Returns `true` if `key` present, otherwise `false`.
|
|
---
|
|
---Returns `nil` when the MetaData is inexistent.
|
|
---@param key string
|
|
---@return boolean?
|
|
function MetaDataRef:contains(key) end
|
|
|
|
---Returns the value stored at `key` as a string if present.
|
|
---
|
|
---Returns nil otherwise.
|
|
---@param key string
|
|
---@return string?
|
|
function MetaDataRef:get(key) end
|
|
|
|
---Set the string `value` at `key`.
|
|
---
|
|
---Value of `""` will delete the key.
|
|
---@param key string
|
|
---@param value string
|
|
function MetaDataRef:set_string(key, value) end
|
|
|
|
---Returns a string value at `key` or `""` if not present.
|
|
---@param key string
|
|
---@return string
|
|
function MetaDataRef:get_string(key) end
|
|
|
|
---Set an integer number `value` to `key`.
|
|
---
|
|
---Range: [s32].
|
|
---
|
|
---Some systems internally have a larger value range
|
|
---but but you should not rely on this behavior to ensure portability of your code.
|
|
---
|
|
---The value will be converted into a string when stored.
|
|
---@param key string
|
|
---@param value integer
|
|
function MetaDataRef:set_int(key, value) end
|
|
|
|
---Returns the value stored at `key` as an integer.
|
|
---
|
|
---Returns `0` if key not present.
|
|
---@param key string
|
|
---@return integer
|
|
function MetaDataRef:get_int(key) end
|
|
|
|
---Store a number (a 64-bit floating-point number) exactly.
|
|
---
|
|
---The value will be converted into a string when stored.
|
|
---@param key string
|
|
---@param value number
|
|
function MetaDataRef:set_float(key, value) end
|
|
|
|
---Returns a 64-bit floating-point number stored at `key`.
|
|
---
|
|
---Returns `0` if key not present.
|
|
---@param key string
|
|
---@return number
|
|
function MetaDataRef:get_float(key) end
|
|
|
|
---Returns a list of all keys in the metadata.
|
|
---@return table
|
|
function MetaDataRef:get_keys() end
|
|
|
|
---Metadata tables represent MetaDataRef in a Lua table form (see `from_table`/`to_table`).
|
|
---
|
|
---Example:
|
|
---```lua
|
|
---metadata_table = {
|
|
--- -- metadata fields (key/value store)
|
|
--- fields = {
|
|
--- infotext = "Container",
|
|
--- another_key = "Another Value",
|
|
--- },
|
|
--- -- inventory data (for nodes)
|
|
--- inventory = {
|
|
--- -- inventory list "main" with 4 slots
|
|
--- main = {
|
|
--- -- list of all item slots
|
|
--- [1] = ItemStack("example:dirt"),
|
|
--- [2] = ItemStack("example:stone 25"),
|
|
--- [3] = ItemStack(""), -- empty slot
|
|
--- [4] = ItemStack("example:pickaxe"),
|
|
--- },
|
|
--- -- inventory list "hidden" with 1 slot
|
|
--- hidden = {
|
|
--- [1] = ItemStack("example:diamond"),
|
|
--- },
|
|
--- },
|
|
---}
|
|
---```
|
|
---@class MetaDataRef.Table
|
|
---Key-value storage of metadata fields.
|
|
---
|
|
---All values are stored as strings.
|
|
---
|
|
---Numbers must be converted to strings first.
|
|
---@field fields table
|
|
---
|
|
---(for NodeMetaRef only): A node inventory in table form
|
|
---
|
|
---Inventory table keys are inventory list names.
|
|
---
|
|
---Inventory table values are item tables.
|
|
---
|
|
---Item table keys are slot IDs (starting with 1).
|
|
---
|
|
---Item table values are ItemStacks
|
|
---@field inventory table
|
|
|
|
---Returns a [metadata table](lua://MetaDataRef.Table) or `nil` on failure.
|
|
---@return MetaDataRef.Table?
|
|
function MetaDataRef:to_table() end
|
|
|
|
---Imports metadata from a [metadata table](lua://MetaDataRef.Table).
|
|
---
|
|
---If `data` is a metadata table,
|
|
---the metadata it represents will replace all metadata of this MetaDataRef object.
|
|
---
|
|
---Any non-table value for `data` will clear all metadata.
|
|
---
|
|
---Item table values the inventory field may also be itemstrings.
|
|
---
|
|
---Returns `true` on success.
|
|
--- @param data MetaDataRef.Table?
|
|
--- @return boolean
|
|
function MetaDataRef:from_table(data) end
|
|
|
|
---Returns `true` if this metadata has the same key-value pairs as `other`.
|
|
---@param other any
|
|
---@return boolean
|
|
function MetaDataRef:equals(other) end
|