Codebase list minetest-mod-infinite-chest / 056d30c
New upstream version 1.0.1 Julien Puydt 5 years ago
8 changed file(s) with 361 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 Copyright (c) 2013, Brett O'Donnell http://cornernote.github.io
1 All rights reserved.
2 _____ _____ _____ _____ _____ _____
3 | |___| __ | | |___| __ | | |___|_ _|___
4 | --| . | -| | | | -_| -| | | | . | | | | -_|
5 |_____|___|__|__|_|___|___|__|__|_|___|___| |_| |___|
6
7
8 Redistribution and use in source and binary forms, with or without modification,
9 are permitted provided that the following conditions are met:
10
11 * Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
13
14 * Redistributions in binary form must reproduce the above copyright notice, this
15 list of conditions and the following disclaimer in the documentation and/or
16 other materials provided with the distribution.
17
18 * Neither the name of the organization nor the names of its
19 contributors may be used to endorse or promote products derived from
20 this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0 # Infinite Chest for Minetest
1
2 [![home](https://img.shields.io/badge/infinite_chest-home-blue.svg?style=flat-square)](http://cornernote.github.io/minetest-infinite_chest/)
3 [![download](https://img.shields.io/github/tag/cornernote/minetest-infinite_chest.svg?style=flat-square&label=release)](https://github.com/cornernote/minetest-infinite_chest/archive/master.zip)
4 [![git](https://img.shields.io/badge/git-project-green.svg?style=flat-square)](https://github.com/cornernote/minetest-infinite_chest)
5 [![forum](https://img.shields.io/badge/minetest-mod-green.svg?style=flat-square)](http://forum.minetest.net/viewtopic.php?t=3053)
6 [![bower](https://img.shields.io/badge/bower-mod-green.svg?style=flat-square)](https://minetest-bower.herokuapp.com/mods/infinite_chest)
7
8
9 ## Description
10
11 Chests with slots that never run out!
12
13
14 ## Features
15
16 - Name your chest slots so you can easily find your items.
17 - Last accessed slot appears at the top of the list.
18
19
20 ## Project Resources
21
22 * [Home](http://cornernote.github.io/minetest-infinite_chest/)
23 * [Download](https://github.com/cornernote/minetest-infinite_chest/archive/master.zip)
24 * [Project](https://github.com/cornernote/minetest-infinite_chest)
25 * [Forum](http://forum.minetest.net/viewtopic.php?t=3053)
26 * [Bower](https://minetest-bower.herokuapp.com/mods/infinite_chest)
27
28
29 ## Support
30
31 - Does this README need improvement? Go ahead and [suggest a change](https://github.com/cornernote/minetest-infinite_chest/edit/master/README.md).
32 - Found a bug, or need help using this project? Check the [open issues](https://github.com/cornernote/minetest-infinite_chest/issues) or [create an issue](https://github.com/cornernote/minetest-infinite_chest/issues/new).
33
34
35 ## About
36
37 This module is open source, so it's distributed freely. If you find it useful then I ask not for your wealth, but simply to spare your time to consider the world we share by watching [Earthlings](http://earthlings.com/), a multi-award winning film available to watch online for free. A must-see for anyone who wishes to make the world a better place.
38
39
40 ## License
41
42 [BSD-3-Clause](https://raw.github.com/cornernote/minetest-infinite_chest/master/LICENSE), Copyright © 2013-2014 [Brett O'Donnell](http://cornernote.github.io/)
0 {
1 "name": "infinite_chest",
2 "description": "Chests with slots that never run out!",
3 "keywords": [
4 "infinite_chest"
5 ],
6 "homepage": "http://cornernote.github.io/minetest-infinite_chest/",
7 "forum": "http://forum.minetest.net/viewtopic.php?t=3053",
8 "screenshots": [
9 "https://cornernote.github.io/minetest-infinite_chest/img/screenshot1.png"
10 ],
11 "authors": [
12 "cornernote"
13 ]
14 }
0 --[[
1
2 Infinite Chest for Minetest
3
4 Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
5 Source Code: https://github.com/cornernote/minetest-infinite_chest
6 License: BSD-3-Clause https://raw.github.com/cornernote/minetest-infinite_chest/master/LICENSE
7
8 API
9
10 ]]--
11
12
13 infinite_chest = {}
14
15 infinite_chest.log = function(message)
16 minetest.log("action", message)
17 end
18
19 infinite_chest.formspec = function(pos,page)
20 local formspec = "size[15,11]"
21 .."button[12,10;1,0.5;go;Go]"
22 if page=="main" then
23 local meta = minetest.env:get_meta(pos)
24 local pages = infinite_chest.get_pages(meta)
25 local x,y = 0,0
26 local p
27 for i = #pages,1,-1 do
28 p = pages[i]
29 x = x+2
30 if x == 16 then
31 y = y+1
32 x = 2
33 end
34 formspec = formspec .."button["..(x-1.5)..","..(y+1)..";1.5,0.5;jump;"..p.."]"
35 end
36 if #pages == 0 then
37 formspec = formspec
38 .."label[4,3; --== Infinite Chest ==--]"
39 .."label[4,4.5; Create as many inventory slots as you like!]"
40 .."label[4,5.0; Simply enter a name for your inventory slot]"
41 .."label[4,5.5; then click Go.]"
42 end
43 return formspec
44 .."field[10.5,10.1;2,1;page;;]"
45 .."label[0,0;Infinite Chest]"
46 end
47 return formspec
48 .."field[10.5,10.1;2,1;page;;"..page.."]"
49 .."label[0,0;Infinite Chest - page: " .. page .. "]"
50 .."button[13,10;2,0.5;back;Back]"
51 .."button[13,6.5;2,0.5;delete;Delete]"
52 .."list[current_name;"..page..";0,1;15,5;]"
53 .."list[current_player;main;0,7;8,4;]"
54 end
55
56 infinite_chest.get_pages = function(meta)
57 local invs = meta:get_string("infinite_chest_list")
58 local pages = {}
59 for p in string.gmatch(invs, "[^%s]+") do
60 table.insert(pages,p)
61 end
62 return pages
63 end
64
65 infinite_chest.add_page = function(pos,page)
66 local meta = minetest.env:get_meta(pos)
67 local invs = meta:get_string("infinite_chest_list")
68 local pages = {}
69 for p in string.gmatch(invs, "[^%s]+") do
70 if page ~= p then
71 table.insert(pages,p)
72 end
73 end
74 table.insert(pages,page)
75 invs = ""
76 for i,p in pairs(pages) do
77 invs = invs .." ".. p
78 end
79 meta:set_string("infinite_chest_list",invs)
80 meta:get_inventory():set_size(page, 15*5)
81 end
82
83 infinite_chest.remove_page = function(pos,page)
84 local meta = minetest.env:get_meta(pos)
85 local invs = meta:get_string("infinite_chest_list")
86 local inv = meta:get_inventory()
87 if not inv:is_empty(page) then
88 return
89 end
90 local pages = {}
91 for p in string.gmatch(invs, "[^%s]+") do
92 if page ~= p then
93 table.insert(pages,p)
94 end
95 end
96 invs = ""
97 for i,p in pairs(pages) do
98 invs = invs .." ".. p
99 end
100 meta:set_string("infinite_chest_list",invs)
101 return true
102 end
103
104 infinite_chest.on_receive_fields = function(pos, formname, fields, sender)
105 local meta = minetest.env:get_meta(pos)
106 local page
107 if fields.go ~= nil and fields.page ~= "" then
108 page = string.lower(string.gsub(fields.page, "%W", "_"))
109 end
110 if fields.jump ~= nil then
111 page = fields.jump
112 end
113 if page ~= nil then
114 infinite_chest.add_page(pos,page)
115 meta:set_string("formspec", infinite_chest.formspec(pos,page))
116 return
117 end
118 if fields.delete ~= nil then
119 if not infinite_chest.remove_page(pos,fields.page) then
120 minetest.chat_send_player(sender:get_player_name(), "cannot delete \""..fields.page.."\" - page is not empty")
121 return
122 end
123 end
124 meta:set_string("formspec", infinite_chest.formspec(pos,"main"))
125 end
126
127 infinite_chest.on_construct = function(pos)
128 local meta = minetest.env:get_meta(pos)
129 meta:set_string("formspec", infinite_chest.formspec(pos,"main"))
130 meta:set_string("infotext", "Infinite Chest")
131 end
132
133 infinite_chest.can_dig = function(pos,player)
134 local meta = minetest.env:get_meta(pos);
135 local pages = infinite_chest.get_pages(meta)
136 local inv = meta:get_inventory()
137 for i,page in pairs(pages) do
138 if not inv:is_empty(page) then
139 minetest.chat_send_player(player:get_player_name(), "cannot dig - page \""..page.."\" is not empty")
140 return false
141 end
142 end
143 return true
144 end
145
146 infinite_chest.after_place_node = function(pos, placer)
147 local meta = minetest.env:get_meta(pos)
148 meta:set_string("owner", placer:get_player_name() or "")
149 meta:set_string("infotext", "Locked Infinite Chest (owned by "..meta:get_string("owner")..")")
150 end
151
152 infinite_chest.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
153 local meta = minetest.env:get_meta(pos)
154 if not infinite_chest.has_locked_chest_privilege(meta, player) then
155 infinite_chest.log(player:get_player_name().." tried to access a locked chest belonging to "..meta:get_string("owner").." at "..minetest.pos_to_string(pos))
156 return 0
157 end
158 return count
159 end
160
161 infinite_chest.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
162 local meta = minetest.env:get_meta(pos)
163 if not infinite_chest.has_locked_chest_privilege(meta, player) then
164 infinite_chest.log(player:get_player_name().." tried to access a locked chest belonging to "..meta:get_string("owner").." at "..minetest.pos_to_string(pos))
165 return 0
166 end
167 return stack:get_count()
168 end
169
170 infinite_chest.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
171 local meta = minetest.env:get_meta(pos)
172 if not infinite_chest.has_locked_chest_privilege(meta, player) then
173 infinite_chest.log(player:get_player_name()..
174 " tried to access a locked chest belonging to "..
175 meta:get_string("owner").." at "..
176 minetest.pos_to_string(pos))
177 return 0
178 end
179 return stack:get_count()
180 end
181
182 infinite_chest.has_locked_chest_privilege = function(meta, player)
183 if meta:get_string("owner") ~= "" and player:get_player_name() ~= meta:get_string("owner") then
184 return false
185 end
186 return true
187 end
188
189 infinite_chest.on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
190 infinite_chest.log(player:get_player_name().." moves stuff in infinite chest at "..minetest.pos_to_string(pos))
191 end
192
193 infinite_chest.on_metadata_inventory_put = function(pos, listname, index, stack, player)
194 infinite_chest.log(player:get_player_name().." moves stuff to infinite chest at "..minetest.pos_to_string(pos))
195 end
196
197 infinite_chest.on_metadata_inventory_take = function(pos, listname, index, stack, player)
198 infinite_chest.log(player:get_player_name().." takes stuff from infinite chest at "..minetest.pos_to_string(pos))
199 end
0 --[[
1
2 Infinite Chest for Minetest
3
4 Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
5 Source Code: https://github.com/cornernote/minetest-infinite_chest
6 License: BSD-3-Clause https://raw.github.com/cornernote/minetest-infinite_chest/master/LICENSE
7
8 MAIN LOADER
9
10 ]]--
11
12
13 -- load api
14 dofile(minetest.get_modpath("infinite_chest").."/api.lua")
15
16 -- register nodes
17 minetest.register_node("infinite_chest:chest", {
18 description = "Infinite Chest",
19 tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png", "default_chest_side.png", "default_chest_side.png", "default_chest_front.png"},
20 paramtype2 = "facedir",
21 groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
22 legacy_facedir_simple = true,
23 sounds = default.node_sound_wood_defaults(),
24 can_dig = infinite_chest.can_dig,
25 on_construct = infinite_chest.on_construct,
26 on_receive_fields = infinite_chest.on_receive_fields,
27 on_metadata_inventory_move = infinite_chest.on_metadata_inventory_move,
28 on_metadata_inventory_put = infinite_chest.on_metadata_inventory_put,
29 on_metadata_inventory_take = infinite_chest.on_metadata_inventory_take,
30 })
31 minetest.register_node("infinite_chest:chest_locked", {
32 description = "Locked Infinite Chest",
33 tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png", "default_chest_side.png", "default_chest_side.png", "default_chest_lock.png"},
34 paramtype2 = "facedir",
35 groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
36 legacy_facedir_simple = true,
37 sounds = default.node_sound_wood_defaults(),
38 on_construct = infinite_chest.on_construct,
39 on_receive_fields = infinite_chest.on_receive_fields,
40 can_dig = infinite_chest.can_dig,
41 after_place_node = infinite_chest.after_place_node,
42 allow_metadata_inventory_move = infinite_chest.allow_metadata_inventory_move,
43 allow_metadata_inventory_put = infinite_chest.allow_metadata_inventory_put,
44 allow_metadata_inventory_take = infinite_chest.allow_metadata_inventory_take,
45 on_metadata_inventory_move = infinite_chest.on_metadata_inventory_move,
46 on_metadata_inventory_put = infinite_chest.on_metadata_inventory_put,
47 on_metadata_inventory_take = infinite_chest.on_metadata_inventory_take,
48 })
49
50 -- register crafts
51 minetest.register_craft({
52 output = 'infinite_chest:chest',
53 recipe = {
54 {'default:chest', 'default:chest', 'default:chest'},
55 {'default:chest', '', 'default:chest'},
56 {'default:chest', 'default:chest', 'default:chest'},
57 }
58 })
59 minetest.register_craft({
60 output = 'infinite_chest:chest_locked',
61 recipe = {
62 {'default:chest_locked', 'default:chest_locked', 'default:chest_locked'},
63 {'default:chest_locked', 'default:mese', 'default:chest_locked'},
64 {'default:chest_locked', 'default:chest_locked', 'default:chest_locked'},
65 }
66 })
67
68 -- log that we started
69 minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- loaded from "..minetest.get_modpath(minetest.get_current_modname()))
(New empty file)