new features
This commit is contained in:
parent
65f7492d52
commit
3484b47ac1
3
init.lua
3
init.lua
@ -28,6 +28,9 @@ dofile(modpath.."/focuses.lua")
|
|||||||
-- Tables
|
-- Tables
|
||||||
dofile(modpath.."/table.lua")
|
dofile(modpath.."/table.lua")
|
||||||
|
|
||||||
|
-- Nodes
|
||||||
|
dofile(modpath.."/nodes.lua")
|
||||||
|
|
||||||
-- Items
|
-- Items
|
||||||
dofile(modpath.."/craftitems.lua")
|
dofile(modpath.."/craftitems.lua")
|
||||||
|
|
||||||
|
1
mod.conf
1
mod.conf
@ -1,3 +1,4 @@
|
|||||||
name = magicalities
|
name = magicalities
|
||||||
description = Magic mod.
|
description = Magic mod.
|
||||||
depends = default
|
depends = default
|
||||||
|
optional_depends = craftguide
|
||||||
|
12
nodes.lua
Normal file
12
nodes.lua
Normal file
@ -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
|
||||||
|
})
|
51
register.lua
51
register.lua
@ -109,3 +109,54 @@ minetest.register_craft({
|
|||||||
},
|
},
|
||||||
output = "magicalities:wand_steel",
|
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
|
||||||
|
62
storage.lua
Normal file
62
storage.lua
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
|
||||||
|
--[[
|
||||||
|
JSON storage information:
|
||||||
|
"<player name>": {
|
||||||
|
"recipes": [<list of item names that this player knows how to craft>],
|
||||||
|
"abilities": [<list of learned abilities that are not crafting recipes>],
|
||||||
|
"protect": [<list of player protected nodes (positions)>],
|
||||||
|
"research": <integer of research points>,
|
||||||
|
}
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- 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)
|
33
table.lua
33
table.lua
@ -11,19 +11,23 @@ local fmspecelems = {
|
|||||||
["dark"] = {5, 4}
|
["dark"] = {5, 4}
|
||||||
}
|
}
|
||||||
|
|
||||||
local function arcane_table_formspec(data)
|
local function arcane_table_formspec(requirements, present)
|
||||||
local spec = ""
|
local spec = ""
|
||||||
local labels = ""
|
local labels = ""
|
||||||
|
|
||||||
if not data then
|
if not requirements then
|
||||||
data = {}
|
requirements = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
if not present then
|
||||||
|
present = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
for name, pos in pairs(fmspecelems) do
|
for name, pos in pairs(fmspecelems) do
|
||||||
local cp = ""
|
local cp = ""
|
||||||
local y = -0.4
|
local y = -0.4
|
||||||
|
|
||||||
if not data[name] then
|
if not requirements[name] or not present[name] then
|
||||||
cp = "^[colorize:#2f2f2f:200"
|
cp = "^[colorize:#2f2f2f:200"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -32,9 +36,10 @@ local function arcane_table_formspec(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
spec = spec .. "image["..pos[1]..","..pos[2]..";1,1;magicalities_symbol_"..name..".png"..cp.."]"
|
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
|
if requirements[name] then
|
||||||
labels = labels .. "label["..(pos[1] + 0.3)..","..(pos[2] + y)..";"..data[name].."]"
|
labels = labels .. "label["..(pos[1] + 0.3)..","..(pos[2] + y)..";"..requirements[name].."]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -47,6 +52,7 @@ local function arcane_table_formspec(data)
|
|||||||
spec..
|
spec..
|
||||||
"list[context;craft;2,1.5;3,3;]"..
|
"list[context;craft;2,1.5;3,3;]"..
|
||||||
"list[context;craftres;7,2.5;1,1;]"..
|
"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;]"..
|
"list[context;wand;7,1;1,1;]"..
|
||||||
labels..
|
labels..
|
||||||
"image[6,2.5;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
|
"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
|
return output, result.requirements
|
||||||
end
|
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 function update_craft(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local out, reqs = set_output(pos)
|
local out, reqs = set_output(pos)
|
||||||
|
|
||||||
|
local present = requirements_present(reqs, inv:get_stack("wand", 1))
|
||||||
|
|
||||||
if reqs then
|
if reqs then
|
||||||
meta:set_string("formspec", arcane_table_formspec(reqs))
|
meta:set_string("formspec", arcane_table_formspec(reqs, present))
|
||||||
else
|
else
|
||||||
meta:set_string("formspec", arcane_table_formspec({}))
|
meta:set_string("formspec", arcane_table_formspec({}))
|
||||||
end
|
end
|
||||||
@ -279,5 +296,5 @@ minetest.register_node("magicalities:table", {
|
|||||||
{-0.5000, 0.3750, -0.5000, 0.5000, 0.5000, 0.5000}
|
{-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}
|
||||||
})
|
})
|
||||||
|
BIN
textures/magicalities_gui_wand_slot.png
Normal file
BIN
textures/magicalities_gui_wand_slot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 258 B |
BIN
textures/magicalities_tree_top.png
Normal file
BIN
textures/magicalities_tree_top.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 789 B |
27
wands.lua
27
wands.lua
@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
magicalities.wands = {}
|
magicalities.wands = {}
|
||||||
|
|
||||||
local transform_recipes = {
|
magicalities.wands.transform_recipes = {
|
||||||
["mg_table"] = {result = "magicalities:arcane_table", requirements = nil}
|
["enchanted_table"] = {result = "magicalities:arcane_table", requirements = nil},
|
||||||
|
["tree"] = {result = "magicalities:tree_enchanted", requirements = nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
local wandcaps = {
|
local wandcaps = {
|
||||||
@ -77,25 +78,15 @@ function magicalities.wands.update_wand_desc(stack)
|
|||||||
local wanddata = minetest.registered_items[stack:get_name()]
|
local wanddata = minetest.registered_items[stack:get_name()]
|
||||||
local description = wanddata.description
|
local description = wanddata.description
|
||||||
local capcontents = wanddata["_cap_max"] or 15
|
local capcontents = wanddata["_cap_max"] or 15
|
||||||
local strbld = description.."\n"
|
local strbld = description.."\n\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 elems = {}
|
local elems = {}
|
||||||
for elem, amount in pairs(data_table) do
|
for elem, amount in pairs(data_table) do
|
||||||
local dataelem = magicalities.elements[elem]
|
local dataelem = magicalities.elements[elem]
|
||||||
if amount > 0 then
|
if amount > 0 then
|
||||||
elems[#elems + 1] = minetest.colorize(dataelem.color, dataelem.description.." ")..
|
if amount < 10 then amount = "0"..amount end
|
||||||
align(longest_desc * 2 - #dataelem.description)..
|
elems[#elems + 1] = "["..amount.."/"..capcontents.."] "..
|
||||||
amount.."/"..capcontents
|
minetest.colorize(dataelem.color, dataelem.description)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -105,7 +96,7 @@ function magicalities.wands.update_wand_desc(stack)
|
|||||||
focusstr = def.description
|
focusstr = def.description
|
||||||
end
|
end
|
||||||
|
|
||||||
strbld = strbld .. focusstr
|
strbld = strbld .. minetest.colorize("#5716ad", focusstr) .. "\n"
|
||||||
if #elems > 0 then
|
if #elems > 0 then
|
||||||
table.sort(elems)
|
table.sort(elems)
|
||||||
strbld = strbld .. "\n" .. table.concat(elems, "\n")
|
strbld = strbld .. "\n" .. table.concat(elems, "\n")
|
||||||
@ -218,7 +209,7 @@ local function wand_action(itemstack, placer, pointed_thing)
|
|||||||
|
|
||||||
-- Replacement
|
-- Replacement
|
||||||
local to_replace = nil
|
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
|
if minetest.get_item_group(node.name, grp) > 0 then
|
||||||
to_replace = result
|
to_replace = result
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user