diff --git a/init.lua b/init.lua index 413d5f0..3ec7005 100644 --- a/init.lua +++ b/init.lua @@ -28,6 +28,9 @@ dofile(modpath.."/focuses.lua") -- Tables dofile(modpath.."/table.lua") +-- Nodes +dofile(modpath.."/nodes.lua") + -- Items dofile(modpath.."/craftitems.lua") diff --git a/mod.conf b/mod.conf index 15a7299..9b448fb 100644 --- a/mod.conf +++ b/mod.conf @@ -1,3 +1,4 @@ name = magicalities description = Magic mod. depends = default +optional_depends = craftguide diff --git a/nodes.lua b/nodes.lua new file mode 100644 index 0000000..1299e1e --- /dev/null +++ b/nodes.lua @@ -0,0 +1,12 @@ + +-- Enchanted Wood +minetest.register_node("magicalities:tree_enchanted", { + description = "Enchanted Tree", + tiles = {"magicalities_tree_top.png", "magicalities_tree_top.png", "magicalities_table_wood.png"}, + paramtype2 = "facedir", + is_ground_content = false, + groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2}, + sounds = default.node_sound_wood_defaults(), + + on_place = minetest.rotate_node +}) diff --git a/register.lua b/register.lua index eebc8cc..abb761b 100644 --- a/register.lua +++ b/register.lua @@ -109,3 +109,54 @@ minetest.register_craft({ }, output = "magicalities:wand_steel", }) + +minetest.register_craft({ + recipe = { + {"group:tree", "group:tree", "group:tree"}, + {"", "group:tree", ""}, + {"group:tree", "group:tree", "group:tree"} + }, + output = "magicalities:table", +}) + +local function _flatten(arr) + local result = {} + for i,v in ipairs(arr) do + for j,b in ipairs(v) do + table.insert(result, b) + end + end + return result +end + +if minetest.get_modpath("craftguide") ~= nil then + craftguide.register_craft_type("arcane", { + description = "Arcane Crafting", + icon = "magicalities_table_arcane_top.png", + }) + + for _, recipe in pairs(recipes) do + craftguide.register_craft({ + type = "arcane", + output = recipe.output, + width = 3, + height = 3, + items = _flatten(recipe.input), + }) + end + + -- How to make things with wand + craftguide.register_craft_type("wand", { + description = "Use Wand", + icon = "magicalities_wand_iron.png", + }) + + for g,v in pairs(magicalities.wands.transform_recipes) do + craftguide.register_craft({ + type = "wand", + output = v.result, + width = 1, + items = {"group:"..g}, + }) + end +end diff --git a/storage.lua b/storage.lua new file mode 100644 index 0000000..3d19068 --- /dev/null +++ b/storage.lua @@ -0,0 +1,62 @@ + +--[[ + JSON storage information: + "": { + "recipes": [], + "abilities": [], + "protect": [], + "research": , + } +]] + +-- Memory cache +magicalities.data = {} + +function magicalities.load_player_data(player_name) + local world = minetest.get_worldpath() + local directory = world.."/magicalities" + minetest.mkdir(directory) + + local filetag = player_name..".info.json" + local file = io.open(directory.."/"..filetag) + + if not file then + magicalities.data[player_name] = { + recipes = {}, + abilities = {}, + protect = {}, + research = 0, + } + return + end + + local str = "" + for line in file:lines() do + str = str..line + end + + file:close() + + magicalities.data[player_name] = minetest.deserialize(str) +end + +function magicalities.save_player_data(player_name) + if not magicalities.data[player_name] then return nil end + + local world = minetest.get_worldpath() + local directory = world.."/magicalities" + minetest.mkdir(directory) + + local filetag = player_name..".info.json" + local data = minetest.serialize(magicalities.data[player_name]) + + minetest.safe_file_write(directory.."/"..filetag, data) +end + +function magicalities.save_all_data() + for pname in pairs(magicalities.data) do + minetest.after(0.1, magicalities.save_player_data, pname) + end +end + +minetest.register_on_shutdown(magicalities.save_all_data) diff --git a/table.lua b/table.lua index 9add630..5c20dac 100644 --- a/table.lua +++ b/table.lua @@ -11,19 +11,23 @@ local fmspecelems = { ["dark"] = {5, 4} } -local function arcane_table_formspec(data) +local function arcane_table_formspec(requirements, present) local spec = "" local labels = "" - if not data then - data = {} + if not requirements then + requirements = {} + end + + if not present then + present = {} end for name, pos in pairs(fmspecelems) do local cp = "" local y = -0.4 - if not data[name] then + if not requirements[name] or not present[name] then cp = "^[colorize:#2f2f2f:200" end @@ -32,9 +36,10 @@ local function arcane_table_formspec(data) end spec = spec .. "image["..pos[1]..","..pos[2]..";1,1;magicalities_symbol_"..name..".png"..cp.."]" + spec = spec .. "tooltip["..pos[1]..","..pos[2]..";1,1;"..magicalities.elements[name].description.."]" - if data[name] then - labels = labels .. "label["..(pos[1] + 0.3)..","..(pos[2] + y)..";"..data[name].."]" + if requirements[name] then + labels = labels .. "label["..(pos[1] + 0.3)..","..(pos[2] + y)..";"..requirements[name].."]" end end @@ -47,6 +52,7 @@ local function arcane_table_formspec(data) spec.. "list[context;craft;2,1.5;3,3;]".. "list[context;craftres;7,2.5;1,1;]".. + "image[7,1;1,1;magicalities_gui_wand_slot.png]".. "list[context;wand;7,1;1,1;]".. labels.. "image[6,2.5;1,1;gui_furnace_arrow_bg.png^[transformR270]".. @@ -204,13 +210,24 @@ local function set_output(pos) return output, result.requirements end +local function requirements_present(requirements, wand) + local present = {} + if wand:is_empty() or not requirements then return present end + for req, cnt in pairs(requirements) do + present[req] = magicalities.wands.wand_has_contents(wand, {[req] = cnt}) + end + return present +end + local function update_craft(pos) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() local out, reqs = set_output(pos) + local present = requirements_present(reqs, inv:get_stack("wand", 1)) + if reqs then - meta:set_string("formspec", arcane_table_formspec(reqs)) + meta:set_string("formspec", arcane_table_formspec(reqs, present)) else meta:set_string("formspec", arcane_table_formspec({})) end @@ -279,5 +296,5 @@ minetest.register_node("magicalities:table", { {-0.5000, 0.3750, -0.5000, 0.5000, 0.5000, 0.5000} } }, - groups = {choppy = 2, oddly_breakable_by_hand = 1, mg_table = 1} + groups = {choppy = 2, oddly_breakable_by_hand = 1, enchanted_table = 1} }) diff --git a/textures/magicalities_gui_wand_slot.png b/textures/magicalities_gui_wand_slot.png new file mode 100644 index 0000000..18647f9 Binary files /dev/null and b/textures/magicalities_gui_wand_slot.png differ diff --git a/textures/magicalities_tree_top.png b/textures/magicalities_tree_top.png new file mode 100644 index 0000000..c3e6c60 Binary files /dev/null and b/textures/magicalities_tree_top.png differ diff --git a/wands.lua b/wands.lua index 0e359bc..7fc0a60 100644 --- a/wands.lua +++ b/wands.lua @@ -2,8 +2,9 @@ magicalities.wands = {} -local transform_recipes = { - ["mg_table"] = {result = "magicalities:arcane_table", requirements = nil} +magicalities.wands.transform_recipes = { + ["enchanted_table"] = {result = "magicalities:arcane_table", requirements = nil}, + ["tree"] = {result = "magicalities:tree_enchanted", requirements = nil} } local wandcaps = { @@ -77,25 +78,15 @@ function magicalities.wands.update_wand_desc(stack) local wanddata = minetest.registered_items[stack:get_name()] local description = wanddata.description local capcontents = wanddata["_cap_max"] or 15 - local strbld = description.."\n" - - local longest_desc = 0 - for _,data in pairs(magicalities.elements) do - if not data.inheritance then - local len = #data.description - if len > longest_desc then - longest_desc = len - end - end - end + local strbld = description.."\n\n" local elems = {} for elem, amount in pairs(data_table) do local dataelem = magicalities.elements[elem] if amount > 0 then - elems[#elems + 1] = minetest.colorize(dataelem.color, dataelem.description.." ").. - align(longest_desc * 2 - #dataelem.description).. - amount.."/"..capcontents + if amount < 10 then amount = "0"..amount end + elems[#elems + 1] = "["..amount.."/"..capcontents.."] ".. + minetest.colorize(dataelem.color, dataelem.description) end end @@ -105,7 +96,7 @@ function magicalities.wands.update_wand_desc(stack) focusstr = def.description end - strbld = strbld .. focusstr + strbld = strbld .. minetest.colorize("#5716ad", focusstr) .. "\n" if #elems > 0 then table.sort(elems) strbld = strbld .. "\n" .. table.concat(elems, "\n") @@ -218,7 +209,7 @@ local function wand_action(itemstack, placer, pointed_thing) -- Replacement local to_replace = nil - for grp, result in pairs(transform_recipes) do + for grp, result in pairs(magicalities.wands.transform_recipes) do if minetest.get_item_group(node.name, grp) > 0 then to_replace = result break