diff --git a/mods/crafting_guide/LICENSE.txt b/mods/crafting_guide/LICENSE.txt new file mode 100644 index 0000000..6f6a256 --- /dev/null +++ b/mods/crafting_guide/LICENSE.txt @@ -0,0 +1,16 @@ +License for Code +---------------- + +Copyright (C) 2016 cd2 (cdqwertz) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +http://www.gnu.org/licenses/lgpl-2.1.html + +License for Media +----------------- + +CC-BY-SA 3.0 UNPORTED. Created by cd2 (cdqwertz) diff --git a/mods/crafting_guide/depends.txt b/mods/crafting_guide/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/mods/crafting_guide/depends.txt @@ -0,0 +1 @@ +default diff --git a/mods/crafting_guide/init.lua b/mods/crafting_guide/init.lua new file mode 100644 index 0000000..8fe549c --- /dev/null +++ b/mods/crafting_guide/init.lua @@ -0,0 +1,110 @@ +crafting_guide = {} + +crafting_guide.form = "size[3,3;]"..default.gui_colors..default.gui_bg.."item_image_button[0,0;1,1;item_11;btn1;]item_image_button[1,0;1,1;item_21;btn2;]item_image_button[2,0;1,1;item_31;btn3;]item_image_button[0,1;1,1;item_12;btn4;]item_image_button[1,1;1,1;item_22;btn5;]item_image_button[2,1;1,1;item_32;btn6;]item_image_button[0,2;1,1;item_13;btn7;]item_image_button[1,2;1,1;item_23;btn8;]item_image_button[2,2;1,1;item_33;btn9;]"; +crafting_guide.form_back = "size[3,4;]"..default.gui_colors..default.gui_bg.."item_image_button[0,0;1,1;item_11;btn1;]item_image_button[1,0;1,1;item_21;btn2;]item_image_button[2,0;1,1;item_31;btn3;]item_image_button[0,1;1,1;item_12;btn4;]item_image_button[1,1;1,1;item_22;btn5;]item_image_button[2,1;1,1;item_32;btn6;]item_image_button[0,2;1,1;item_13;btn7;]item_image_button[1,2;1,1;item_23;btn8;]item_image_button[2,2;1,1;item_33;btn9;]button[0,3;3,1;btn_back;Back]"; + +crafting_guide.form_items = "size[8,7]"..default.gui_colors..default.gui_bg.."button[0,6;3,1;btn_left;<]button[5,6;3,1;btn_right;>]" + +crafting_guide.pages = {} + +function crafting_guide.get_formspec(crafts,back_button) + local str = crafting_guide.form + if back_button then + str = crafting_guide.form_back + end + local x = 1 + local y = 1 + local j = 1 + for i=1,9 do + str = string.gsub(str,"item_"..x..y, crafts[1].items[j] or "") + j = j + 1 + + x = x+1 + if x > 3 then + x = 1 + y = y+1 + end + end + return str +end + +function crafting_guide.get_item_formspec(page) + page = page or 0 + + local str = crafting_guide.form_items + local i = 0 + local x = 0 + local y = 0 + + local items = {} + for name,def in pairs(minetest.registered_items) do + table.insert(items,name) + end + + table.sort(items) + + for _,name in ipairs(items) do + if minetest.get_all_craft_recipes(name) and i < (8*6)*(page+1) then + if i > (8*6)*(page) then + str = str .. "item_image_button["..x..","..y..";1,1;"..name..";"..name..";]" + x = x + 1 + if x > 7 then + x = 0 + y = y +1 + end + end + i = i +1 + end + end + return str +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname == "crafting_guide:book" then + if fields.btn_back then + minetest.show_formspec(player:get_player_name(), "crafting_guide:book_items", crafting_guide.get_item_formspec()) + end + end + if formname == "crafting_guide:book_items" then + if fields.btn_left then + crafting_guide.pages[player:get_player_name()] = crafting_guide.pages[player:get_player_name()] -1 + minetest.show_formspec(player:get_player_name(), "crafting_guide:book_items", crafting_guide.get_item_formspec(crafting_guide.pages[player:get_player_name()])) + elseif fields.btn_right then + crafting_guide.pages[player:get_player_name()] = crafting_guide.pages[player:get_player_name()] +1 + minetest.show_formspec(player:get_player_name(), "crafting_guide:book_items", crafting_guide.get_item_formspec(crafting_guide.pages[player:get_player_name()])) + else + for i,j in pairs(fields) do + local crafts = minetest.get_all_craft_recipes(i) + if crafts then + minetest.show_formspec(player:get_player_name(), "crafting_guide:book", crafting_guide.get_formspec(crafts,true)) + end + end + end + end +end) + +minetest.register_craftitem("crafting_guide:lens", { + inventory_image = "crafting_guide_lens.png", + description = "Lens", + + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.under then + local crafts = minetest.get_all_craft_recipes(minetest.get_node(pointed_thing.under).name) + if crafts then + minetest.show_formspec(user:get_player_name(), "crafting_guide:lens", crafting_guide.get_formspec(crafts)) + else + minetest.show_formspec(user:get_player_name(), "crafting_guide:lens", "size[3,3;]"..default.gui_colors..default.gui_bg.."label[0,0;No crafts]") + end + end + end +}) + +minetest.register_craftitem("crafting_guide:book", { + inventory_image = "crafting_guide_book.png", + description = "Crafting Guide", + + on_use = function(itemstack, user, pointed_thing) + crafting_guide.pages[user:get_player_name()] = 0 + minetest.show_formspec(user:get_player_name(), "crafting_guide:book_items", crafting_guide.get_item_formspec(0)) + end +}) diff --git a/mods/crafting_guide/textures/crafting_guide_book.png b/mods/crafting_guide/textures/crafting_guide_book.png new file mode 100644 index 0000000..d900154 Binary files /dev/null and b/mods/crafting_guide/textures/crafting_guide_book.png differ diff --git a/mods/crafting_guide/textures/crafting_guide_lens.png b/mods/crafting_guide/textures/crafting_guide_lens.png new file mode 100644 index 0000000..c084104 Binary files /dev/null and b/mods/crafting_guide/textures/crafting_guide_lens.png differ