diff --git a/minetestforfun_game/mods/creative/init.lua b/minetestforfun_game/mods/creative/init.lua index 809c2aa3..2012d337 100644 --- a/minetestforfun_game/mods/creative/init.lua +++ b/minetestforfun_game/mods/creative/init.lua @@ -152,7 +152,7 @@ if minetest.setting_getbool("creative_mode") then }) minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack) - return true + return end) function minetest.handle_node_drops(pos, drops, digger) diff --git a/mods/builtin_falling/func.lua b/mods/builtin_falling/func.lua index 18f95f02..e9b74dbb 100755 --- a/mods/builtin_falling/func.lua +++ b/mods/builtin_falling/func.lua @@ -121,20 +121,16 @@ function add_falling_protect_item(named) minetest.override_item(named, { on_place = function(itemstack, placer, pointed_thing) if not pointed_thing.type == "node" then - return itemstack + return end local pn = placer:get_player_name() if minetest.is_protected(pointed_thing.above, pn) then - return itemstack + return end minetest.add_node(pointed_thing.above, {name=itemstack:get_name()}) local meta = minetest.get_meta(pointed_thing.above) meta:set_string("owner", pn) nodeupdate(pointed_thing.above) - if not minetest.setting_getbool("creative_mode") then - itemstack:take_item() - end - return itemstack end }) end diff --git a/mods/intweak/README.txt b/mods/intweak/README.txt deleted file mode 100755 index 7283cf7d..00000000 --- a/mods/intweak/README.txt +++ /dev/null @@ -1,30 +0,0 @@ -Minetest mod "Inventory Tweak" -============================== -version: 1.2.2 - -License of source code: WTFPL ------------------------------ -Written 2013 by BlockMen - -This program is free software. It comes without any warranty, to -the extent permitted by applicable law. You can redistribute it -and/or modify it under the terms of the Do What The Fuck You Want -To Public License, Version 2, as published by Sam Hocevar. See -http://sam.zoy.org/wtfpl/COPYING for more details. - -License of sounds: ------------------- -intweak_break_tool.ogg by EdgardEdition (CC BY 3.0), http://www.freesound.org/people/EdgardEdition - - ---USING the mod-- ------------------- - -This mod implements two new functions to the players inventory. First is a breaking sound of any tool, -that is played when a tool breakes after the specific number of uses. - -The second new function is Auto-refill. This function replaces broken tools or emptied stacks with others from your inventory. - - -!! -You can disable the auto-refill by changing first line of init.lua to "local auto_refill = false" \ No newline at end of file diff --git a/mods/intweak/depends.txt b/mods/intweak/depends.txt deleted file mode 100755 index 331d858c..00000000 --- a/mods/intweak/depends.txt +++ /dev/null @@ -1 +0,0 @@ -default \ No newline at end of file diff --git a/mods/intweak/init.lua b/mods/intweak/init.lua deleted file mode 100755 index 3940c5e8..00000000 --- a/mods/intweak/init.lua +++ /dev/null @@ -1,66 +0,0 @@ -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) - minetest.log("action", "intweak-mod: refilled stack of" .. player:get_player_name() ) - 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 minetest.setting_getbool("creative_mode") then - return true - else - if cnt == 0 then - minetest.after(0.01, refill, placer, newnode.name, index) - end - end - end) -end - - -local ttyp = {} -local tools = {} - -minetest.register_on_punchnode(function(pos, node, puncher) - if not puncher then return end - if minetest.setting_getbool("creative_mode") then return end - local pn = puncher:get_player_name() - tools[pn] = puncher:get_wielded_item():get_name() - if minetest.registered_items[tools[pn]] == nil then return end - ttyp[pn] = minetest.registered_items[tools[pn]].type - local left = puncher:get_wielded_item():get_wear() + 65535/65--) - local tab = minetest.registered_tools[tools[pn]] - 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[pn] == "tool" and left >= 65535 then - minetest.sound_play("intweak_tool_break", {pos = puncher:getpos(), gain = 1, max_hear_distance = 5}) - if auto_refill == true then minetest.after(0.01, refill, puncher, tools[pn], puncher:get_wield_index()) end - end -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 pn = digger:get_player_name() - local num = digger:get_wielded_item():get_wear() - local index = digger:get_wield_index() - if num == 0 and ttyp[pn] == "tool" and digger:get_wielded_item():get_name() == "" then - minetest.sound_play("intweak_tool_break", {pos = digger:getpos(),gain = 1, max_hear_distance = 5}) - if auto_refill == true then minetest.after(0.01, refill, digger, tools[pn], index) end - end -end) - -print("[Mod] Inventory Tweak _loaded") diff --git a/mods/intweak/sounds/intweak_tool_break.ogg b/mods/intweak/sounds/intweak_tool_break.ogg deleted file mode 100755 index 57b1122b..00000000 Binary files a/mods/intweak/sounds/intweak_tool_break.ogg and /dev/null differ diff --git a/mods/invtweak/README.txt b/mods/invtweak/README.txt new file mode 100644 index 00000000..85660526 --- /dev/null +++ b/mods/invtweak/README.txt @@ -0,0 +1,42 @@ +Minetest mod "Inventory Tweaks" +=============================== +version: 2.0 + +License of source code: WTFPL +----------------------------- +Written 2013-2015 by BlockMen + +This program is free software. It comes without any warranty, to +the extent permitted by applicable law. You can redistribute it +and/or modify it under the terms of the Do What The Fuck You Want +To Public License, Version 2, as published by Sam Hocevar. See +http://sam.zoy.org/wtfpl/COPYING for more details. + +License of sounds: +------------------ +invtweak_break_tool.ogg by EdgardEdition (CC BY 3.0), http://www.freesound.org/people/EdgardEdition + + +~About~ +------- +This mod add different new functions to Minetest. + +First: This mod adds 3 different buttons to player inventory. With those buttons you can sort your inventory easily. +"›•"-Button concernates all stacks to their maximum size. +"^"-Button sorts all items in an ascending order +"v"-Button sorts all items in an descending order + +NOTE: It's currently only working for the player inventory, not for chests or other formspecs. + +Furthermore this mod has the ability to refill your wielded items automaticly. For example your current tool +break and you have one more of the same type (e.g. a stone pickaxe) this mod put it right in you hand +and you can keep digging our placing nodes without opening the inventory. +You can disable this setting by adding/changing following to your minetest.conf file: "invtweak_autorefill = false" + +As a small gimmick it adds also a sound when a tool breaks, just to improve the atmosphere of the gameplay. + + +Supported mods: +- unified_inventory +- 3d_armor. + diff --git a/mods/invtweak/depends.txt b/mods/invtweak/depends.txt new file mode 100644 index 00000000..86aaa64c --- /dev/null +++ b/mods/invtweak/depends.txt @@ -0,0 +1,3 @@ +default +3d_armor? +unified_inventory? \ No newline at end of file diff --git a/mods/invtweak/init.lua b/mods/invtweak/init.lua new file mode 100644 index 00000000..928580fc --- /dev/null +++ b/mods/invtweak/init.lua @@ -0,0 +1,287 @@ +local auto_refill = minetest.setting_getbool("invtweak_auto_refill") or true + +local tweak = {} +tweak.formspec = {} + +tweak.buttons = { +--sort_asc +"0.8,0.6;sort_asc;^]".."tooltip[sort_asc;sort Items asc.;#30434C;#FFF]", +--sort_desc +"0.8,0.6;sort_desc;v]".."tooltip[sort_desc;sort Items desc.;#30434C;#FFF]", +--concatenate +"0.8,0.6;sort;·»]".."tooltip[sort;stack Items and sort asc.;#30434C;#FFF]" +} + +local function get_formspec_size(formspec) + local w = 8 + local h = 7.5 + local sstring = string.find(formspec,"size[",1,true) + if sstring ~= nil then + sstring = string.sub(formspec, sstring+5) + local p = string.find(sstring,",") + w = string.sub(sstring,1,p-1) + sstring = string.sub(sstring,p+1,string.find(sstring,"]")+2) + p = string.find(sstring,",") + if p == nil then p = string.find(sstring,"]") end + h = string.sub(sstring,1,p-1) + end + return w,h +end + +local function add_buttons(player, formspec) + local name = player:get_player_name() + if not formspec then + formspec = player:get_inventory_formspec() + end + local w,h = get_formspec_size(formspec) + for i=1,#tweak.buttons do + formspec = formspec .. "button["..w-(0.8+(i*0.8))..",0.2;" .. tweak.buttons[i] + end + player:set_inventory_formspec(formspec) + return formspec +end + +local armor_mod = minetest.get_modpath("3d_armor") +local ui_mod = minetest.get_modpath("unified_inventory") +-- override mods formspec function +if ui_mod then + local org = unified_inventory.get_formspec + unified_inventory.get_formspec = function(player, page) + local formspec = org(player, page) + return add_buttons(player, formspec) + end +end +if armor_mod and not ui_mod then + local org = armor.get_armor_formspec + armor.get_armor_formspec = function(self, name) + local formspec = org(self, name) + return add_buttons(minetest.get_player_by_name(name), formspec) + end +end + +minetest.register_on_joinplayer(function(player) + local formspec = nil + if armor_mod and not ui_mod then + formspec = armor.get_armor_formspec(self, player:get_player_name()) + end + minetest.after(0.65,function() + add_buttons(player, formspec) + end) +end) + + +local function comp_asc(w1,w2) + if w1.name < w2.name then + return true + end +end + +local function comp_desc(w1,w2) + if w1.name > w2.name then + return true + end +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if fields.sort_asc then + tweak.sort(player, comp_asc) + end + if fields.sort_desc then + tweak.sort(player, comp_desc) + end + if fields.sort then + tweak.sort(player, comp_asc, true) + end + + -- player inventory + if minetest.setting_getbool("creative_mode") then + add_buttons(player) + end +end) + +-- sort asc without mod prefix +local function comp_in(w1, w2) + local w11 = string.find(w1.name, ":") + local w22 = string.find(w2.name, ":") + if w11 ~= nil then + w11 = string.sub(w1.name,w11) + else + w11 = w1.name + end + if w22 ~= nil then + w22 = string.sub(w2.name,w22) + else + w22 = w2.name + end + if w11 < w22 then + return true + end +end + +tweak.concatenate = function(list) + local last = nil + local last_cnt = 100 + local refresh = false + for _,stack in ipairs(list) do + local i = _ + if refresh then + refresh = false + table.sort(list, comp_asc) + list = tweak.concatenate(list) + break + end + if stack.name ~= "zztmpsortname" and last == stack.name then + if last_cnt < stack.max then + local diff = stack.max - last_cnt + local add = stack.count + if stack.count > diff then + stack.count = stack.count - diff + add = diff + else + stack.name = "zztmpsortname" + refresh = true + end + list[i-1].count = list[i-1].count + add + end + end + last = stack.name + last_cnt = stack.count + end + return list +end + +tweak.sort = function(player, mode, con) + local inv = player:get_inventory() + if inv then + local list = inv:get_list("main") + local tmp_list = {} + + --write whole list as table + for _,stack in ipairs(list) do + local tbl_stack = stack:to_table() + if tbl_stack == nil then tbl_stack = {name="zztmpsortname"} end + tbl_stack.max = stack:get_stack_max() + tmp_list[_]=tbl_stack + end + + -- sort asc/desc + table.sort(tmp_list, mode) + + if con then + tmp_list = tweak.concatenate(tmp_list) + table.sort(tmp_list, mode) + end + + --write back to inventory + for _,stack in ipairs(tmp_list) do + stack.max = nil + if stack.name ~= "zztmpsortname" then + inv:set_stack("main", _, ItemStack(stack)) + else + inv:set_stack("main", _, ItemStack(nil)) + end + end + end +end + + +-- tool break sound + autorefill +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) + minetest.log("action", "Inventory Tweaks: refilled stack("..stck_name..") of " .. player:get_player_name() ) + 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 minetest.setting_getbool("creative_mode") then + return + else + if cnt == 0 then + minetest.after(0.01, refill, placer, newnode.name, index) + end + end + end) +end + +local wielded = {} +wielded.name = {} +wielded.wear = {} + +minetest.register_on_punchnode(function(pos, node, puncher) + 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 custom tools like lighter +end) + +minetest.register_on_dignode(function(pos, oldnode, digger) + 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 + + 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 + minetest.after(0.01, refill, digger, old_name, index) + end + end + end +end) diff --git a/mods/invtweak/sounds/invtweak_tool_break.ogg b/mods/invtweak/sounds/invtweak_tool_break.ogg new file mode 100644 index 00000000..c68522cd Binary files /dev/null and b/mods/invtweak/sounds/invtweak_tool_break.ogg differ diff --git a/worlds/minetestforfun/news.txt b/worlds/minetestforfun/news.txt index 91c1e835..8a5dacc3 100644 --- a/worlds/minetestforfun/news.txt +++ b/worlds/minetestforfun/news.txt @@ -7,6 +7,7 @@ MAJ de "whoison" (la commande "/timeonline " peut aussi être utilisé d MAJ de "mobs" (ajout des chèvres/goats) ---21/04/2015--- (Remerciements : Davedevils, Gael-de-Sailly, Obani, crabman, Mg) +MAJ de "invtweak" (ajout de boutons pour trier l'inventaire) MAJ de "doors" (les trap cherry doors sont compatibles mesecons) MAJ de "metatools" MAJ de "name_restrictions" (ajout de noms dans la blacklist) diff --git a/worlds/minetestforfun/world.mt b/worlds/minetestforfun/world.mt index a31f6551..47a0bed3 100644 --- a/worlds/minetestforfun/world.mt +++ b/worlds/minetestforfun/world.mt @@ -115,7 +115,7 @@ load_mod_bobblocks = true load_mod_pipeworks = true load_mod_factions = true -load_mod_intweak = true +load_mod_invtweak = true load_mod_screwdriver = true load_mod_bone = true