Commit e493199 1 parent d09fc6c commit e493199 Copy full SHA for e493199
File tree 1 file changed +35
-9
lines changed
1 file changed +35
-9
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ In this chapter you will learn how to use ItemStacks.
10
10
11
11
* Creating ItemStacks
12
12
* Name and Count
13
+ * Adding and Taking Items
13
14
* Wear
14
- * Copying a stack
15
15
* Lua Tables
16
16
* Metadata
17
17
* More Methods
39
39
end
40
40
{% endhighlight %}
41
41
42
+ And you can copy stacks like this:
43
+
44
+ {% highlight lua %}
45
+ local items2 = ItemStack(items)
46
+ {% endhighlight %}
47
+
42
48
## Name and Count
43
49
44
50
{% highlight lua %}
58
64
end
59
65
{% endhighlight %}
60
66
67
+ ## Adding and Taking Items
68
+
69
+ ### Adding
70
+
71
+ Use ` add_item ` to add items to an ItemStack.
72
+ An ItemStack of the items that could not be added is returned.
73
+
74
+ {% highlight lua %}
75
+ local items = ItemStack("default: stone 50")
76
+ local to_add = ItemStack("default: stone 100")
77
+ local leftovers = items: add_item (to_add)
78
+
79
+ print("Could not add" .. leftovers: get_count () .. " of the items.")
80
+ -- ^ will be 51
81
+ {% endhighlight %}
82
+
83
+ ## Taking
84
+
85
+ The following code takes ** up to** 100.
86
+ If there aren't enough items in the stack, it will take as much as it can.
87
+
88
+ {% highlight lua %}
89
+ local taken = items: take_item (100)
90
+ -- taken is the ItemStack taken from the main ItemStack
91
+
92
+ print("Took " .. taken: get_count () .. " items")
93
+ {% endhighlight %}
94
+
61
95
## Wear
62
96
63
97
ItemStacks also have wear on them. Wear is a number out of 65535, the higher is
@@ -77,14 +111,6 @@ items:add_wear(65535 / (max_uses - 1))
77
111
When digging a node, the amount of wear a tool gets may depends on the node
78
112
being dug. So max_uses varies depending on what is being dug.
79
113
80
- ## Copying a stack
81
-
82
- It's as simple as this:
83
-
84
- {% highlight lua %}
85
- local items2 = ItemStack(items)
86
- {% endhighlight %}
87
-
88
114
## Lua Tables
89
115
90
116
{% highlight lua %}
You can’t perform that action at this time.
0 commit comments