Page 1 of 1

Item durability

PostPosted: Tue Jan 01, 2013 19:46
by LorenzoVulcan
Are there any functions for getting and modifying a durability of an item?

PostPosted: Tue Jan 01, 2013 19:57
by Jordach
LorenzoVulcan wrote:Are there any functions for getting and modifying a durability of an item?

Go look at http://github.com/RealBadAngel/technic that has a tool repair box that can fix tools.

Read the source from there.

PostPosted: Tue Jan 01, 2013 20:24
by LorenzoVulcan
Jordach wrote:
LorenzoVulcan wrote:Are there any functions for getting and modifying a durability of an item?

Go look at http://github.com/RealBadAngel/technic that has a tool repair box that can fix tools.

Read the source from there.

Thanks,i'm searching on this but i can't actually find it...Any help?

EDIT:I think i found it,it's item["wear"],thanks!

PostPosted: Tue Jan 01, 2013 20:55
by Jordach

PostPosted: Tue Jan 01, 2013 22:45
by PilzAdam
If you have an ItemStack you can easily change the wear: https://github.com/celeron55/minetest/blob/master/doc/lua_api.txt#L1251

PostPosted: Wed Jan 02, 2013 11:43
by LorenzoVulcan
Now it's all solved,but:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
    for i=1,4 do
        local item_stack=ItemStack(inv:get_stack("items", i))
        if item_stack:get_name() == itemname then
            if gen_energy >= energy_per_second then
            item_stack:add_wear(energy_per_second)
            gen_meta:set_int("energy",gen_energy-energy_per_second)
            print(item_stack:get_wear())
            end
        end   
    end

The wear doesn't change.
Anyway thanks all for your help :)

PostPosted: Wed Jan 02, 2013 13:42
by PilzAdam
LorenzoVulcan wrote:Now it's all solved,but:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
    for i=1,4 do
        local item_stack=ItemStack(inv:get_stack("items", i))
        if item_stack:get_name() == itemname then
            if gen_energy >= energy_per_second then
            item_stack:add_wear(energy_per_second)
            gen_meta:set_int("energy",gen_energy-energy_per_second)
            print(item_stack:get_wear())
            end
        end   
    end

The wear doesn't change.
Anyway thanks all for your help :)

You have to call inv:set_stack("items", i, stack) to add the ItemStack back to the inventory. Only changing the ItemStack that you got by calling get_stack() doesnt effect the inventory.

PostPosted: Wed Jan 02, 2013 14:27
by LorenzoVulcan
Ok,Thanks all guys :) I'll credit you,this works fine.Sorry but that's my first time using the ItemStack.