initial commit

master
Brett O'Donnell 2012-09-17 18:55:44 +09:30
commit a334ea7470
2 changed files with 143 additions and 0 deletions

51
README.txt Normal file
View File

@ -0,0 +1,51 @@
----------------------------------
Inventory Plus for Minetest
----------------------------------
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
Source Code: https://github.com/cornernote/minetest-bags
License: GPLv3
----------------------------------
Description
----------------------------------
Allows additional formspec buttons to be added to the player inventory screen.
These are processed by your own mod, they can show other formspec screens, or perform in game functionality.
Supports creative mode with no code changes.
----------------------------------
License
----------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
----------------------------------
Credits
----------------------------------
Thank you to the minetest community who has shared their code and knowledge with me.

92
init.lua Normal file
View File

@ -0,0 +1,92 @@
--[[
Inventory Plus for Minetest
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
Source Code: https://github.com/cornernote/minetest-particles
License: GPLv3
]]--
-- expose api
inventory_plus = {}
-- define pages
inventory_plus.pages = {}
if minetest.setting_getbool("creative_mode") then
inventory_plus.pages["creative_prev"] = "Creative"
end
inventory_plus.pages["craft"] = "Craft"
-- set_inventory_formspec
inventory_plus.set_inventory_formspec = function(player,formspec)
if minetest.setting_getbool("creative_mode") then
-- if creative mode is on then wait a bit
minetest.after(0.01,function()
player:set_inventory_formspec(formspec)
end)
else
player:set_inventory_formspec(formspec)
end
end
-- get_formspec
inventory_plus.get_formspec = function(player,page)
local formspec = "size[8,7.5]"
-- player inventory
formspec = formspec .. "list[current_player;main;0,3.5;8,4;]"
-- craft page
if page=="craft" then
formspec = formspec
.."button[0,0;2,0.5;main;Back]"
.."list[current_player;craft;3,0;3,3;]"
.."list[current_player;craftpreview;7,1;1,1;]"
end
if page=="main" then
-- buttons
local x,y=0,0
for k,v in pairs(inventory_plus.pages) 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.set_inventory_formspec(player,inventory_plus.get_formspec(player,"main"))
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.01,function()
inventory_plus.set_inventory_formspec(player, player:get_inventory_formspec().."button[5,0;2,0.5;main;Back]")
return
end)
end
end)
-- log that we started
minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- loaded from "..minetest.get_modpath(minetest.get_current_modname()))