Calinou wrote:I like it. This should be in the default game. :D
Mito551 wrote:what part of the code does the auto-refill?
jojoa1997 wrote:could you make this work for all tools like if an item has minetest.register_tool then the things happen. In minitest there are 2 tools that dont do this. Also maybe adding an optional group would be nice if you have set some node/craftitems to do something like a tool
local auto_refill = true -- set to false if you dont want get refilled your stack automatic
function refill(player, stck_name, index)
local inv = player:get_inventory()
for i,stack in ipairs(inv:get_list("main")) do
if stack:get_name() == stck_name then
inv:set_stack("main", index, stack)
stack:clear()
inv:set_stack("main", i, stack)
return
end
end
end
if auto_refill == true then
minetest.register_on_placenode(function(pos, newnode, placer, oldnode)
if not placer then return end
local index = placer:get_wield_index()
local cnt = placer:get_wielded_item():get_count()-1
if cnt == 0 then minetest.after(0.01, refill, placer, newnode.name, index) end
end)
end
local tname = ""
minetest.register_on_punchnode(function(pos, node, puncher)
if not puncher then return end
if puncher:get_wielded_item():get_wear() ~= 0 then
tname = puncher:get_wielded_item():get_name()
else
tname = ""
end
end)
minetest.register_on_dignode(function(pos, oldnode, digger)
if not digger then return end
local num = digger:get_wielded_item():get_wear()
local index = digger:get_wield_index()
if num == 0 and tname ~= "" then
minetest.sound_play("intweak_tool_break", {gain = 1.5, max_hear_distance = 5})
if auto_refill == true then minetest.after(0.01, refill, digger, tname, index) end
end
end)
Casimir wrote:Prevent the game from crashing when there is no digger/placer/puncher: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
#code
btw.: Nice mod. Tried to code the auto refill some time ago but failed. And your solution is more simple than I expected.
Casimir wrote:Lines 17, 27, 36. Is a rare bug caused by certain mods that use place_node without a placer, or dig_node without a digger.
Casimir wrote:I noticed a bug: when you have a unused tool and use it on something it is not made for it breaks instantly. E.g. dig dirt with a brand new pickaxe.
Mossmanikin wrote:Very cool this mod. Minetest has far too less sounds and the auto-refilling is very handy.
Both features seem not to work in creative mode for me (stable 0.4.7, no other mods).
Don't know if it's a bug or a feature, but who needs anything but building blocks in creative mode anyway?
onpon4 wrote:I find it really annoying that this instantly breaks many tools when you use them on the wrong thing. I was annoyed when I lost a perfectly good diamond sword because I was wielding it while I picked up a torch, and I've lost a compass from another mod more than once because of it.
(It's not whatever bug you fixed in 1.2.1. This is version 0.4.7 without creative mode.)
Users browsing this forum: No registered users and 62 guests