initial commit

master
Brett O'Donnell 2012-09-16 20:29:15 +09:30
commit 2129db41e3
6 changed files with 257 additions and 0 deletions

64
README.txt Normal file
View File

@ -0,0 +1,64 @@
----------------------------------
Bags for Minetest
----------------------------------
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
Source Code: https://github.com/cornernote/minetest-infinite_chest
License: GPLv3
----------------------------------
Description
----------------------------------
Allows players to craft and attach bags to their inventory to increase player item storage capacity.
----------------------------------
Modders Guide
----------------------------------
Turn your item into a Bag:
Add bagslots=X to the groups in the node definition.
EG:
minetest.register_node("your_mod:your_item", {
description = "Your Item",
groups = {bagslots=16},
})
----------------------------------
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.

127
api.lua Normal file
View File

@ -0,0 +1,127 @@
--[[
Bags for Minetest
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
Source Code: https://github.com/cornernote/minetest-particles
License: GPLv3
API
]]--
-- expose api
bags = {}
-- get_formspec
bags.get_formspec = function(player,page)
local formspec = "size[8,8.5]"
.."button[4,0;2,0.5;main;Craft]"
.."button[6,0;2,0.5;bags;Bags]"
.."list[current_player;main;0,4.5;8,4;]"
-- bags inventory page
if page=="bags" then
return formspec
--.."label[0,0;Bags]"
.."button[0,3;2,0.5;bag1;Bag 1]"
.."list[detached:"..player:get_player_name().."_bags;bag1;0.5,2;1,1;]"
.."button[2,3;2,0.5;bag2;Bag 2]"
.."list[detached:"..player:get_player_name().."_bags;bag2;2.5,2;1,1;]"
.."button[4,3;2,0.5;bag3;Bag 3]"
.."list[detached:"..player:get_player_name().."_bags;bag3;4.5,2;1,1;]"
.."button[6,3;2,0.5;bag4;Bag 4]"
.."list[detached:"..player:get_player_name().."_bags;bag4;6.5,2;1,1;]"
end
-- bag invenory page
for i=1,4 do
if page=="bag"..i then
local image = player:get_inventory():get_stack("bag"..i, 1):get_definition().inventory_image
return formspec
.."image[0,0;1,1;"..image.."]"
.."list[current_player;bag"..i.."contents;0,1;8,3;]"
end
end
-- default invenory page
return formspec
--.."label[0,0;Player Inventory]"
.."list[current_player;craft;3,1;3,3;]"
.."list[current_player;craftpreview;7,2;1,1;]"
.."image[1,1.5;1,2;player.png]"
end
-- on_player_receive_fields
bags.on_player_receive_fields = function(player, formname, fields)
if minetest.setting_getbool("creative_mode") then return end
if fields.bags then
player:set_inventory_formspec(bags.get_formspec(player,"bags"))
return
end
for i=1,4 do
local bag = "bag"..i
if fields[bag] then
if bags.get_bagslots(player:get_inventory():get_stack(bag, 1))~=nil then
player:set_inventory_formspec(bags.get_formspec(player,bag))
end
return
end
end
player:set_inventory_formspec(bags.get_formspec(player))
end
-- on_joinplayer
bags.on_joinplayer = function(player)
if minetest.setting_getbool("creative_mode") then return end
local pinv = player:get_inventory()
local inv = minetest.create_detached_inventory(player:get_player_name().."_bags",{
on_put = function(inv, listname, index, stack, player)
player:get_inventory():set_stack(listname, index, stack)
player:get_inventory():set_size(listname.."contents", bags.get_bagslots(stack))
end,
on_take = function(inv, listname, index, stack, player)
player:get_inventory():set_stack(listname, index, nil)
end,
allow_put = function(inv, listname, index, stack, player)
if bags.get_bagslots(stack) then
return 1
else
return 0
end
end,
allow_take = function(inv, listname, index, stack, player)
if player:get_inventory():is_empty(listname.."contents")==true then
return 1
else
return 0
end
end,
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
return 0
end,
})
for i=1,4 do
local bag = "bag"..i
inv:set_size(bag, 1)
inv:set_stack(bag,1,pinv:get_stack(bag,1))
pinv:set_size(bag, 1)
end
player:set_inventory_formspec(bags.get_formspec(player))
end
-- get_bagslots
bags.get_bagslots = function(stack)
if stack then
return stack:get_definition().groups.bagslots
end
end

66
init.lua Normal file
View File

@ -0,0 +1,66 @@
--[[
Bags for Minetest
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
Source Code: https://github.com/cornernote/minetest-particles
License: GPLv3
MAIN LOADER
]]--
-- load api
dofile(minetest.get_modpath("bags").."/api.lua")
-- register misc
minetest.register_on_player_receive_fields(function(player, formname, fields)
bags.on_player_receive_fields(player, formname, fields)
end)
minetest.register_on_joinplayer(function(player)
bags.on_joinplayer(player)
end)
-- register craftitems
minetest.register_craftitem("bags:small", {
description = "Small Bag",
inventory_image = "bags_small.png",
groups = {bagslots=8},
})
minetest.register_craftitem("bags:medium", {
description = "Medium Bag",
inventory_image = "bags_medium.png",
groups = {bagslots=16},
})
minetest.register_craftitem("bags:large", {
description = "Large Bag",
inventory_image = "bags_large.png",
groups = {bagslots=24},
})
-- register crafts
minetest.register_craft({
output = "bags:small",
recipe = {
{"", "default:stick", ""},
{"default:wood", "default:stick", "default:wood"},
{"default:wood", "default:wood", "default:wood"},
},
})
minetest.register_craft({
output = "bags:medium",
recipe = {
{"", "default:stick", ""},
{"bags:small", "bags:small", "bags:small"},
{"bags:small", "bags:small", "bags:small"},
},
})
minetest.register_craft({
output = "bags:large",
recipe = {
{"", "default:stick", ""},
{"bags:medium", "bags:medium", "bags:medium"},
{"bags:medium", "bags:medium", "bags:medium"},
},
})

BIN
textures/bags_large.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

BIN
textures/bags_medium.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

BIN
textures/bags_small.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 B