Fix toolbreaking sound

master
BlockMen 2014-05-18 18:37:03 +02:00
parent 0b5db3ceec
commit e59600e3e8
1 changed files with 67 additions and 25 deletions

View File

@ -1,4 +1,4 @@
local auto_refill = false -- set to false if you dont want get refilled your stack automatic
local auto_refill = false -- set to "true" if you want get refilled your stack automatic
function refill(player, stck_name, index)
local inv = player:get_inventory()
@ -7,7 +7,7 @@ function refill(player, stck_name, index)
inv:set_stack("main", index, stack)
stack:clear()
inv:set_stack("main", i, stack)
minetest.log("action", "intweak-mod: refilled stack of" .. player:get_player_name() )
minetest.log("action", "Intweak-mod: refilled stack("..stck_name..") of " .. player:get_player_name() )
return
end
end
@ -28,34 +28,76 @@ if auto_refill == true then
end)
end
local ttyp = {}
local tools = {}
local wielded = {}
wielded.name = {}
wielded.wear = {}
minetest.register_on_punchnode(function(pos, node, puncher)
if not puncher then return end
if minetest.setting_getbool("creative_mode") then return end
tools[puncher:get_player_name()] = puncher:get_wielded_item():get_name()
ttyp[puncher:get_player_name()] = minetest.registered_items[tools[puncher:get_player_name()]].type
local left = puncher:get_wielded_item():get_wear() + 65535/65--)
local tab = minetest.registered_tools[tools[puncher:get_player_name()]]
if tab == nil then return end
local left = tonumber(dump(tab["uses"]))
if left == nil then return end
left = puncher:get_wielded_item():get_wear() + 65535/left
if ttyp[puncher:get_player_name()] == "tool" and left >= 65535 then
minetest.sound_play("default_tool_break", {pos = puncher:getpos(), gain = 1.5, max_hear_distance = 5})
if auto_refill == true then minetest.after(0.01, refill, puncher, tools[puncher:get_player_name()], puncher:get_wield_index()) end
if not puncher or minetest.setting_getbool("creative_mode") then
return
end
local name = puncher:get_player_name()
local item = puncher:get_wielded_item()
local tname = item:get_name()
local def = minetest.registered_tools[tname]
wielded.name[name] = tname
if not item or not tname or tname == "" or not def then
return
end
local typ = def.type
if not typ or typ ~= "tool" then
return
end
wielded.wear[name] = item:get_wear()
-- TODO: re-add for costum tools like lighter
end)
minetest.register_on_dignode(function(pos, oldnode, digger)
if not digger then return end
if minetest.setting_getbool("creative_mode") then return end
local num = digger:get_wielded_item():get_wear()
local index = digger:get_wield_index()
if num == 0 and ttyp[digger:get_player_name()] == "tool" then
minetest.sound_play("default_tool_break", {pos = digger:getpos(),gain = 1.5, max_hear_distance = 5})
if auto_refill == true then minetest.after(0.01, refill, digger, tools[digger:get_player_name()], index) end
if not digger then return end
local name = digger:get_player_name()
local item = digger:get_wielded_item()
local index = digger:get_wield_index()
local tname = item:get_name()
local def = minetest.registered_tools[tname]
if not item then
return
end
if tname ~= "" then
if not def then
return
end
end
--[[if not typ or typ ~= "tool" then
return
end]]
local old_name = wielded.name[name]
if tname == old_name and tname == "" then
return
end
local old = wielded.wear[name]
if not old and tname == "" then
old = 0
end
local new = item:get_wear()
if old ~= new then
if old > 0 and new == 0 then
wielded.wear[name] = new
minetest.sound_play("default_tool_break", {
pos = digger:getpos(),
gain = 0.9,
max_hear_distance = 5
})
if auto_refill == true then
minetest.after(0.01, refill, digger, old_name, index)
end
end
end
end)