1 local minetest,pairs = minetest,pairs
3 local tmi_master_inventory = {}
9 "background[-0.19,-0.25;9.41,9.49;main_inventory.png]"..
10 "listcolors[#8b8a89;#c9c3c6;#3e3d3e;#000000;#FFFFFF]"..
11 "list[current_player;main;0,4.5;9,1;]".. --hot bar
12 "list[current_player;main;0,6;9,3;9]".. --big part
13 "list[current_player;craft;2.5,1;2,2;]"..
15 "list[current_player;armor_head;0.25,0;1,1;]"..
16 "list[current_player;armor_torso;0.25,1;1,1;]"..
17 "list[current_player;armor_legs;0.25,2;1,1;]"..
18 "list[current_player;armor_feet;0.25,3;1,1;]"..
19 --craft preview with ring
20 "list[current_player;craftpreview;6.1,1.5;1,1;]"..
21 "listring[current_player;main]"..
22 "listring[current_player;craft]"
23 --this is the 3x3 crafting table formspec
24 local crafting_table_inv =
26 "background[-0.19,-0.25;9.41,9.49;crafting_inventory_workbench.png]"..
27 "listcolors[#8b8a89;#c9c3c6;#3e3d3e;#000000;#FFFFFF]"..
28 "list[current_player;main;0,4.5;9,1;]".. --hot bar
29 "list[current_player;main;0,6;9,3;9]".. --big part
30 "list[current_player;craft;1.75,0.5;3,3;]"..
32 "list[current_player;armor_head;0.25,0;1,1;]"..
33 "list[current_player;armor_torso;0.25,1;1,1;]"..
34 "list[current_player;armor_legs;0.25,2;1,1;]"..
35 "list[current_player;armor_feet;0.25,3;1,1;]"..
36 --craft preview with ring
37 "list[current_player;craftpreview;6.1,1.5;1,1;]"..
38 "listring[current_player;main]"..
39 "listring[current_player;craft]"
40 --this is from Linuxdirk, thank you AspireMint for showing me this
41 local recipe_converter = function (items, width)
42 local usable_recipe = { {}, {}, {} }
44 -- The recipe is a shapeless recipe so all items are in one table
53 usable_recipe[1][1] = items[1] or ''
54 usable_recipe[2][1] = items[2] or ''
55 usable_recipe[3][1] = items[3] or ''
62 usable_recipe[1][1] = items[1] or ''
63 usable_recipe[1][2] = items[2] or ''
64 usable_recipe[2][1] = items[3] or ''
65 usable_recipe[2][2] = items[4] or ''
66 usable_recipe[3][1] = items[5] or ''
67 usable_recipe[3][2] = items[6] or ''
74 usable_recipe[1][1] = items[1] or ''
75 usable_recipe[1][2] = items[2] or ''
76 usable_recipe[1][3] = items[3] or ''
77 usable_recipe[2][1] = items[4] or ''
78 usable_recipe[2][2] = items[5] or ''
79 usable_recipe[2][3] = items[6] or ''
80 usable_recipe[3][1] = items[7] or ''
81 usable_recipe[3][2] = items[8] or ''
82 usable_recipe[3][3] = items[9] or ''
87 local map_group_to_item = {
88 ["coal"] = "main:coal",
89 ["glass"] = "main:glass",
90 ["sand"] = "main:sand",
91 ["stick"] = "main:stick",
92 ["stone"] = "main:cobble",
93 ["tree"] = "main:tree",
94 ["wood"] = "main:wood"
97 local get_if_group = function(item)
98 if item ~= nil and item:sub(1,6) == "group:" then
99 local group_name = item:sub(7, item:len())
100 local mapped_item = map_group_to_item[group_name]
101 if mapped_item ~= nil then
111 local output_constant =
112 "listcolors[#8b8a89;#c9c3c6;#3e3d3e;#000000;#FFFFFF]"..
113 "list[current_player;main;0,4.5;9,1;]".. --hot bar
114 "list[current_player;main;0,6;9,3;9]".. --main inventory
115 "button[5,3.5;1,1;toomanyitems.back;back]" --back button
119 local function create_craft_formspec(item)
125 recipe = minetest.get_craft_recipe(item)
127 usable_table = recipe_converter(recipe.items, recipe.width)
129 output = output_constant
131 if recipe.method == "normal" then
134 if recipe.width > 0 then
137 item = get_if_group(usable_table[x][y])
139 output = output.."item_image_button["..base_x+y..","..base_y+x..";1,1;"..item..";"..item..";]"
141 output = output.."item_image_button["..base_x+y..","..base_y+x..";1,1;;;]"
150 item = get_if_group(usable_table[i])
152 output = output.."item_image_button["..base_x+y..","..base_y+x..";1,1;"..item..";"..item..";]"
154 output = output.."item_image_button["..base_x+y..","..base_y+x..";1,1;;;]"
161 elseif recipe.method == "cooking" then
162 item = recipe.items[1]
163 output = output.."item_image_button["..(base_x+2)..","..(base_y+1)..";1,1;"..item..";"..item..";]"
164 output = output.."image[2.75,1.5;1,1;default_furnace_fire_fg.png]"
169 local function cheat_button(name)
170 if pool[name] and pool[name].cheating then
171 return("button[11.5,7.6;2,2;toomanyitems.cheat;cheat:on]")
173 return("button[11.5,7.6;2,2;toomanyitems.cheat;cheat:off]")
186 minetest.register_on_player_receive_fields(function(player, formname, fields)
187 name = player:get_player_name()
188 temp_pool = pool[name]
190 if formname == "" then
193 elseif formname == "crafting" then
194 form = crafting_table_inv
199 if fields["toomanyitems.next"] then
200 temp_pool.page = temp_pool.page + 1
201 --page loops back to first
202 if temp_pool.page > tmi_master_inventory.page_limit then
205 minetest.show_formspec(name,id, form..tmi_master_inventory["page_"..temp_pool.page]..cheat_button(name))
206 minetest.sound_play("lever", {to_player = name,gain=0.7})
207 player:set_inventory_formspec(base_inv..tmi_master_inventory["page_"..temp_pool.page]..cheat_button(name))
209 elseif fields["toomanyitems.prev"] then
210 temp_pool.page = temp_pool.page - 1
211 --page loops back to end
212 if temp_pool.page < 1 then
213 temp_pool.page = tmi_master_inventory.page_limit
216 minetest.show_formspec(name,id, form..tmi_master_inventory["page_"..temp_pool.page]..cheat_button(name))
217 minetest.sound_play("lever", {to_player = name,gain=0.7})
218 player:set_inventory_formspec(base_inv..tmi_master_inventory["page_"..temp_pool.page]..cheat_button(name))
219 elseif fields["toomanyitems.back"] then
221 minetest.show_formspec(name,id, form..tmi_master_inventory["page_"..temp_pool.page]..cheat_button(name))
222 minetest.sound_play("lever", {to_player = name,gain=0.7})
223 --this resets the craft table
224 elseif fields.quit then
225 inv = player:get_inventory()
227 inv:set_width("craft", 2)
228 inv:set_size("craft", 4)
229 --reset the player inv
230 --minetest.show_formspec(name,id, form..tmi_master_inventory["page_"..temp_pool.page]..cheat_button(name))
231 elseif fields["toomanyitems.cheat"] then
232 --check if the player has the give priv
233 if (not temp_pool.cheating and minetest.get_player_privs(name).give == true) or temp_pool.cheating == true then
234 temp_pool.cheating = not temp_pool.cheating
236 minetest.show_formspec(name,id, form..tmi_master_inventory["page_"..temp_pool.page]..cheat_button(name))
237 minetest.sound_play("lever", {to_player = name,gain=0.7})
238 player:set_inventory_formspec(base_inv..tmi_master_inventory["page_"..temp_pool.page]..cheat_button(name))
240 minetest.chat_send_player(name, "Sorry m8, server says I can't let you do that :(")
241 minetest.sound_play("lever", {to_player = name,gain=0.7,pitch=0.7})
243 --this is the "cheating" aka giveme function and craft recipe
244 elseif fields and type(fields) == "table" and string.match(next(fields),"toomanyitems.") then
246 item = string.gsub(next(fields), "toomanyitems.", "")
247 stack = ItemStack(item.." 64")
248 inv = player:get_inventory()
249 if temp_pool.cheating and minetest.get_player_privs(name).give then
252 if inv and inv:room_for_item("main",stack) then
253 inv:add_item("main", stack)
254 minetest.sound_play("pickup", {to_player = name,gain=0.7,pitch = math.random(60,100)/100})
257 minetest.chat_send_player(name, "Might want to clear your inventory")
258 minetest.sound_play("lever", {to_player = name,gain=0.7,pitch=0.7})
261 --this is to get the craft recipe
263 craft_inv = create_craft_formspec(item)
264 if craft_inv and craft_inv ~= "" then
265 minetest.show_formspec(name, id, tmi_master_inventory["page_"..temp_pool.page]..craft_inv..cheat_button(name))
266 minetest.sound_play("lever", {to_player = name,gain=0.7})
274 --run through the items and then set the pages
275 local item_counter = 0
280 minetest.register_on_mods_loaded(function()
282 --sort all items (There is definitely a better way to do this)
284 --get all craftable items
285 local all_items_table = {}
286 for index,data in pairs(minetest.registered_items) do
287 if data.name ~= "" then
288 local recipe = minetest.get_craft_recipe(data.name)
289 --only put in craftable items
290 if recipe.method then
291 table.insert(all_items_table,data.name)
296 table.sort(all_items_table)
298 --dump all the items in
300 tmi_master_inventory["page_"..page] = "size[17.2,8.75]background[-0.19,-0.25;9.41,9.49;crafting_inventory_workbench.png]"
302 for _,item in pairs(all_items_table) do
303 tmi_master_inventory["page_"..page] = tmi_master_inventory["page_"..page].."item_image_button["..(9.25+x)..","..y..";1,1;"..item..";toomanyitems."..item..";]"
312 tmi_master_inventory["page_"..page] = "size[17.2,8.75]background[-0.19,-0.25;9.41,9.49;crafting_inventory_workbench.png]"
316 --add buttons and labels
319 tmi_master_inventory["page_"..i] = tmi_master_inventory["page_"..i].."button[9.25,7.6;2,2;toomanyitems.prev;prev]"..
320 "button[15.25,7.6;2,2;toomanyitems.next;next]"..
321 --this is +1 so it makes more sense
322 "label[13.75,8.25;page "..i.."/"..page.."]"
325 tmi_master_inventory.page_limit = page
327 --override crafting table
331 minetest.override_item("craftingtable:craftingtable", {
332 on_rightclick = function(pos, node, player, itemstack)
333 name = player:get_player_name()
334 temp_pool = pool[name]
335 player:get_inventory():set_width("craft", 3)
336 player:get_inventory():set_size("craft", 9)
337 minetest.show_formspec(name, "crafting", crafting_table_inv..tmi_master_inventory["page_"..temp_pool.page]..cheat_button(name))
343 --set new players inventory up
347 minetest.register_on_joinplayer(function(player)
348 name = player:get_player_name()
350 temp_pool = pool[name]
353 temp_pool.cheating = false
355 inv = player:get_inventory()
356 inv:set_width("craft", 2)
357 inv:set_width("main", 9)
358 inv:set_size("main", 9*4)
359 inv:set_size("craft", 4)
361 player:set_inventory_formspec(base_inv..tmi_master_inventory["page_1"]..cheat_button(name))
363 player:hud_set_hotbar_itemcount(9)
364 player:hud_set_hotbar_image("inventory_hotbar.png")
365 player:hud_set_hotbar_selected_image("hotbar_selected.png")
369 minetest.register_on_leaveplayer(function(player)
370 name = player:get_player_name()