diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-06-07 03:19:05 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-06-07 03:19:05 +0200 |
commit | b11c0a6721cd884d78b38b63797dfdb933004e03 (patch) | |
tree | 629c49cda2995fafef2bf345abf31b39bd21ff69 /doc/lua_api.txt | |
parent | 827b9f8d7054158b058679999d77c1345162a293 (diff) | |
parent | edc7df54801ab3bf30f96ac5aad6ce11a102f6b9 (diff) | |
download | dragonfireclient-b11c0a6721cd884d78b38b63797dfdb933004e03.tar.xz |
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'doc/lua_api.txt')
-rw-r--r-- | doc/lua_api.txt | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt index d277429b3..1d8de7ed9 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1673,10 +1673,16 @@ these formats. ### Serialized This is called "stackstring" or "itemstring". It is a simple string with -1-3 components: the full item identifier, an optional amount and an optional -wear value. Syntax: +1-4 components: - <identifier> [<amount>[ <wear>]] +1. Full item identifier ("item name") +2. Optional amount +3. Optional wear value +4. Optional item metadata + +Syntax: + + <identifier> [<amount>[ <wear>[ <metadata>]]] Examples: @@ -1684,6 +1690,26 @@ Examples: * `"default:dirt 5"`: 5 dirt * `"default:pick_stone"`: a new stone pickaxe * `"default:pick_wood 1 21323"`: a wooden pickaxe, ca. 1/3 worn out +* `[[default:pick_wood 1 21323 "\u0001description\u0002My worn out pick\u0003"]]`: + * a wooden pickaxe from the `default` mod, + * amount must be 1 (pickaxe is a tool), ca. 1/3 worn out (it's a tool), + * with the `description` field set to `"My worn out pick"` in its metadata +* `[[default:dirt 5 0 "\u0001description\u0002Special dirt\u0003"]]`: + * analogeous to the above example + * note how the wear is set to `0` as dirt is not a tool + +You should ideally use the `ItemStack` format to build complex item strings +(especially if they use item metadata) +without relying on the serialization format. Example: + + local stack = ItemStack("default:pick_wood") + stack:set_wear(21323) + stack:get_meta():set_string("description", "My worn out pick") + local itemstring = stack:to_string() + +Additionally the methods `minetest.itemstring_with_palette(item, palette_index)` +and `minetest.itemstring_with_color(item, colorstring)` may be used to create +item strings encoding color information in their metadata. ### Table format @@ -1779,7 +1805,6 @@ An example: Make meat soup from any meat, any water and any bowl: {"group:water"}, {"group:bowl"}, }, - -- preserve = {"group:bowl"}, -- Not implemented yet (TODO) } Another example: Make red wool from white wool and red dye: @@ -3593,6 +3618,12 @@ Helper functions * `minetest.pointed_thing_to_face_pos(placer, pointed_thing)`: returns a position. * returns the exact position on the surface of a pointed node +* `minetest.get_tool_wear_after_use(uses [, initial_wear])` + * Simulates a tool being used once and returns the added wear, + such that, if only this function is used to calculate wear, + the tool will break exactly after `uses` times of uses + * `uses`: Number of times the tool can be used + * `initial_wear`: The initial wear the tool starts with (default: 0) * `minetest.get_dig_params(groups, tool_capabilities [, wear])`: Simulates an item that digs a node. Returns a table with the following fields: @@ -6528,7 +6559,13 @@ an itemstring, a table or `nil`. or those of the hand if none are defined for this item type * `add_wear(amount)` * Increases wear by `amount` if the item is a tool, otherwise does nothing + * Valid `amount` range is [0,65536] * `amount`: number, integer +* `add_wear_by_uses(max_uses)` + * Increases wear in such a way that, if only this function is called, + the item breaks after `max_uses` times + * Valid `max_uses` range is [0,65536] + * Does nothing if item is not a tool or if `max_uses` is 0 * `add_item(item)`: returns leftover `ItemStack` * Put some item or stack onto this stack * `item_fits(item)`: returns `true` if item or stack can be fully added to |