How do you make items swap?

Post Reply
AndPherb
New member
Posts: 8
Joined: Wed Jan 14, 2026 04:49

How do you make items swap?

by AndPherb » Post

I want to make a pickaxe that gets progressively weaker as you use it. I learned I needed to create several versions of the pickaxes, but I don't know how to make the pickaxe swap out for an identical pickaxe with the same wear.
If someone could help, that would be nice.
Thank you!

User avatar
Desour
Member
Posts: 1581
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

Re: How do you make items swap?

by Desour » Post

AndPherb wrote:
Sat Jan 31, 2026 18:43
I learned I needed to create several versions of the pickaxes, but I don't know how to make the pickaxe swap out for an identical pickaxe with the same wear.
There's set_tool_capabilities nowadays, so you don't need to register several picks.
For wear there's set_wear.
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

User avatar
Linuxdirk
Member
Posts: 3416
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: How do you make items swap?

by Linuxdirk » Post

Desour wrote:
Sun Feb 01, 2026 00:17
AndPherb wrote:
Sat Jan 31, 2026 18:43
I learned I needed to create several versions of the pickaxes, but I don't know how to make the pickaxe swap out for an identical pickaxe with the same wear.
There's set_tool_capabilities nowadays, so you don't need to register several picks.
For wear there's set_wear.
As I understand it, AndPherb wants a pickaxe that can crack very hard materials but after some time when it was worn, it cannot do that anymore.

Can we set tool capabilities via ItemStack metadata? Then this could be possible by writing a function in after_dig_node that checks wear value and adjusts the tool capacities accordingly.

Edit: Just checked. Yes, is possible.

Code: Select all

`ItemStackMetaRef`
------------------

ItemStack metadata: reference extra data and functionality stored in a stack.
Can be obtained via `item:get_meta()`.

### Methods

* All methods in MetaDataRef
* `set_tool_capabilities([tool_capabilities])`
    * Overrides the item's tool capabilities
    * A nil value will clear the override data and restore the original
      behavior.
[...]
So this would be the way to go. Add an after_dig_node function that checks the wear level and sets the tool capabilities as ItemStack metadata.

(And btw. that’s actually a cool idea!)

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests