forked from mtcontrib/invtweak
Version MFF.
This commit is contained in:
parent
5dadd5c2c3
commit
02217047db
2
README.txt
Normal file → Executable file
2
README.txt
Normal file → Executable file
@ -1,6 +1,6 @@
|
|||||||
Minetest mod "Inventory Tweaks"
|
Minetest mod "Inventory Tweaks"
|
||||||
===============================
|
===============================
|
||||||
version: 2.0.1
|
version: 2.0
|
||||||
|
|
||||||
License of source code: WTFPL
|
License of source code: WTFPL
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
0
depends.txt
Normal file → Executable file
0
depends.txt
Normal file → Executable file
81
init.lua
Normal file → Executable file
81
init.lua
Normal file → Executable file
@ -5,16 +5,17 @@ tweak.formspec = {}
|
|||||||
|
|
||||||
tweak.buttons = {
|
tweak.buttons = {
|
||||||
--sort_asc
|
--sort_asc
|
||||||
"0.55,0.6;sort_asc;^]".."tooltip[sort_asc;sort Items asc.;#30434C;#FFF]",
|
"0.8,0.6;sort_asc;^]".."tooltip[sort_asc;sort Items asc.;#30434C;#FFF]",
|
||||||
--sort_desc
|
--sort_desc
|
||||||
"0.55,0.6;sort_desc;v]".."tooltip[sort_desc;sort Items desc.;#30434C;#FFF]",
|
"0.8,0.6;sort_desc;v]".."tooltip[sort_desc;sort Items desc.;#30434C;#FFF]",
|
||||||
--concatenate
|
--concatenate
|
||||||
"0.65,0.6;sort;›•]".."tooltip[sort;stack Items and sort asc.;#30434C;#FFF]"
|
"0.8,0.6;sort;·»]".."tooltip[sort;stack Items and sort asc.;#30434C;#FFF]"
|
||||||
}
|
}
|
||||||
|
|
||||||
local function get_formspec_size(formspec)
|
local function get_formspec_size(formspec)
|
||||||
local w = 8
|
local w = 8
|
||||||
local h = 7.5
|
local h = 7.5
|
||||||
|
if not formspec then return end
|
||||||
local sstring = string.find(formspec,"size[",1,true)
|
local sstring = string.find(formspec,"size[",1,true)
|
||||||
if sstring ~= nil then
|
if sstring ~= nil then
|
||||||
sstring = string.sub(formspec, sstring+5)
|
sstring = string.sub(formspec, sstring+5)
|
||||||
@ -38,7 +39,7 @@ local function add_buttons(player, formspec)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
for i=1,#tweak.buttons do
|
for i=1,#tweak.buttons do
|
||||||
formspec = formspec .. "button["..w-2+(i*0.5)..",-0.2;" .. tweak.buttons[i]
|
formspec = formspec .. "button["..w-(0.8+(i*0.8))..",0.2;" .. tweak.buttons[i]
|
||||||
end
|
end
|
||||||
player:set_inventory_formspec(formspec)
|
player:set_inventory_formspec(formspec)
|
||||||
return formspec
|
return formspec
|
||||||
@ -191,8 +192,11 @@ end
|
|||||||
-- tool break sound + autorefill
|
-- tool break sound + autorefill
|
||||||
function refill(player, stck_name, index)
|
function refill(player, stck_name, index)
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
|
local old_stack = inv:get_stack("main", index)
|
||||||
|
if old_stack:get_name() == stck_name then return end
|
||||||
|
if inv:get_list("main") then
|
||||||
for i,stack in ipairs(inv:get_list("main")) do
|
for i,stack in ipairs(inv:get_list("main")) do
|
||||||
if stack:get_name() == stck_name then
|
if i ~= index and stack:get_name() == stck_name then
|
||||||
inv:set_stack("main", index, stack)
|
inv:set_stack("main", index, stack)
|
||||||
stack:clear()
|
stack:clear()
|
||||||
inv:set_stack("main", i, stack)
|
inv:set_stack("main", i, stack)
|
||||||
@ -201,6 +205,7 @@ function refill(player, stck_name, index)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if auto_refill == true then
|
if auto_refill == true then
|
||||||
minetest.register_on_placenode(function(pos, newnode, placer, oldnode)
|
minetest.register_on_placenode(function(pos, newnode, placer, oldnode)
|
||||||
@ -208,7 +213,7 @@ if auto_refill == true then
|
|||||||
local index = placer:get_wield_index()
|
local index = placer:get_wield_index()
|
||||||
local cnt = placer:get_wielded_item():get_count()-1
|
local cnt = placer:get_wielded_item():get_count()-1
|
||||||
if minetest.setting_getbool("creative_mode") then
|
if minetest.setting_getbool("creative_mode") then
|
||||||
return true
|
return
|
||||||
else
|
else
|
||||||
if cnt == 0 then
|
if cnt == 0 then
|
||||||
minetest.after(0.01, refill, placer, newnode.name, index)
|
minetest.after(0.01, refill, placer, newnode.name, index)
|
||||||
@ -218,73 +223,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 > 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)
|
||||||
|
BIN
sounds/invtweak_tool_break.ogg
Normal file → Executable file
BIN
sounds/invtweak_tool_break.ogg
Normal file → Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user