Item durability

User avatar
LorenzoVulcan
Member
 
Posts: 437
Joined: Mon Mar 12, 2012 06:46

Item durability

by LorenzoVulcan » Tue Jan 01, 2013 19:46

Are there any functions for getting and modifying a durability of an item?
Developer of the BlockForge 2# Project!
Official thread: http://minetest.net/forum/viewtopic.php?pid=54290#p54290
 

User avatar
Jordach
Member
 
Posts: 4412
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Tue Jan 01, 2013 19:57

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.

( ͡° ͜ʖ ͡°) ( ͡o ͜ʖ ͡o) [$ ( ͡° ͜ʖ ͡°) $] ( ͡$ ͜ʖ ͡$) ヽ༼ຈل͜ຈ༽ノ



My image and media server is back online and is functioning as normal.
 

User avatar
LorenzoVulcan
Member
 
Posts: 437
Joined: Mon Mar 12, 2012 06:46

by LorenzoVulcan » Tue Jan 01, 2013 20:24

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!
Last edited by LorenzoVulcan on Tue Jan 01, 2013 20:28, edited 1 time in total.
Developer of the BlockForge 2# Project!
Official thread: http://minetest.net/forum/viewtopic.php?pid=54290#p54290
 

User avatar
Jordach
Member
 
Posts: 4412
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Tue Jan 01, 2013 20:55

( ͡° ͜ʖ ͡°) ( ͡o ͜ʖ ͡o) [$ ( ͡° ͜ʖ ͡°) $] ( ͡$ ͜ʖ ͡$) ヽ༼ຈل͜ຈ༽ノ



My image and media server is back online and is functioning as normal.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Tue Jan 01, 2013 22:45

If you have an ItemStack you can easily change the wear: https://github.com/celeron55/minetest/blob/master/doc/lua_api.txt#L1251
 

User avatar
LorenzoVulcan
Member
 
Posts: 437
Joined: Mon Mar 12, 2012 06:46

by LorenzoVulcan » Wed Jan 02, 2013 11:43

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 :)
Developer of the BlockForge 2# Project!
Official thread: http://minetest.net/forum/viewtopic.php?pid=54290#p54290
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Wed Jan 02, 2013 13:42

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.
 

User avatar
LorenzoVulcan
Member
 
Posts: 437
Joined: Mon Mar 12, 2012 06:46

by LorenzoVulcan » Wed Jan 02, 2013 14:27

Ok,Thanks all guys :) I'll credit you,this works fine.Sorry but that's my first time using the ItemStack.
Developer of the BlockForge 2# Project!
Official thread: http://minetest.net/forum/viewtopic.php?pid=54290#p54290
 


Return to Minetest Features

Who is online

Users browsing this forum: No registered users and 15 guests

cron