Protect crystals, some other changes
This commit is contained in:
parent
1ce5b1c3ba
commit
3775bb848d
86
book.lua
86
book.lua
@ -1,5 +1,84 @@
|
||||
|
||||
local page_cache = {}
|
||||
local recipe_cache = {}
|
||||
local group_cache = {}
|
||||
|
||||
local function resolve_group(group)
|
||||
if group_cache[group] then return group_cache[group] end
|
||||
local remove_group = group:sub(7)
|
||||
local found
|
||||
for v in pairs(minetest.registered_items) do
|
||||
if minetest.get_item_group(v, remove_group) > 0 then
|
||||
found = v
|
||||
break
|
||||
end
|
||||
end
|
||||
if not found then return "" end
|
||||
group_cache[group] = found
|
||||
return found
|
||||
end
|
||||
|
||||
local function fromtable_output(tbl, out)
|
||||
local res
|
||||
for _,v in pairs(tbl) do
|
||||
if v.output == out then
|
||||
res = v
|
||||
break
|
||||
end
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
local function generate_recipe_hypertext(item, recipe_type)
|
||||
if recipe_cache[recipe_type .. "/" .. item] then return recipe_cache[recipe_type .. "/" .. item] end
|
||||
|
||||
local lines = {}
|
||||
|
||||
if recipe_type == 'cauldron' then
|
||||
local x = fromtable_output(magicalities.cauldron.recipes, item)
|
||||
if not x then return "" end
|
||||
local rec = x.requirements
|
||||
local y = {}
|
||||
|
||||
for _,v in pairs(x.items) do
|
||||
table.insert(y, "<item name=\""..v.."\" width=64 height=64>")
|
||||
end
|
||||
|
||||
table.insert(lines, "<center>" .. table.concat(y, "<img name=magicalities_book_plus.png width=64 height=64>") .. "</center>")
|
||||
table.insert(lines, "<center><img name=gui_furnace_arrow_bg.png^\\[transformFY width=64 height=64></center>")
|
||||
table.insert(lines, "<center><item name=\"magicalities:cauldron_with_water\" width=64 height=64><img name=magicalities_book_plus.png width=64 height=64><item name=\"magicalities:wand_steel\" width=64 height=64></center>")
|
||||
|
||||
if rec then
|
||||
local p = {}
|
||||
for rec,v in pairs(rec) do
|
||||
table.insert(p, v .. " " .. magicalities.elements[rec].description)
|
||||
end
|
||||
table.insert(lines, "<center><big>" .. table.concat(p, " | ") .. "</big></center>")
|
||||
end
|
||||
end
|
||||
|
||||
if #lines > 0 then
|
||||
local ht = table.concat(lines, "\n")
|
||||
recipe_cache[recipe_type .. "/" .. item] = ht
|
||||
return ht
|
||||
end
|
||||
end
|
||||
|
||||
local function line_special (line)
|
||||
local types = {"cauldron"}
|
||||
local matched = false
|
||||
|
||||
for _,v in pairs(types) do
|
||||
matched = line:match("^<"..v) ~= nil
|
||||
if matched then break end
|
||||
end
|
||||
|
||||
if not matched then return line end
|
||||
local tyt = line:match("^<([%w]*)")
|
||||
local itm = line:match("name=([^>]*)")
|
||||
if not tyt or not itm then return "" end
|
||||
return generate_recipe_hypertext(itm, tyt)
|
||||
end
|
||||
|
||||
local function book_formspec(user, page, scrollindex)
|
||||
if page then
|
||||
@ -75,6 +154,7 @@ local function book_read(book, user, pointed_thing)
|
||||
end
|
||||
|
||||
local function cache_book_pages()
|
||||
recipe_cache = {}
|
||||
local file = io.open(minetest.get_modpath("magicalities").."/book.txt")
|
||||
local all = {}
|
||||
local previous = ""
|
||||
@ -86,6 +166,7 @@ local function cache_book_pages()
|
||||
previous = line
|
||||
since = 0
|
||||
elseif previous ~= "" then
|
||||
line = line_special(line)
|
||||
if since > 0 then
|
||||
line = '\n'..line
|
||||
end
|
||||
@ -173,4 +254,9 @@ minetest.register_chatcommand("mgcbookcache", {
|
||||
end
|
||||
})
|
||||
|
||||
local initial = true
|
||||
minetest.register_on_joinplayer(function ()
|
||||
if not initial then return end
|
||||
initial = false
|
||||
cache_book_pages()
|
||||
end)
|
||||
|
10
book.txt
10
book.txt
@ -32,16 +32,10 @@ Right-Click on the Cauldron with a <b>Bucket of Water</b> in order to fill it wi
|
||||
The <b>Gold-Capped Wand</b> is an improved version of the Steel-Capped Wand. It can contain up to 50 of each element instead of the Steel Wand's 25.
|
||||
#2magicalities:transterra
|
||||
The <b>Transterra</b> is a stone that can be used to <b>create or remove nodes from the world</b>. It is made in the Cauldron.
|
||||
<center><item name="default:stone" width=64 height=64><img name=magicalities_book_plus.png width=64 height=64><item name="default:dirt" width=64 height=64><img name=magicalities_book_plus.png width=64 height=64><item name="magicalities:crystal_fire" width=64 height=64></center>
|
||||
<center><img name=gui_furnace_arrow_bg.png^\[transformFY width=64 height=64></center>
|
||||
<center><item name="magicalities:cauldron_with_water" width=64 height=64><img name=magicalities_book_plus.png width=64 height=64><item name="magicalities:wand_steel" width=64 height=64></center>
|
||||
<center><big>1 Earth | 1 Dark</big></center>
|
||||
<cauldron name=magicalities:transterra>
|
||||
#2magicalities:tellium
|
||||
<b>Tellium</b> is a metal that can be used to <b>create magical tools</b>. It is made in the Cauldron.
|
||||
<center><item name="default:steel_ingot" width=64 height=64><img name=magicalities_book_plus.png width=64 height=64><item name="default:obsidian" width=64 height=64></center>
|
||||
<center><img name=gui_furnace_arrow_bg.png^\[transformFY width=64 height=64></center>
|
||||
<center><item name="magicalities:cauldron_with_water" width=64 height=64><img name=magicalities_book_plus.png width=64 height=64><item name="magicalities:wand_steel" width=64 height=64></center>
|
||||
<center><big>5 Fire | 5 Earth</big></center>
|
||||
<cauldron name=magicalities:tellium>
|
||||
#2magicalities:element_ring
|
||||
The <b>Elemental Ring</b> can show you what elements a crystal contains and their quantities.
|
||||
#2magicalities:focus_blank
|
||||
|
@ -89,6 +89,11 @@ local function crystal_rightclick(pos, node, clicker, itemstack, pointed_thing)
|
||||
local player = clicker:get_player_name()
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Protect crystals
|
||||
if minetest.is_protected(pos, player) then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Add contents to the crystal
|
||||
local contents = minetest.deserialize(meta:get_string("contents"))
|
||||
if not contents then
|
||||
|
30
storage.lua
30
storage.lua
@ -15,18 +15,20 @@ local storage = minetest.get_mod_storage()
|
||||
-- Memory cache
|
||||
magicalities.data = {}
|
||||
|
||||
local data_default = {
|
||||
recipes = {},
|
||||
abilities = {},
|
||||
protect = {},
|
||||
research = 0,
|
||||
}
|
||||
|
||||
-- Storage actions
|
||||
|
||||
function magicalities.load_player_data(player_name)
|
||||
local stdata = minetest.deserialize(storage:get_string(player_name))
|
||||
|
||||
if not stdata then
|
||||
magicalities.data[player_name] = {
|
||||
recipes = {},
|
||||
abilities = {},
|
||||
protect = {},
|
||||
research = 0,
|
||||
}
|
||||
magicalities.data[player_name] = table.copy(data_default)
|
||||
return
|
||||
end
|
||||
|
||||
@ -53,6 +55,22 @@ end
|
||||
|
||||
-- System Actions
|
||||
|
||||
minetest.register_chatcommand("mgcstoragereset", {
|
||||
func = function (name, params)
|
||||
magicalities.data[name] = table.copy(data_default)
|
||||
magicalities.save_player_data(name)
|
||||
return true, "Deleted player storage successfully."
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("mgcstoragesave", {
|
||||
privs = {basic_privs = 1},
|
||||
func = function (name, params)
|
||||
magicalities.save_all_data()
|
||||
return true, "Saved all magicalities data."
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_on_shutdown(magicalities.save_all_data)
|
||||
|
||||
minetest.register_on_joinplayer(function (player)
|
||||
|
@ -1,6 +1,5 @@
|
||||
|
||||
magicalities.arcane = {}
|
||||
magicalities.arcane.recipes = {}
|
||||
magicalities.arcane = { recipes = {} }
|
||||
|
||||
local fmspecelems = {
|
||||
["earth"] = {2.98, 0.15},
|
||||
|
BIN
textures/magicalities_gui_slot.png
Normal file
BIN
textures/magicalities_gui_slot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 271 B |
Loading…
Reference in New Issue
Block a user