How do I set item's "tool_capabilities" from item meta?

Post Reply
User avatar
davidthecreator
Member
Posts: 452
Joined: Mon Aug 18, 2014 19:48
GitHub: daviddoesminetest
In-game: DavidDoesMinetest
Location: Lithuania

How do I set item's "tool_capabilities" from item meta?

by davidthecreator » Post

When I tried to write

Code: Select all

itemstack:get_meta():set_string("tool_capabilities", "{}")
It does seem to work and completely remove all tool capabilities from the item...
But when I actually write some sort of capability I want to edit, it dosen't work...
For example, if I try to change the full_punch_interval:

Code: Select all

itemstack:get_meta():set_string("tool_capabilities", "{full_punch_interval=1.0}")
It dosen't work... And says: "Missing '}' or object member name" ...

So how do I make it work?

User avatar
orwell
Member
Posts: 958
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
IRC: orwell96_mt
In-game: orwell
Location: Raxacoricofallapatorius

Re: How do I set item's "tool_capabilities" from item meta?

by orwell » Post

From what I know, the item meta string expects a string in the JSON format. You can generate this by using

Code: Select all

local meta = itemstack:get_meta()
meta:set_string("tool_capabilities", minetest.json_encode({
        full_punch_interval=1.0
}))
I'm not sure, however.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...

User avatar
davidthecreator
Member
Posts: 452
Joined: Mon Aug 18, 2014 19:48
GitHub: daviddoesminetest
In-game: DavidDoesMinetest
Location: Lithuania

Re: How do I set item's "tool_capabilities" from item meta?

by davidthecreator » Post

orwell wrote:From what I know, the item meta string expects a string in the JSON format. You can generate this by using

Code: Select all

local meta = itemstack:get_meta()
meta:set_string("tool_capabilities", minetest.json_encode({
        full_punch_interval=1.0
}))
I'm not sure, however.
Didn't work... But thanks...

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: How do I set item's "tool_capabilities" from item meta?

by rubenwardy » Post

You should use the set_tool_capabilities(tool_capabilities) method

Code: Select all

local caps = stack:get_tool_capabilities()
stack:get_meta():set_tool_capabilities(caps)
Also remember that stacks are a copy, not a reference. You need to update the slot in the inventory
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
davidthecreator
Member
Posts: 452
Joined: Mon Aug 18, 2014 19:48
GitHub: daviddoesminetest
In-game: DavidDoesMinetest
Location: Lithuania

Re: How do I set item's "tool_capabilities" from item meta?

by davidthecreator » Post

rubenwardy wrote:You should use the set_tool_capabilities(tool_capabilities) method

Code: Select all

local caps = stack:get_tool_capabilities()
stack:get_meta():set_tool_capabilities(caps)
Also remember that stacks are a copy, not a reference. You need to update the slot in the inventory
Thanks, it worked.

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests