Skip to content

Commit fd8c37a

Browse files
committed
Nodes Items Crafting: updated
1 parent fe3d75d commit fd8c37a

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

chapters/nodes_items_crafting.md

+54-10
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ Item Strings
2222
------------
2323

2424
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.
2626
A string in programming terms is a piece of text.
2727

2828
modname:itemname
2929

3030
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.
3333

3434
### Overriding
3535

3636
Overriding allows you to:
3737

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.
4040

4141
To override, you prefix the item string with a colon, ``:``.
4242
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
5252
Registering a Craftitem
5353
-----------------------
5454

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.
5656
They are used in recipes to create other items, or they can be used be the player, such as food.
5757

5858
{% highlight lua %}
@@ -62,8 +62,9 @@ minetest.register_craftitem("mymod:diamond_fragments", {
6262
})
6363
{% endhighlight %}
6464

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.
6768

6869
### Foods
6970

@@ -81,6 +82,47 @@ The number supplied to the minetest.item_eat function is the number of hit point
8182
Two hit points make one heart, and because there are 10 hearts there are 20 hitpoints.
8283
Hitpoints don't have to be integers (whole numbers), they can be decimals.
8384

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
84126

85127
Registering a basic node
86128
------------------------
@@ -132,6 +174,8 @@ minetest.register_node("mymod:diamond", {
132174
})
133175
{% endhighlight %}
134176

177+
The is_ground_content attribute allows caves to be generated over the stone.
178+
135179
Crafting
136180
--------
137181

@@ -144,7 +188,7 @@ identified by the ``type`` property.
144188
* cooking - Recipes for the furnace to use.
145189
* tool_repair - Used to allow the repairing of tools.
146190

147-
Craft recipes do not use Item Strings.
191+
Craft recipes do not use Item Strings to uniquely identify themselves.
148192

149193
### Shaped
150194

@@ -172,7 +216,7 @@ This means that the craft must always be exactly that.
172216
In most cases, such as the door recipe, you don't care if the ingredients
173217
are always in an exact place, you just want them correct relative to each
174218
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,
176220
allows the recipe to be crafted if it was all moved one place to the right.
177221

178222
{% highlight lua %}

0 commit comments

Comments
 (0)