elemental ring

This commit is contained in:
Evert Prants 2018-04-18 12:05:29 +03:00
parent 0afbd6029a
commit 409784a52c
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
7 changed files with 139 additions and 19 deletions

View File

@ -14,7 +14,3 @@ minetest.register_craftitem("magicalities:cap_gold", {
inventory_image = "magicalities_cap_gold.png"
})
minetest.register_craftitem("magicalities:element_ring", {
description = "Elemental Ring",
inventory_image = "magicalities_element_ring.png"
})

View File

@ -1,28 +1,69 @@
-- Magicalities crystals
magicalities.crystals = {}
local randbuff = PcgRandom(os.clock())
local function generate_crystal_buffer(pos)
local function compare(a,b)
return a[2] > b[2]
end
local function crystal_infotext(pos, data)
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
local nodedef = minetest.registered_nodes[node.name]
if not data then
data = minetest.deserialize(meta:get_string("contents"))
end
-- Sort
local sortable = {}
for name, v in pairs(data) do
sortable[#sortable + 1] = {name, v[1]}
end
table.sort(sortable, compare)
-- Create string
local str = nodedef.description.. "\n\n"
local datastrs = {}
for _, v in pairs(sortable) do
local elemdesc = magicalities.elements[v[1]].description
datastrs[#datastrs + 1] = v[2].."x "..elemdesc
end
str = str .. table.concat( datastrs, "\n")
meta:set_string("infotext", str)
end
function magicalities.crystals.generate_crystal_buffer(pos)
local final = {}
local node = minetest.get_node(pos)
local nodedef = minetest.registered_nodes[node.name]
local self_cnt = randbuff:next(10, 60)
local added = 0
for name, data in pairs(magicalities.elements) do
if #final > 5 then break end
if added > 5 then break end
if not data.inheritance then
if name == nodedef["_element"] then
final[name] = {self_cnt, self_cnt}
added = added + 1
else
if randbuff:next(0, 5) == 0 then
local cnt = randbuff:next(0, math.floor(self_cnt / 4))
final[name] = {cnt, cnt}
if cnt > 0 then
final[name] = {cnt, cnt}
added = added + 1
end
end
end
else
if randbuff:next(0, 15) == 0 then
local cnt = randbuff:next(0, math.floor(self_cnt / 8))
final[name] = {cnt, cnt}
if cnt > 0 then
final[name] = {cnt, cnt}
added = added + 1
end
end
end
end
@ -31,13 +72,13 @@ local function generate_crystal_buffer(pos)
end
local function crystal_rightclick(pos, node, clicker, itemstack, pointed_thing)
local output = generate_crystal_buffer(pos)
local output = magicalities.crystals.generate_crystal_buffer(pos)
local meta = minetest.get_meta(pos)
-- Add contents to the crystal
local contents = minetest.deserialize(meta:get_string("contents"))
if not contents then
contents = generate_crystal_buffer(pos)
contents = magicalities.crystals.generate_crystal_buffer(pos)
meta:set_string("contents", minetest.serialize(contents))
end

View File

@ -28,5 +28,8 @@ dofile(modpath.."/table.lua")
-- Items
dofile(modpath.."/craftitems.lua")
-- Scanner
dofile(modpath.."/scanner.lua")
-- Register
dofile(modpath.."/register.lua")

View File

@ -44,6 +44,18 @@ local recipes = {
["dark"] = 25,
["air"] = 25,
}
},
{
input = {
{"default:gold_ingot", "default:gold_ingot", "default:gold_ingot"},
{"default:gold_ingot", "", "default:gold_ingot"},
},
output = "magicalities:cap_gold",
requirements = {
["earth"] = 5,
["light"] = 5,
["dark"] = 5,
}
}
}

74
scanner.lua Normal file
View File

@ -0,0 +1,74 @@
-- Scans crystals for their contents
local fmspecelems = {
["earth"] = {2, 0.15},
["water"] = {0, 1},
["air"] = {4, 1},
["fire"] = {2, 4.85},
["light"] = {0, 4},
["dark"] = {4, 4}
}
local function create_formspec(elements, desc)
local spec = ""
local labels = ""
if not elements then
elements = {}
end
for name, pos in pairs(fmspecelems) do
local cp = ""
local y = -0.4
if not elements[name] then
cp = "^[colorize:#2f2f2f:200"
elseif elements[name] and elements[name][1] == 0 then
cp = "^[colorize:#2f2f2f:128"
end
if pos[2] > 2.5 then
y = 0.85
end
spec = spec .. "image["..pos[1]..","..pos[2]..";1,1;magicalities_symbol_"..name..".png"..cp.."]"
if elements[name] then
labels = labels .. "label["..(pos[1] + 0.3)..","..(pos[2] + y)..";"..elements[name][1].."]"
end
end
return "size[5,6]"..
default.gui_bg..
default.gui_bg_img..
"label[0,0;"..desc.."]"..
"image[0,0.3;6,6;magicalities_symbol_hexagram.png]"..
spec..
labels
end
local function show_spec(i, placer, pointed_thing)
local pos = pointed_thing.under
local node = minetest.get_node(pos)
if not node or minetest.get_item_group(node.name, "crystal_cluster") == 0 then
return i
end
local meta = minetest.get_meta(pos)
local nodedef = minetest.registered_nodes[node.name]
local contents = minetest.deserialize(meta:get_string("contents"))
if not contents then
contents = magicalities.crystals.generate_crystal_buffer(pos)
end
minetest.show_formspec(placer:get_player_name(), "magicalities:crystal_scanner", create_formspec(contents, nodedef.description))
return i
end
minetest.register_craftitem("magicalities:element_ring", {
description = "Elemental Ring\nShows contents of crystals",
inventory_image = "magicalities_element_ring.png",
on_place = show_spec,
})

View File

@ -24,7 +24,7 @@ local function arcane_table_formspec(data)
local y = -0.4
if not data[name] then
cp = "^[colorize:#2f2f2f"
cp = "^[colorize:#2f2f2f:200"
end
if pos[2] > 2.5 then

View File

@ -142,7 +142,7 @@ local function initialize_wand(stack)
for name, data in pairs(magicalities.elements) do
if not data.inheritance then
data_table[name] = 10
data_table[name] = 0
end
end
@ -206,12 +206,6 @@ local function use_wand(itemstack, user, pointed_thing)
magicalities.wands.update_wand_desc(itemstack)
end
if not magicalities.wands.wand_has_contents(itemstack, {water = 5}) then
return itemstack
end
--itemstack = magicalities.wands.wand_take_contents(itemstack, {water = 5})
-- Calculate velocity
local dir = user:get_look_dir()
local vel = {x=0,y=0,z=0}
@ -225,7 +219,7 @@ local function use_wand(itemstack, user, pointed_thing)
pos.y = pos.y + (dir.y * 2) + 1.5
pos.z = pos.z + (dir.z * 2)
for i = 1, 8 do
for i = 1, 16 do
-- Deviation
local relvel = {x=0,y=0,z=0}
relvel.x = vel.x + (randparticles:next((-i/2.5) * 1000, (i/2.5) * 1000) / 1000)