From f0edb9a710afed5b8c0287193c9bcccfefdc6c46 Mon Sep 17 00:00:00 2001 From: Alexander Weber Date: Sun, 19 Mar 2017 19:39:58 +0100 Subject: [PATCH] Inventory compat cleanup fix inventory_plus after cleanup. Create own register_on_player_receive_fields for this inventory removed smart_inventory (moved to the inventoy mod), adjusted sfinv moved sfinv to own mod 3d_armor_sfinv moved unified_inventory to 3d_armor_ui moved inventory_plus support to own mod 3d_armor_ip --- 3d_armor/api.lua | 15 ++--- 3d_armor/depends.txt | 3 - 3d_armor/init.lua | 105 +-------------------------------- 3d_armor_ip/LICENSE.txt | 5 ++ 3d_armor_ip/depends.txt | 2 + 3d_armor_ip/description.txt | 1 + 3d_armor_ip/init.lua | 34 +++++++++++ 3d_armor_sfinv/LICENSE.txt | 5 ++ 3d_armor_sfinv/depends.txt | 2 + 3d_armor_sfinv/description.txt | 1 + 3d_armor_sfinv/init.lua | 18 ++++++ 3d_armor_ui/LICENSE.txt | 5 ++ 3d_armor_ui/depends.txt | 2 + 3d_armor_ui/description.txt | 1 + 3d_armor_ui/init.lua | 44 ++++++++++++++ 15 files changed, 129 insertions(+), 114 deletions(-) create mode 100644 3d_armor_ip/LICENSE.txt create mode 100644 3d_armor_ip/depends.txt create mode 100644 3d_armor_ip/description.txt create mode 100644 3d_armor_ip/init.lua create mode 100644 3d_armor_sfinv/LICENSE.txt create mode 100644 3d_armor_sfinv/depends.txt create mode 100644 3d_armor_sfinv/description.txt create mode 100644 3d_armor_sfinv/init.lua create mode 100644 3d_armor_ui/LICENSE.txt create mode 100644 3d_armor_ui/depends.txt create mode 100644 3d_armor_ui/description.txt create mode 100644 3d_armor_ui/init.lua diff --git a/3d_armor/api.lua b/3d_armor/api.lua index 8d4b9fe..33866a0 100644 --- a/3d_armor/api.lua +++ b/3d_armor/api.lua @@ -6,18 +6,15 @@ armor = { timer = 0, elements = {"head", "torso", "legs", "feet"}, physics = {"jump", "speed", "gravity"}, - formspec = "size[8,8.5]".. + formspec = "image[2.5,0;2,4;armor_preview]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - default.get_hotbar_bg(0,4.25).. - "image[2,0.5;2,4;armor_preview]".. - "list[current_player;main;0,4.25;8,1;]".. - "list[current_player;main;0,5.5;8,3;8]".. - "list[current_player;craft;4,0.5;3,3;]".. - "list[current_player;craftpreview;7,1.5;1,1;]".. - "listring[current_player;main]".. - "listring[current_player;craft]", + default.get_hotbar_bg(0, 4.7).. + "label[5,1;Level: armor_level]".. + "label[5,1.5;Heal: armor_heal]".. + "list[current_player;main;0,4.7;8,1;]".. + "list[current_player;main;0,5.85;8,3;8]", def = {}, textures = {}, default_skin = "character", diff --git a/3d_armor/depends.txt b/3d_armor/depends.txt index 0d20f61..b4197a9 100644 --- a/3d_armor/depends.txt +++ b/3d_armor/depends.txt @@ -1,9 +1,6 @@ default player_monoids? armor_monoid? -inventory_plus? -unified_inventory? -sfinv? fire? ethereal? bakedclay? diff --git a/3d_armor/init.lua b/3d_armor/init.lua index 3d67f45..945a371 100644 --- a/3d_armor/init.lua +++ b/3d_armor/init.lua @@ -55,96 +55,11 @@ dofile(modpath.."/armor.lua") -- Mod Compatibility -local armor_formpage = "image[2.5,0;2,4;armor_preview]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - default.get_hotbar_bg(0, 4.7).. - "label[5,1;Level: armor_level]".. - "label[5,1.5;Heal: armor_heal]".. - "list[current_player;main;0,4.7;8,1;]".. - "list[current_player;main;0,5.85;8,3;8]" if armor.config.fire_protect then - armor_formpage = armor_formpage.."label[5,2;Fire: armor_fire]" + armor.formspec = armor.formspec.."label[5,2;Fire: armor_fire]" end -if minetest.global_exists("technic") then - armor_formpage = armor_formpage.."label[5,2.5;Radiation: armor_radiation]" -end -if minetest.get_modpath("inventory_plus") then - armor.inv_mod = "inventory_plus" - armor.formspec = "size[8,8.5]button[6,0;2,0.5;main;Back]"..armor_formpage - armor:register_on_update(function(player) - local name = player:get_player_name() - local formspec = armor:get_armor_formspec(name, true) - local page = player:get_inventory_formspec() - if page:find("detached:"..name.."_armor") then - inventory_plus.set_inventory_formspec(player, formspec) - end - end) - if minetest.get_modpath("crafting") then - inventory_plus.get_formspec = function(player, page) - end - end -elseif minetest.get_modpath("unified_inventory") and not unified_inventory.sfinv_compat_layer then - armor.inv_mod = "unified_inventory" - armor:register_on_update(function(player) - local name = player:get_player_name() - if unified_inventory.current_page[name] == "armor" then - unified_inventory.set_inventory_formspec(player, "armor") - end - end) - unified_inventory.register_button("armor", { - type = "image", - image = "inventory_plus_armor.png", - }) - unified_inventory.register_page("armor", { - get_formspec = function(player, perplayer_formspec) - local fy = perplayer_formspec.formspec_y - local name = player:get_player_name() - local formspec = "background[0.06,"..fy..";7.92,7.52;3d_armor_ui_form.png]".. - "label[0,0;Armor]".. - "list[detached:"..name.."_armor;armor;0,"..fy..";2,3;]".. - "image[2.5,"..(fy - 0.25)..";2,4;"..armor.textures[name].preview.."]".. - "label[5.0,"..(fy + 0.0)..";Level: "..armor.def[name].level.."]".. - "label[5.0,"..(fy + 0.5)..";Heal: "..armor.def[name].heal.."]".. - "listring[current_player;main]".. - "listring[detached:"..name.."_armor;armor]" - if armor.config.fire_protect then - formspec = formspec.."label[5.0,"..(fy + 1.0).. - ";Fire: "..armor.def[name].fire.."]" - end - if minetest.global_exists("technic") then - formspec = formspec.."label[5.0,"..(fy + 1.5).. - ";Radiation: "..armor.def[name].radiation.."]" - end - return {formspec=formspec} - end, - }) -elseif minetest.get_modpath("inventory_enhanced") then - armor.inv_mod = "inventory_enhanced" -elseif minetest.get_modpath("smart_inventory") then - armor.inv_mod = "smart_inventory" - armor:register_on_update(function(player) - local name = player:get_player_name() - local state = smart_inventory.get_page_state("player", name) - if state then - state:get("update_hook"):submit() - end - end) -elseif minetest.get_modpath("sfinv") then - armor.inv_mod = "sfinv" - armor.formspec = armor_formpage - armor:register_on_update(function(player) - sfinv.set_player_inventory_formspec(player) - end) - sfinv.register_page("3d_armor:armor", { - title = "Armor", - get = function(self, player, context) - local name = player:get_player_name() - local formspec = armor:get_armor_formspec(name, true) - return sfinv.make_formspec(player, context, formspec, false) - end - }) +if minetest.get_modpath("technic") then + armor.formspec = armor.formspec.."label[5,2.5;Radiation: armor_radiation]" end local skin_mods = {"skins", "u_skins", "simple_skins", "wardrobe"} for _, mod in pairs(skin_mods) do @@ -190,11 +105,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if not name then return end - if armor.inv_mod == "inventory_plus" and fields.armor then - local formspec = armor:get_armor_formspec(name, true) - inventory_plus.set_inventory_formspec(player, formspec) - return - end for field, _ in pairs(fields) do if string.find(field, "skins_set") then minetest.after(0, function(player) @@ -249,9 +159,6 @@ minetest.register_on_joinplayer(function(player) return count end, }, name) - if armor.inv_mod == "inventory_plus" then - inventory_plus.register_button(player,"armor", "Armor") - end armor_inv:set_size("armor", 6) player_inv:set_size("armor", 6) for i=1, 6 do @@ -312,12 +219,6 @@ if armor.config.drop == true or armor.config.destroy == true then end end armor:set_player_armor(player) - if armor.inv_mod == "unified_inventory" then - unified_inventory.set_inventory_formspec(player, "craft") - elseif armor.inv_mod == "inventory_plus" then - local formspec = inventory_plus.get_formspec(player, "main") - inventory_plus.set_inventory_formspec(player, formspec) - end if armor.config.destroy == false then minetest.after(armor.config.bones_delay, function() local meta = nil diff --git a/3d_armor_ip/LICENSE.txt b/3d_armor_ip/LICENSE.txt new file mode 100644 index 0000000..6b58a7a --- /dev/null +++ b/3d_armor_ip/LICENSE.txt @@ -0,0 +1,5 @@ +[mod] 3d Armor integration to inventory plus [3d_armor_ip] +========================================================== + +License Source Code: (C) 2012-2017 Stuart Jones - LGPL v2.1 + diff --git a/3d_armor_ip/depends.txt b/3d_armor_ip/depends.txt new file mode 100644 index 0000000..e96293b --- /dev/null +++ b/3d_armor_ip/depends.txt @@ -0,0 +1,2 @@ +3d_armor +inventory_plus? diff --git a/3d_armor_ip/description.txt b/3d_armor_ip/description.txt new file mode 100644 index 0000000..01e1b54 --- /dev/null +++ b/3d_armor_ip/description.txt @@ -0,0 +1 @@ +Adds 3d_armor page to the inventory plus diff --git a/3d_armor_ip/init.lua b/3d_armor_ip/init.lua new file mode 100644 index 0000000..59c21c3 --- /dev/null +++ b/3d_armor_ip/init.lua @@ -0,0 +1,34 @@ +if not minetest.global_exists("inventory_plus") then + minetest.log("warning", "3d_armor_ip: Mod loaded but unused.") + return +end + +armor.formspec = "size[8,8.5]button[6,0;2,0.5;main;Back]"..armor.formspec +armor:register_on_update(function(player) + local name = player:get_player_name() + local formspec = armor:get_armor_formspec(name, true) + local page = player:get_inventory_formspec() + if page:find("detached:"..name.."_armor") then + inventory_plus.set_inventory_formspec(player, formspec) + end +end) + +if minetest.get_modpath("crafting") then + inventory_plus.get_formspec = function(player, page) + end +end + +minetest.register_on_joinplayer(function(player) + inventory_plus.register_button(player,"armor", "Armor") +end) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if fields.armor then + local name = armor:get_valid_player(player, "[on_player_receive_fields]") + if not name then + return + end + local formspec = armor:get_armor_formspec(name, true) + inventory_plus.set_inventory_formspec(player, formspec) + end +end) diff --git a/3d_armor_sfinv/LICENSE.txt b/3d_armor_sfinv/LICENSE.txt new file mode 100644 index 0000000..538b950 --- /dev/null +++ b/3d_armor_sfinv/LICENSE.txt @@ -0,0 +1,5 @@ +[mod] 3d Armor sfinv integration [3d_armor_sfinv] +================================================= + +License Source Code: (C) 2012-2017 Stuart Jones - LGPL v2.1 + diff --git a/3d_armor_sfinv/depends.txt b/3d_armor_sfinv/depends.txt new file mode 100644 index 0000000..c7beeda --- /dev/null +++ b/3d_armor_sfinv/depends.txt @@ -0,0 +1,2 @@ +3d_armor +sfinv? diff --git a/3d_armor_sfinv/description.txt b/3d_armor_sfinv/description.txt new file mode 100644 index 0000000..0ef2ae9 --- /dev/null +++ b/3d_armor_sfinv/description.txt @@ -0,0 +1 @@ +Adds 3d_armor page to the sfinv inventory diff --git a/3d_armor_sfinv/init.lua b/3d_armor_sfinv/init.lua new file mode 100644 index 0000000..ede9007 --- /dev/null +++ b/3d_armor_sfinv/init.lua @@ -0,0 +1,18 @@ +if not minetest.global_exists("sfinv") then + minetest.log("warning", "3d_armor_sfinv: Mod loaded but unused.") + return +end + +sfinv.register_page("3d_armor:armor", { + title = "Armor", + get = function(self, player, context) + local name = player:get_player_name() + local formspec = armor:get_armor_formspec(name, true) + return sfinv.make_formspec(player, context, formspec, false) + end +}) +armor:register_on_update(function(player) + if sfinv.enabled then + sfinv.set_player_inventory_formspec(player) + end +end) diff --git a/3d_armor_ui/LICENSE.txt b/3d_armor_ui/LICENSE.txt new file mode 100644 index 0000000..50859b0 --- /dev/null +++ b/3d_armor_ui/LICENSE.txt @@ -0,0 +1,5 @@ +[mod] 3d Armor integration to unified inventory [3d_armor_ui] +============================================================= + +License Source Code: (C) 2012-2017 Stuart Jones - LGPL v2.1 + diff --git a/3d_armor_ui/depends.txt b/3d_armor_ui/depends.txt new file mode 100644 index 0000000..cf4ccf9 --- /dev/null +++ b/3d_armor_ui/depends.txt @@ -0,0 +1,2 @@ +3d_armor +unified_inventory? diff --git a/3d_armor_ui/description.txt b/3d_armor_ui/description.txt new file mode 100644 index 0000000..873f876 --- /dev/null +++ b/3d_armor_ui/description.txt @@ -0,0 +1 @@ +Adds 3d_armor page to the unified inventory diff --git a/3d_armor_ui/init.lua b/3d_armor_ui/init.lua new file mode 100644 index 0000000..5ba6f7a --- /dev/null +++ b/3d_armor_ui/init.lua @@ -0,0 +1,44 @@ +if not minetest.global_exists("unified_inventory") then + minetest.log("warning", "3d_armor_ui: Mod loaded but unused.") + return +end + +if unified_inventory.sfinv_compat_layer then + return +end + +armor:register_on_update(function(player) + local name = player:get_player_name() + if unified_inventory.current_page[name] == "armor" then + unified_inventory.set_inventory_formspec(player, "armor") + end +end) + +unified_inventory.register_button("armor", { + type = "image", + image = "inventory_plus_armor.png", +}) + +unified_inventory.register_page("armor", { + get_formspec = function(player, perplayer_formspec) + local fy = perplayer_formspec.formspec_y + local name = player:get_player_name() + local formspec = "background[0.06,"..fy..";7.92,7.52;3d_armor_ui_form.png]".. + "label[0,0;Armor]".. + "list[detached:"..name.."_armor;armor;0,"..fy..";2,3;]".. + "image[2.5,"..(fy - 0.25)..";2,4;"..armor.textures[name].preview.."]".. + "label[5.0,"..(fy + 0.0)..";Level: "..armor.def[name].level.."]".. + "label[5.0,"..(fy + 0.5)..";Heal: "..armor.def[name].heal.."]".. + "listring[current_player;main]".. + "listring[detached:"..name.."_armor;armor]" + if armor.config.fire_protect then + formspec = formspec.."label[5.0,"..(fy + 1.0).. + ";Fire: "..armor.def[name].fire.."]" + end + if minetest.global_exists("technic") then + formspec = formspec.."label[5.0,"..(fy + 1.5).. + ";Radiation: "..armor.def[name].radiation.."]" + end + return {formspec=formspec} + end, +})