mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-01-23 16:30:19 +01:00
debug|rewrite invtweak
https://github.com/Ombridride/minetest-minetestforfun-server/issues/133
This commit is contained in:
parent
990963550c
commit
37d5883c41
@ -219,73 +219,55 @@ if auto_refill == true then
|
|||||||
end
|
end
|
||||||
|
|
||||||
local wielded = {}
|
local wielded = {}
|
||||||
wielded.name = {}
|
wielded["name"] = {}
|
||||||
wielded.wear = {}
|
wielded["wear"] = {}
|
||||||
|
wielded["index"] = {}
|
||||||
|
|
||||||
minetest.register_on_punchnode(function(pos, node, puncher)
|
minetest.register_on_punchnode(function(pos, node, puncher)
|
||||||
if not puncher or minetest.setting_getbool("creative_mode") then
|
if not puncher or minetest.setting_getbool("creative_mode") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local name = puncher:get_player_name()
|
local name = puncher:get_player_name()
|
||||||
|
if not name then return end
|
||||||
local item = puncher:get_wielded_item()
|
local item = puncher:get_wielded_item()
|
||||||
|
if not item then return end
|
||||||
|
local index = puncher:get_wield_index()
|
||||||
local tname = item:get_name()
|
local tname = item:get_name()
|
||||||
local def = minetest.registered_tools[tname]
|
local def = minetest.registered_tools[tname]
|
||||||
|
|
||||||
wielded.name[name] = tname
|
if not tname or tname == "" or not def then -- if empty or not tools
|
||||||
|
wielded["name"][name] = ""
|
||||||
if not item or not tname or tname == "" or not def then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
wielded["name"][name] = tname
|
||||||
|
wielded["index"][name] = index
|
||||||
local typ = def.type
|
local typ = def.type
|
||||||
if not typ or typ ~= "tool" then
|
if not typ or typ ~= "tool" then --if tools, true
|
||||||
return
|
wielded["wear"][name] = false
|
||||||
|
else
|
||||||
|
wielded["wear"][name] = true
|
||||||
end
|
end
|
||||||
wielded.wear[name] = item:get_wear()
|
|
||||||
-- TODO: re-add for custom tools like lighter
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||||
if not digger then return end
|
if not digger then return end
|
||||||
|
|
||||||
local name = digger:get_player_name()
|
local name = digger:get_player_name()
|
||||||
|
if not name then return end
|
||||||
local item = digger:get_wielded_item()
|
local item = digger:get_wielded_item()
|
||||||
|
if not item then return end
|
||||||
local index = digger:get_wield_index()
|
local index = digger:get_wield_index()
|
||||||
local tname = item:get_name()
|
local tname = item:get_name()
|
||||||
local def = minetest.registered_tools[tname]
|
if tname ~= "" then return end --new not empty, return
|
||||||
|
|
||||||
|
local old_name = wielded["name"][name]
|
||||||
|
if old_name == nil or old_name == "" then return end -- old empty, not replace
|
||||||
|
|
||||||
if not item then
|
local old_wear = wielded["wear"][name]
|
||||||
return
|
local old_index = wielded["index"][name]
|
||||||
end
|
if index == old_index and old_wear == true then -- if identical index and old is tools, replace
|
||||||
if tname ~= "" then
|
minetest.sound_play("invtweak_tool_break", {pos = digger:getpos(), gain = 0.9, max_hear_distance = 5})
|
||||||
if not def then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
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 and old > 0 and new == 0 then
|
|
||||||
wielded.wear[name] = new
|
|
||||||
minetest.sound_play("invtweak_tool_break", {
|
|
||||||
pos = digger:getpos(),
|
|
||||||
gain = 0.9,
|
|
||||||
max_hear_distance = 5
|
|
||||||
})
|
|
||||||
if auto_refill == true then
|
if auto_refill == true then
|
||||||
minetest.after(0.01, refill, digger, old_name, index)
|
minetest.after(0.01, refill, digger, old_name, index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user