1 local F = minetest.formspec_escape
3 -- Create a detached inventory
4 local inv_everything = minetest.create_detached_inventory("everything", {
5 allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
8 allow_put = function(inv, listname, index, stack, player)
11 allow_take = function(inv, listname, index, stack, player)
15 local inv_trash = minetest.create_detached_inventory("trash", {
16 allow_take = function(inv, listname, index, stack, player)
19 allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
22 on_put = function(inv, listname, index, stack, player)
23 inv:set_list("main", {})
26 inv_trash:set_size("main", 1)
30 local function get_chest_formspec(page)
31 local start = 0 + (page-1)*32
33 "list[detached:everything;main;0,0;8,4;"..start.."]"..
34 "list[current_player;main;0,5;8,4;]" ..
35 "label[6,4;Trash:]" ..
36 "list[detached:trash;main;7,4;1,1]" ..
37 "button[0,4;1,1;chest_of_everything_prev;"..F("<").."]"..
38 "button[1,4;1,1;chest_of_everything_next;"..F(">").."]"..
39 "label[2,4;"..F("Page: "..page).."]"..
40 "listring[detached:everything;main]"..
41 "listring[current_player;main]"..
42 "listring[detached:trash;main]"
45 minetest.register_node("chest_of_everything:chest", {
46 description = "Chest of Everything" .. "\n" ..
47 "Grants access to all items",
48 tiles ={"chest_of_everything_chest.png^[sheet:2x2:0,0", "chest_of_everything_chest.png^[sheet:2x2:0,0",
49 "chest_of_everything_chest.png^[sheet:2x2:1,0", "chest_of_everything_chest.png^[sheet:2x2:1,0",
50 "chest_of_everything_chest.png^[sheet:2x2:1,0", "chest_of_everything_chest.png^[sheet:2x2:0,1"},
52 groups = {dig_immediate=2,choppy=3},
53 is_ground_content = false,
54 on_construct = function(pos)
55 local meta = minetest.get_meta(pos)
56 meta:set_string("infotext", "Chest of Everything")
57 meta:set_int("page", 1)
58 meta:set_string("formspec", get_chest_formspec(1))
60 on_receive_fields = function(pos, formname, fields, sender)
61 if formname == "" then
62 local meta = minetest.get_meta(pos)
63 local page = meta:get_int("page")
64 if fields.chest_of_everything_prev then
66 elseif fields.chest_of_everything_next then
72 if page > max_page then
75 meta:set_int("page", page)
76 meta:set_string("formspec", get_chest_formspec(page))
81 minetest.register_on_mods_loaded(function()
83 for itemstring,_ in pairs(minetest.registered_items) do
84 if itemstring ~= "" and itemstring ~= "unknown" and itemstring ~= "ignore" then
85 table.insert(items, itemstring)
88 --[[ Sort items in this order:
94 * Items from the 'broken' mod
96 local function compare(item1, item2)
97 local def1 = minetest.registered_items[item1]
98 local def2 = minetest.registered_items[item2]
99 local tool1 = def1.type == "tool"
100 local tool2 = def2.type == "tool"
101 local testtool1 = minetest.get_item_group(item1, "testtool") == 1
102 local testtool2 = minetest.get_item_group(item2, "testtool") == 1
103 local dummy1 = minetest.get_item_group(item1, "dummy") == 1
104 local dummy2 = minetest.get_item_group(item2, "dummy") == 1
105 local broken1 = def1.mod_origin == "broken"
106 local broken2 = def2.mod_origin == "broken"
107 local craftitem1 = def1.type == "craft"
108 local craftitem2 = def2.type == "craft"
109 if item1 == "chest_of_everything:chest" then
111 elseif item2 == "chest_of_everything:chest" then
113 elseif dummy1 and not dummy2 then
115 elseif not dummy1 and dummy2 then
117 elseif broken1 and not broken2 then
119 elseif not broken1 and broken2 then
121 elseif testtool1 and not testtool2 then
123 elseif not testtool1 and testtool2 then
125 elseif tool1 and not tool2 then
127 elseif not tool1 and tool2 then
129 elseif craftitem1 and not craftitem2 then
131 elseif not craftitem1 and craftitem2 then
137 table.sort(items, compare)
138 inv_everything:set_size("main", #items)
139 max_page = math.ceil(#items / 32)
141 inv_everything:add_item("main", items[i])