Update doc_items (fake items)
[MineClone/MineClone2.git] / mods / HELP / doc / doc_items / API.md
blobf8d3b87ce38bea14f901e88eb773962a5a58552a
1 # API documentation for `doc_items`
2 ## Introduction
3 This document explains the API of `doc_items`. It contains a reference of
4 all functions.
6 ## Quick start
7 The most common use case for using this API requires only to set some
8 hand-written help texts for your items.
10 The preferred way is to add the following optional fields to the
11 item definition when using `minetest.register_node`, etc.:
13 * `_doc_items_longdesc`: Long description of this item.
14   Describe here what this item is, what it is for, its purpose, etc.
15 * `_doc_items_usagehelp`: Description of *how* this item can be used.
16   Only set this if needed, e.g. standard mining tools don't need this.
18 Example:
20     minetest.register_node("example:dice", {
21         description = "Dice",
22         _doc_items_longdesc = "A decorative dice which shows the numbers 1-6 on its sides.",
23         _doc_items_usagehelp = "Right-click the dice to roll it.",
24         tiles = { "example_dice.png" },
25         is_ground_content = false,
26         --[[ and so on … ]]
27     })
29 When using this method, your mod does not need additional dependencies.
31 See below for some recommendations on writing good help texts.
33 If you need more customization, read ahead. ;-)
35 ## New item fields
36 This mod adds support for new fields of the item definition. They allow for
37 easy and quick manipulation of the item help entries. All fields are optional.
39 * `_doc_items_longdesc`: Long description
40 * `_doc_items_usagehelp`: Usage help
41 * `_doc_items_image`: Entry image (default: inventory image)
42 * `_doc_items_hidden`: Whether entry is hidden (default: `false` for air and hand, `true` for everything else)
43 * `_doc_items_create_entry`: Whether to create an entry for this item (default: `true`)
44 * `_doc_items_entry_name`: The title of the entry. By default, this is the same as the `description` field
45   of the item. This field is required if the `description` is empty
46 * `_doc_items_durability`: This field is for describing how long a tool can be used before it breaks. Choose one data type:
47    * It it is a `number`: Fixed number of uses before it breaks
48    * If it is a `string`: Free-form text which explains how the durability works. Try to keep it short and only use it if the other types won't work
50 A full explanation of these fields is provided below.
52 ## Concepts
53 This section explains the core concepts of an item help entry in-depth.
55 ### Factoids
56 Basically, a factoid is usually a single sentence telling the player a specific
57 fact about the item. The task of each factoid is to basically convert parts
58 of the item definition to useful, readable, understandable text.
60 Example: It's a fact that `default:sand` has the group `falling_node=1`.
61 A factoid for this is basically just a simple conditional which puts the
62 the sentence “This block is affected to gravity and can fall.” into the
63 text if the node is member of said group.
65 Factoids can be more complex than that. The factoid for node drops needs to
66 account for different drop types and probabilities, etc.
68 `doc_items` has many predefined factoids already. This includes all “special”
69 groups (like `falling_node`), drops, mining capabilities, punch interval,
70 and much more.
72 Custom factoids can be added with `doc.sub.items.register_factoid`.
74 The idea behind factoids is to generate as much information as possible
75 automatically to reduce redundancy, inconsistencies and the workload of hand-
76 written descriptions.
78 ### Long description and usage help
79 Factoids are not always sufficient to describe an item. This is the case
80 for facts where the item definition can not be used to automatically
81 generate texts. Examples: Custom formspecs, ABMs, special tool action
82 on right-click.
84 That's where the long description and usage help comes into play.
85 Those are two texts which are written manually for a specific item.
87 Roughly, the long description is for describing **what** the item is, how it
88 acts, what it is for. The usage help is for explaining **how** the
89 item can be used. It is less important for standard mining tools and weapons.
91 There is no hard length limit for the long description and the usage help.
93 #### Recommendations for long description
94 The long description should roughly contain the following info:
96 * What the item does
97 * What it is good for
98 * How it may be generated in the world
99 * Maybe some background info if you're in a funny mood
100 * Notable information which doesn't fit elsewhere
102 The description should normally **not** contain:
104 * Information which is already covered by factoids, like digging groups,
105   damage, group memberships, etc.
106 * How the item can be used
107 * Direct information about other items
108 * Any other redundant information
109 * Crafting recipes
111 One exception from the rule may be for highlighting the most important
112 purpose of a simple item, like that coal lumps are primarily used as fuel.
114 Sometimes, a long description is not necessary because the item is already
115 exhaustively explained by factoids.
117 For very simple items, consider using one of the template texts (see below).
119 Minimal style guide: Use complete sentences.
121 #### Recommendations for usage help
122 The usage help should only be set for items which are in some way special
123 in their usage. Standard tools and weapons should never have an usage help.
125 The rule of thumb is this: If a new player who already knows the Minetest
126 basics, but not this item, will not directly know how to use this item,
127 then the usage help should be added. If basic Minetest knowledge or
128 existing factoids are completely sufficient, usage help should not be added.
130 The recommendations for what not to put into the usage help is the same
131 as for long descriptions.
133 #### Template texts
134 For your convenience, a few template texts are provided for common texts
135 to avoid redundancy and to increase consistency for simple things. Read
136 `init.lua` to see the actual texts.
138 ##### Long description
139 * `doc.sub.items.temp.build`: For building blocks like the brick block in Minetest Game
140 * `doc.sub.items.temp.deco`: For other decorational blocks.
141 * `doc.sub.items.temp.craftitem`: For items solely or almost solely used for crafting
143 ##### Usage help
144 * `doc.sub.items.temp.eat`: For eatable items using the `on_use=minetest.item_eat(1)` idiom
145 * `doc.sub.items.temp.eat_bad`: Same as above, but eating them is considered a bad idea
146 * `doc.sub.items.temp.rotate_node`: For nodes with `on_place=minetest.rotate_node`,
147   explains placement and rotation
149 ### Entry creation
150 By default, an entry for each item is added automatically, except for items
151 without a description (`description == nil`). This behaviour can be changed
152 on a per-item basis.
154 By setting the item definition's field `_doc_items_create_entry` to `true`
155 or `false`you can explicitly define whether this item should get its own
156 entry.
158 Suppressing an entry is useful for items which aren't supposed to be directly
159 seen or obtained by the player or if they are only used for technical
160 and/or internal purposes. Another possible reason to suppress an entry is
161 to scrub the entry list of lots of very similar related items where the
162 difference is too small to justify two separate entries (e.g.
163 burning furnace vs inactive furnace, because the gameplay mechanics are
164 identical for both).
166 ### Hidden entries
167 Hidden entries are entries which are not visible in the list of entries. This
168 concept directly comes from the Documentation System. The entry will still be
169 created, it is just not selectable by normal means. Players might be able to
170 “unlock” an entry later. Refer to the API documentation of the Documentation
171 System to learn more.
173 By default, all entries are hidden except air and the hand.
175 To mark an entry as hidden, add the field `_doc_items_hidden=true` to its
176 item definition. To make sure an entry is never hidden, add
177 `_doc_items_hidden=false` instead (this rarely needs to be specified
178 explicitly).
180 ### Hand and air
181 The mod adds some default help texts for the hand and the air which are
182 written in a way that they probably are true for most games out of the
183 box, but especially the hand help text is kept intentionally vague.
184 If you want to change these help texts or the entry names or other
185 attributes, just add `_doc_items_*` fields to the item definition, either
186 by re-defining or overwriting these items (e.g. with
187 `minetest.override_item`).
189 In the mod `doc_minetest_game`, the default hand help text is overwritten
190 to explain the hand in more detail, especially the hand behaviour in
191 Creative Mode.
193 ## Functions
194 This is the reference of all available functions in this API.
196 ### `doc.sub.items.register_factoid(category_id, factoid_type, factoid_generator)`
197 Add a custom factoid (see above) for the specified category.
199 * `category_id`: The help category for which the factoid applies:
200     * `"nodes"`: Blocks
201     * `"tools"`: Tools and weapons
202     * `"craftitems"`: Misc. items
203     * `nil`: All of the above
204 * `factoid_type`: Rough categorization of the factoid's content, used to
205   optimize the final text display. This currently determines where in the
206   entry text the factoid appears. Possible values:
207     * For all items:
208         * `"use"`: It's about using the item in some way (written right after the fixed usage help)
209         * `"groups"`: Group-related factoid (very vague)
210         * `"misc"`: Factoid doesn't fit anywhere else, is shown near the end
211     * For nodes only:
212         * `damage`: Related to player/mob damage or health
213         * `movement`: Related to player movement on, in or at node
214         * `sound`: Related to node sounds
215         * `gravity`: Related to gravity (e.g. falling node)
216         * `drop_destroy`: Related to node being destroyed or node dropping as an item
217         * `light`: Related to node light (luminance)
218         * `mining`: Related to mining
219         * `drops`: Related to node drops
220 * `factoid_generator`: A function which turns item definition into a string
221   (see blow)
223 #### `factoid_generator(itemstring, def)`
224 `itemstring` is the itemstring of the item to be documented, and `def` is the
225 complete item definition table (from Minetest).
227 This function must return a helpful string which turns a part of the item's
228 definition into an useful sentence or text. The text can contain newlines,
229 but it must not end with a newline.
231 This function must **always** return a string. If you don't want to add any text,
232 return the empty string.
234 Style guide: Try to use complete sentences and avoid too many newlines.
236 #### Example
237 This factoid will add the sentence “This block will extinguish nearby fire.”
238 to all blocks which are member of the group `puts_out_fire`.
240     doc.sub.items.register_factoid("nodes", "groups", function(itemstring, def)
241         if def.groups.puts_out_fire ~= nil then
242             return "This block will extinguish nearby fire."
243         else
244             return ""
245         end
246     end)
249 ### `doc.sub.items.disable_core_factoid(factoid_name)`
250 This function removes a core (built-in) factoid entirely, its text will never be displayed in any
251 entry then.
253 #### Parameter
254 `factoid_name` chooses the factoid you want to disable. The following core factoids can be disabled:
256 * `"node_mining"`: Mining properties of nodes
257 * `"tool_capabilities"`: Tool capabilities such as digging times
258 * `"groups"`: Group memberships
259 * `"fuel"`: How long the item burns as a fuel and if there's a leftover
260 * `"itemstring"`: The itemstring
261 * `"drops"`: Node drops
262 * `"connects_to"`: Tells to which nodes the node connects to
263 * `"light"`: Light and transparency information for nodes
264 * `"drop_destroy"`: Information about when the node causes to create its “drop” and if it gets destroyed by flooding
265 * `"gravity"`: Factoid for `falling_node` group
266 * `"sounds"`: Infos about sound effects related to the item
267 * `"node_damage"`: Direct damage and drowning damage caused by nodes
268 * `"node_movement"`: Nodes affecting player movement
269 * `"liquid"`: Liquid-related infos of a node
270 * `"basics"`: Collection of many basic factoids: The custom help texts, pointability, collidability, range, stack size, `liquids_pointable`, “punches don't work as usual”. Be careful with this one!
272 #### Background
273 Normally, the core factoids are written in a very general-purpose style, so this function might
274 not be needed at all. But it might be useful for games and mods which radically break with
275 some of the underlying core assumptions in Minetest. For example, if your mod completely changes
276 the digging system, the help texts provided by `doc_items` are probably incorrect, so you can
277 disable `node_mining` and register a custom factoid as a replacement.
279 Please do not use this function lightly because it touches the very core of `doc_items`. Try to
280 understand a core factoid before you consider to disable it. If you think a core factoid is just
281 broken or buggy in general, please file a bug instead.
284 ### `doc.sub.items.add_friendly_group_names(groupnames)`
285 Use this function so set some more readable group names to show them
286 in the formspec, since the internal group names are somewhat cryptic
287 to players.
289 `groupnames` is a table where the keys are the “internal” group names and
290 the values are the group names which will be actually shown in the
291 Documentation System.
293 ***Note***: This function is mostly there to work around a problem in
294 Minetest as it does not support “friendly” group names, which means exposing
295 groups to an interface is not pretty. Therefore, this function may be
296 deprecated when Minetest supports such a thing.
298 ### `doc.sub.items.get_group_name(internal_group_name)`
299 Returns the group name of the specified group as displayed by this mod.
300 If the setting `doc_items_friendly_group_names` is `true`, this might
301 return a “friendly” group name (see above). If no friendly group name
302 exists, `internal_group_name` is returned.
303 If `doc_items_friendly_group_names` is `false`, the argument is always
304 returned.
306 ### `doc.sub.items.add_notable_groups(groupnames)`
307 Add a list of groups you think are notable enough to be mentioned in the
308 “This item belongs to the following groups: (…)” factoid. This factoid
309 is intended to give a quick rundown of misc. groups which don't fit
310 to other factoids, yet they are still somewhat relevant to gameplay.
312 `groupnames` is a table of group names you wish to add.
314 #### What groups should be added
315 What is “notable” is subjective, but there are some guidelines:
317 Do add a group if:
319 * It is used in an ABM
320 * It is used for a custom interaction with another item
321 * It is simple enough for the player to know an item is member of this group
322 * You want to refer to this group in help texts
323 * The “don'ts” below don't apply
325 Do not add a group if:
327 * It is *only* used for crafting, `connects_to`, mining times or damage groups
328 * A factoid covering this group already exists
329 * The group membership itself requires an explanation (consider writing a factoid instead)
330 * The group has no gameplay relevance
331 * Group rating is important to gameplay (consider writing a factoid instead)
333 Groups which are used for crafting or in the `connects_to` field of item
334 definitions are already automatically added to this factoid.
336 ##### Examples for good additions
338 * A group where its members can be placed in bookshelves.
339   so this group meets the “custom interaction” criterion
340 * `water` in Minetest Game: Used for water nodes in the obsidian ABM
341 * `sand` in Minetest Game: Used for the cactus growth ABM, but also crafting.
342   Since it is not *only* used for crafting, it is OK to be added
344 ##### Examples for bad additions
346 * `stick` in Minetest Game: This group appears in many crafting recipes and
347   has no other use. It is already added automatically
348 * A group in which members turn into obsidian when they touch water (ABM):
349   This group is not trivial and should be introduced in a factoid instead
350 * `cracky` in Min
351 * `dig_immediate`: This group is already covered by the default factoids of this
352   mod
355 ## Groups interpretations
356 Nodes which are technically a liquid will not be considered liquids by this mod
357 if the group `fake_liquid=1` is used. Useful for stuff like cobwebs.
361 ## Dependencies
362 If you only add the custom fields to your items, you do *not* need to depend
363 on this mod. If you use anything else from this mod (e.g. a function), you
364 probably *do* need to depend (optionally or mandatorily) on this mod.