How?
I would like in the on_construct function, but is not a node (with a pos).
maybe in tool_capabilities could I add a custom key/value?
Add metadata to tool
- rubenwardy
- Moderator
- Posts: 6978
- Joined: Tue Jun 12, 2012 18:11
- GitHub: rubenwardy
- IRC: rubenwardy
- In-game: rubenwardy
- Location: Bristol, United Kingdom
- Contact:
Re: Add metadata to tool
Please can you stop making duplicate posts, and learn to use the edit button.
Answer:
Make sure to save the stack by returning or setting it
Answer:
Code: Select all
local meta = stack:get_meta()
Re: Add metadata to tool
Thanks :-)
rubenwardy wrote:Please can you stop making duplicate posts, and learn to use the edit button.
Answer:
Make sure to save the stack by returning or setting itCode: Select all
local meta = stack:get_meta()
Re: Add metadata to tool
i suspect you need know how to get and set the data too:
local item=itemstack:to_table()
item.metadata -- the meta
itemstack:replace(item) -- set meta and data
but if you need to set more then text you need to use serialize
https://github.com/AiTechEye/bows/blob/ ... ua#L77-L92
local item=itemstack:to_table()
item.metadata -- the meta
itemstack:replace(item) -- set meta and data
but if you need to set more then text you need to use serialize
https://github.com/AiTechEye/bows/blob/ ... ua#L77-L92
Re: Add metadata to tool
Thanks, very explicative!!!AiTechEye wrote:i suspect you need know how to get and set the data too:
local item=itemstack:to_table()
item.metadata -- the meta
itemstack:replace(item) -- set meta and data
but if you need to set more then text you need to use serialize
https://github.com/AiTechEye/bows/blob/ ... ua#L77-L92
- rubenwardy
- Moderator
- Posts: 6978
- Joined: Tue Jun 12, 2012 18:11
- GitHub: rubenwardy
- IRC: rubenwardy
- In-game: rubenwardy
- Location: Bristol, United Kingdom
- Contact:
Re: Add metadata to tool
This is completely the wrong way to do it. metadata is deprecated and shouldn't be usedAiTechEye wrote:i suspect you need know how to get and set the data too:
local item=itemstack:to_table()
item.metadata -- the meta
itemstack:replace(item) -- set meta and data
but if you need to set more then text you need to use serialize
https://github.com/AiTechEye/bows/blob/ ... ua#L77-L92
Do this instead:
Code: Select all
local meta = itemstack:get_meta()
-- Use just like with node meta
meta:set_string("foo", "bar")
meta:set_string("counter", 1)
-- Then make sure to save somehow, typically by returning it if on_use
return itemstack
Re: Add metadata to tool
I've done as you say, cos I read on the wiki for developers. And finally I saved with 'set_stack'.
rubenwardy wrote:This is completely the wrong way to do it. metadata is deprecated and shouldn't be usedAiTechEye wrote:i suspect you need know how to get and set the data too:
local item=itemstack:to_table()
item.metadata -- the meta
itemstack:replace(item) -- set meta and data
but if you need to set more then text you need to use serialize
https://github.com/AiTechEye/bows/blob/ ... ua#L77-L92
Do this instead:
Code: Select all
local meta = itemstack:get_meta() -- Use just like with node meta meta:set_string("foo", "bar") meta:set_string("counter", 1) -- Then make sure to save somehow, typically by returning it if on_use return itemstack
Who is online
Users browsing this forum: No registered users and 4 guests