Initial commit

This commit is contained in:
Wuzzy 2016-09-23 02:24:39 +02:00
commit 34c4a92b8f
3 changed files with 55 additions and 0 deletions

1
description.txt Normal file
View File

@ -0,0 +1 @@
This provides a simple form to select a single item type.

53
init.lua Normal file
View File

@ -0,0 +1,53 @@
select_item = {}
local get_items = function()
return minetest.registered_items
end
local check_item = function(itemstring, filter)
local itemdef = minetest.registered_items[itemstring]
if itemstring == "air" or itemstring == "ignore" then
return false
end
if itemdef.description == nil or itemdef.description == "" then
return false
end
if itemdef.groups ~= nil and itemdef.groups.not_for_inventories ~= nil then
return false
end
return true
end
local xsize = 18
local ysize = 9
select_item.select_item = function(playername, filter)
local form = "size["..xsize..","..(ysize+1).."]"
local items = get_items()
local x = 0
local y = 0.5
form = form .. "label[0,0;Select an item:]"
for itemstring, itemdef in pairs(items) do
if check_item(itemstring, filter) then
local name = "item_"..itemstring
form = form .. "item_image_button["..x..","..y..";1,1;"..itemstring..";"..name..";]"
x = x + 1
if x >= xsize then
x = 0
y = y + 1
if y >= ysize then
break
end
end
end
end
form = form .. "button[0,"..y..";1,1;previous;<]"
form = form .. "button[1,"..y..";1,1;next;>]"
form = form .. "button["..(xsize-4)..","..y..";2,1;cancel;Cancel]"
form = form .. "button["..(xsize-2)..","..y..";2,1;done;OK]"
minetest.show_formspec(playername, "select_item:select_item", form)
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
-- TODO
end)

1
mod.conf Normal file
View File

@ -0,0 +1 @@
name = select_item