diff --git a/mods/inventory_plus/License b/mods/inventory_plus/License new file mode 100644 index 00000000..f7e0b452 --- /dev/null +++ b/mods/inventory_plus/License @@ -0,0 +1,32 @@ +Copyright (c) 2013, Brett O'Donnell http://cornernote.github.io +All rights reserved. + _____ _____ _____ _____ _____ _____ +| |___| __ | | |___| __ | | |___|_ _|___ +| --| . | -| | | | -_| -| | | | . | | | | -_| +|_____|___|__|__|_|___|___|__|__|_|___|___| |_| |___| + + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + +* Neither the name of the organization nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/mods/inventory_plus/depends.txt b/mods/inventory_plus/depends.txt new file mode 100644 index 00000000..b4747143 --- /dev/null +++ b/mods/inventory_plus/depends.txt @@ -0,0 +1,4 @@ +default +sethome? +creative? +intllib? diff --git a/mods/inventory_plus/home_gui.lua b/mods/inventory_plus/home_gui.lua new file mode 100644 index 00000000..6ab35ac9 --- /dev/null +++ b/mods/inventory_plus/home_gui.lua @@ -0,0 +1,64 @@ + +-- Load support for intllib. +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP .. "/intllib.lua") + +-- static spawn position +local statspawn = minetest.string_to_pos(minetest.settings:get("static_spawnpoint")) + or {x = 0, y = 12, z = 0} +local home_gui = {} + +-- get_formspec +home_gui.get_formspec = function(player) + + local formspec = "size[6,2]" + .. default.gui_bg + .. default.gui_bg_img + .. default.gui_slots + .. "button[0,0;2,0.5;main;" .. S("Back") .. "]" + .. "button_exit[0,1.5;2,0.5;home_gui_set;" .. S("Set Home") .. "]" + .. "button_exit[2,1.5;2,0.5;home_gui_go;Go " .. S("Home") .. "]" + .. "button_exit[4,1.5;2,0.5;home_gui_spawn;" .. S("Spawn") .. "]" + + local home = sethome.get( player:get_player_name() ) + + if home then + formspec = formspec + .."label[2.5,-0.2;" .. S("Home set to:") .. "]" + .."label[2.5,0.4;".. minetest.pos_to_string(vector.round(home)) .. "]" + end + + return formspec +end + +-- add inventory_plus page when player joins +minetest.register_on_joinplayer(function(player) + inventory_plus.register_button(player,"home_gui",S("Home Pos")) +end) + +-- what to do when we press da buttons +minetest.register_on_player_receive_fields(function(player, formname, fields) + local privs = minetest.get_player_privs(player:get_player_name()).home + if privs and fields.home_gui_set then + sethome.set( player:get_player_name(), player:get_pos() ) + end + if privs and fields.home_gui_go then + sethome.go( player:get_player_name() ) + end + if privs and fields.home_gui_spawn then + player:setpos(statspawn) + end + if fields.home_gui or fields.home_gui_set or fields.home_gui_go then + inventory_plus.set_inventory_formspec(player, home_gui.get_formspec(player)) + end +end) + +-- spawn command +minetest.register_chatcommand("spawn", { + description = S("Go to Spawn"), + privs = {home = true}, + func = function(name) + local player = minetest.get_player_by_name(name) + player:setpos(statspawn) + end, +}) diff --git a/mods/inventory_plus/init.lua b/mods/inventory_plus/init.lua new file mode 100644 index 00000000..7fe804a2 --- /dev/null +++ b/mods/inventory_plus/init.lua @@ -0,0 +1,206 @@ +--[[ + +Inventory Plus for Minetest + +Copyright (c) 2012 cornernote, Brett O'Donnell +Source Code: https://github.com/cornernote/minetest-inventory_plus +License: BSD-3-Clause https://raw.github.com/cornernote/minetest-inventory_plus/master/LICENSE + +Edited by TenPlus1 (19th October 2016) + +]]-- + +-- Load support for intllib. +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP .. "/intllib.lua") + +-- compatibility with older minetest versions +if not rawget(_G, "creative") then + local creative = {} +end + +-- check for new creative addition +local addition = "" +if creative.formspec_add then + creative.formspec_add = "button[5.4,4.2;2.65,0.3;main;" .. S("Back") .. "]" +else + addition = "button[5.4,4.2;2.65,0.3;main;" .. S("Back") .. "]" +end + +-- expose api +inventory_plus = {} + +-- define buttons +inventory_plus.buttons = {} + +-- default inventory page +inventory_plus.default = minetest.settings:get("inventory_default") or "craft" + +-- register_button +inventory_plus.register_button = function(player, name, label) + + local player_name = player:get_player_name() + + if inventory_plus.buttons[player_name] == nil then + inventory_plus.buttons[player_name] = {} + end + + inventory_plus.buttons[player_name][name] = label +end + +-- set_inventory_formspec +inventory_plus.set_inventory_formspec = function(player, formspec) + + -- error checking + if not formspec then + return + end + + -- short pause before setting inventory + minetest.after(0.01, function() + player:set_inventory_formspec(formspec) + end) +end + +-- create detached inventory for trashcan +local trashInv = minetest.create_detached_inventory("trash", { + + on_put = function(inv, toList, toIndex, stack, player) + inv:set_stack(toList, toIndex, {}) + end +}) + +trashInv:set_size("main", 1) + +-- get_formspec +inventory_plus.get_formspec = function(player, page) + + if not player then + return + end + + -- creative page + if page == "creative" then + + return player:get_inventory_formspec() .. addition + end + + -- default inventory page + local formspec = "size[8,7.5]" + .. default.gui_bg + .. default.gui_bg_img + .. default.gui_slots + .. "list[current_player;main;0,3.5;8,4;]" + + -- craft page + if page == "craft" then + + if not player:get_inventory() then + print (S("[Inventory Plus] NO PLAYER INVENTORY FOUND!")) + return + end + + formspec = formspec + .. "button[0,1;2,0.5;main;" .. S("Back") .. "]" + .. "list[current_player;craftpreview;7,1;1,1;]" + .. "list[current_player;craft;3,0;3,3;]" + .. "listring[current_name;craft]" + .. "listring[current_player;main]" + -- trash icon + .. "list[detached:trash;main;1,2;1,1;]" + .. "image[1.1,2.1;0.8,0.8;creative_trash_icon.png]" + end + + -- main page + if page == "main" then + + local name = player:get_player_name() + local num = 0 + + -- count buttons + for k, v in pairs( inventory_plus.buttons[name] ) do + num = num + 1 + end + + -- buttons + local x = 0 + local f = math.ceil(num / 4) + local y = (2.5 / 2) / f + + for k, v in pairs( inventory_plus.buttons[name] ) do + + formspec = formspec .. "button[" .. x .. "," + .. y .. ";2,0.5;" .. k .. ";" .. v .. "]" + + x = x + 2 + + if x == 8 then + x = 0 + y = y + 1 + end + end + end + + return formspec +end + +-- register_on_joinplayer +minetest.register_on_joinplayer(function(player) + + inventory_plus.register_button(player,"craft", S("Craft")) + + if minetest.settings:get_bool("creative_mode") + or minetest.check_player_privs(player:get_player_name(), {creative = true}) then + inventory_plus.register_button(player, "creative_prev", S("Creative")) + end + + minetest.after(1, function() + + inventory_plus.set_inventory_formspec(player, + inventory_plus.get_formspec(player, inventory_plus.default)) + end) +end) + +-- register_on_player_receive_fields +minetest.register_on_player_receive_fields(function(player, formname, fields) + + -- main + if fields.main then + + inventory_plus.set_inventory_formspec(player, + inventory_plus.get_formspec(player, "main")) + + return + end + + -- craft + if fields.craft then + + inventory_plus.set_inventory_formspec(player, + inventory_plus.get_formspec(player, "craft")) + + return + end + + -- creative + if fields.creative_prev + or fields.creative_next then + + minetest.after(0.1, function() + + inventory_plus.set_inventory_formspec(player, + inventory_plus.get_formspec(player, "creative")) + end) + + return + end +end) + +-- compatabiltiy with old workbench (right-click wood to get items back) +minetest.register_alias("inventory_plus:workbench", "default:wood") + +-- Add Home GUI +if minetest.get_modpath("sethome") and sethome then + print (S("sethome found, adding home_gui to inventory plus")) + dofile(MP .. "/home_gui.lua") +end diff --git a/mods/inventory_plus/intllib.lua b/mods/inventory_plus/intllib.lua new file mode 100644 index 00000000..6669d720 --- /dev/null +++ b/mods/inventory_plus/intllib.lua @@ -0,0 +1,45 @@ + +-- Fallback functions for when `intllib` is not installed. +-- Code released under Unlicense . + +-- Get the latest version of this file at: +-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua + +local function format(str, ...) + local args = { ... } + local function repl(escape, open, num, close) + if escape == "" then + local replacement = tostring(args[tonumber(num)]) + if open == "" then + replacement = replacement..close + end + return replacement + else + return "@"..open..num..close + end + end + return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl)) +end + +local gettext, ngettext +if minetest.get_modpath("intllib") then + if intllib.make_gettext_pair then + -- New method using gettext. + gettext, ngettext = intllib.make_gettext_pair() + else + -- Old method using text files. + gettext = intllib.Getter() + end +end + +-- Fill in missing functions. + +gettext = gettext or function(msgid, ...) + return format(msgid, ...) +end + +ngettext = ngettext or function(msgid, msgid_plural, n, ...) + return format(n==1 and msgid or msgid_plural, ...) +end + +return gettext, ngettext