ItemStacks
Introduction
In this chapter you will learn how to use ItemStacks.
- Creating ItemStacks
- Name and Count
- Adding and Taking Items
- Wear
- Lua Tables
- Metadata
- More Methods
Creating ItemStacks
An item stack is a… stack of items. It’s basically just an item type with
a count of items in the stack.
You can create a stack like so:
You could alternatively create a blank ItemStack and fill it using methods:
And you can copy stacks like this:
Name and Count
Adding and Taking Items
Adding
Use add_item
to add items to an ItemStack.
An ItemStack of the items that could not be added is returned.
Taking
The following code takes up to 100.
If there aren’t enough items in the stack, it will take as much as it can.
Wear
ItemStacks also have wear on them. Wear is a number out of 65535, the higher it is,
the more wear.
You use add_wear()
, get_wear()
and set_wear(wear)
.
When digging a node, the amount of wear a tool gets may depends on the node
being dug. So max_uses varies depending on what is being dug.
Lua Tables
ItemStacks can also have a single field of metadata attached to
them.
More Methods
Have a look at the
list of methods for an ItemStack.
There are a lot more available than talked about here.