@@ -22,21 +22,21 @@ Item Strings
22
22
------------
23
23
24
24
Each item, whether that be a node, craftitem, tool or entity, has an item string.\\
25
- This is oftenly refered to as just name or registered name.
25
+ This is sometimes referred to as registered name or just name.
26
26
A string in programming terms is a piece of text.
27
27
28
28
modname:itemname
29
29
30
30
The modname is the name of the folder your mod is in.
31
- You may call the itemname any thing you like, however it should be relevant to what the item is,
32
- and it can't be already registered.
31
+ You may call the itemname any thing you like, however it should be relevant to
32
+ what the item is, and it can't already be registered.
33
33
34
34
### Overriding
35
35
36
36
Overriding allows you to:
37
37
38
- * Create an item in another mod's namespace .
39
- * Override an existing item.
38
+ * Redefine an existing item .
39
+ * Use an item string with a different modname .
40
40
41
41
To override, you prefix the item string with a colon, `` : `` .
42
42
Declaring an item as `` :default:dirt `` will override the default: dirt in the default mod.
@@ -52,7 +52,7 @@ JPEGs are supported, but they do not support transparency and are generally bad
52
52
Registering a Craftitem
53
53
-----------------------
54
54
55
- Craftitems are the simplest item in Minetest. Craftitems cannot be placed in the world.
55
+ Craftitems are the simplest items in Minetest. Craftitems cannot be placed in the world.
56
56
They are used in recipes to create other items, or they can be used be the player, such as food.
57
57
58
58
{% highlight lua %}
@@ -62,8 +62,9 @@ minetest.register_craftitem("mymod:diamond_fragments", {
62
62
})
63
63
{% endhighlight %}
64
64
65
- Definitions are usually made up of an [ item string] ( #item-strings ) to identify the definition,
66
- and a definition table.
65
+ Item definitions like seen above are usually made up of an unique
66
+ [ item string] ( #item-strings ) and a definition table. The definition table
67
+ contains attributes which affect the behavour of the item.
67
68
68
69
### Foods
69
70
@@ -81,6 +82,47 @@ The number supplied to the minetest.item_eat function is the number of hit point
81
82
Two hit points make one heart, and because there are 10 hearts there are 20 hitpoints.
82
83
Hitpoints don't have to be integers (whole numbers), they can be decimals.
83
84
85
+ Sometimes you may want a food to be replaced with another item when being eaten,
86
+ for example smaller pieces of cake or bones after eating meat. To do this, use:
87
+
88
+ minetest.item_eat(hp, replace_with_item)
89
+
90
+ Where replace_with_item is an item string.
91
+
92
+ ### Foods, extended
93
+
94
+ How about if you want to do more than just eat the item,
95
+ such as send a message to the player?
96
+
97
+ {% highlight lua %}
98
+ minetest.register_craftitem("mymod: mudpie ", {
99
+ description = "Alien Mud Pie",
100
+ inventory_image = "myfood_mudpie.png",
101
+ on_use = function(itemstack, user, pointed_thing)
102
+ hp_change = 20
103
+ replace_with_item = nil
104
+
105
+ minetest.chat_send_player(user:get_player_name(), "You ate an alien mud pie!")
106
+
107
+ -- Support for hunger mods using minetest.register_on_item_eat
108
+ for _, callback in pairs(core.registered_on_item_eats) do
109
+ local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing)
110
+ if result then
111
+ return result
112
+ end
113
+ end
114
+
115
+ if itemstack:take_item() ~= nil then
116
+ user:set_hp(user:get_hp() + hp_change)
117
+ end
118
+
119
+ return itemstack
120
+ end
121
+ })
122
+ {% endhighlight %}
123
+
124
+ If you are creating a hunger mod, or if you are affecting foods outside of your
125
+ mod, you should consider using minetest.register_on_item_eat
84
126
85
127
Registering a basic node
86
128
------------------------
@@ -132,6 +174,8 @@ minetest.register_node("mymod:diamond", {
132
174
})
133
175
{% endhighlight %}
134
176
177
+ The is_ground_content attribute allows caves to be generated over the stone.
178
+
135
179
Crafting
136
180
--------
137
181
@@ -144,7 +188,7 @@ identified by the ``type`` property.
144
188
* cooking - Recipes for the furnace to use.
145
189
* tool_repair - Used to allow the repairing of tools.
146
190
147
- Craft recipes do not use Item Strings.
191
+ Craft recipes do not use Item Strings to uniquely identify themselves .
148
192
149
193
### Shaped
150
194
@@ -172,7 +216,7 @@ This means that the craft must always be exactly that.
172
216
In most cases, such as the door recipe, you don't care if the ingredients
173
217
are always in an exact place, you just want them correct relative to each
174
218
other. In order to do this, delete any empty rows and columns.
175
- In the above case, their is an empty last column, which, when removed,
219
+ In the above case, there is an empty last column, which, when removed,
176
220
allows the recipe to be crafted if it was all moved one place to the right.
177
221
178
222
{% highlight lua %}
0 commit comments