parent
e3e8fe5e19
commit
3c287f8801
271
api.lua
271
api.lua
|
@ -1,271 +1,12 @@
|
|||
-----------------------------------------------------------------
|
||||
-- MULTIBLOCK RECIPES -------------------------------------------
|
||||
-- MOD MAGIC API ------------------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
|
||||
function magic.register_recipe(name, recipe, action)
|
||||
magic.recipes[name] = {recipe, action}
|
||||
end
|
||||
|
||||
function magic.do_spell(itemstack, placer, pointed_thing)
|
||||
local name
|
||||
|
||||
if pointed_thing.type == "object" then
|
||||
return
|
||||
elseif pointed_thing.type == "node" then
|
||||
name = minetest.get_node(pointed_thing.under).name
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local coincidences = magic.find_possible_recipes(pointed_thing)
|
||||
|
||||
if #coincidences > 0 then
|
||||
for n_rec, rec in ipairs(coincidences) do
|
||||
local pt = pointed_thing
|
||||
|
||||
if magic.check_recipe(rec, pt) then
|
||||
magic.recipes[rec][2](pt, placer)
|
||||
return
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
function magic.check_recipe(recipe_id, target)
|
||||
local recipe = magic.recipes[recipe_id][1]
|
||||
|
||||
local posx = target.under.x
|
||||
local posy = target.under.y
|
||||
local posz = target.under.z
|
||||
|
||||
local reference = {x = posx - math.floor(#recipe[1][1] / 2),
|
||||
y = posy - math.floor(#recipe / 2),
|
||||
z = posz - math.floor(#recipe[1] / 2)}
|
||||
|
||||
local i = 0
|
||||
local j = 0
|
||||
local k = 0
|
||||
|
||||
k = 0
|
||||
for n_lin, lin in ipairs(recipe) do
|
||||
posy = reference.y + k
|
||||
|
||||
j = 0
|
||||
for n_col, col in ipairs(lin) do
|
||||
posz = reference.z + j
|
||||
|
||||
i = 0
|
||||
for n_elem, elem in ipairs(col) do
|
||||
posx = reference.x + i
|
||||
|
||||
if elem ~= "" then
|
||||
local nodedef = minetest.registered_nodes[minetest.get_node({x = posx,y = posy,z = posz}).name]
|
||||
local grupo = false;
|
||||
for g, _ in pairs(nodedef.groups) do
|
||||
if elem == g then
|
||||
grupo = true;
|
||||
end
|
||||
end
|
||||
|
||||
if elem ~= minetest.get_node({x = posx,y = posy,z = posz}).name and not grupo then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
i = i + 1
|
||||
end
|
||||
j = j + 1
|
||||
end
|
||||
k = k + 1
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function magic.find_possible_recipes(node)
|
||||
local to_ret = {}
|
||||
local coincide
|
||||
local nodedef = minetest.registered_nodes[minetest.get_node(node.under).name]
|
||||
|
||||
for n_rec, rec in pairs(magic.recipes) do
|
||||
coincide = false
|
||||
|
||||
for n_lin, lin in ipairs(rec[1]) do
|
||||
for n_col, col in ipairs(lin) do
|
||||
for n_elem, elem in ipairs(col) do
|
||||
local grupo = false;
|
||||
for g, _ in pairs(nodedef.groups) do
|
||||
if elem == g then
|
||||
grupo = true;
|
||||
end
|
||||
end
|
||||
if elem == minetest.get_node(node.under).name or grupo then
|
||||
to_ret[#to_ret+1] = n_rec
|
||||
|
||||
coincide = true
|
||||
end
|
||||
|
||||
if coincide then break end
|
||||
end
|
||||
|
||||
if coincide then break end
|
||||
end
|
||||
|
||||
if coincide then break end
|
||||
end
|
||||
end
|
||||
|
||||
return to_ret
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
-- ALTAR RITUALS ------------------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
function magic.register_ritual(name, ritual, action)
|
||||
magic.rituals[name] = {ritual, action}
|
||||
end
|
||||
|
||||
function magic.do_ritual(node, player)
|
||||
local things = magic.get_items(node)
|
||||
|
||||
if #things < 1 then
|
||||
minetest.chat_send_player(player:get_player_name(), "[Mod magic] The altar is empty")
|
||||
return
|
||||
end
|
||||
|
||||
local itemlist = magic.organice_items(things)
|
||||
local n_rit = magic.check_ritual(itemlist)
|
||||
|
||||
if n_rit then
|
||||
magic.rituals[n_rit][2](node, player)
|
||||
end
|
||||
end
|
||||
|
||||
function magic.get_items(node)
|
||||
local pos = node.under
|
||||
local things = {}
|
||||
|
||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
|
||||
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
|
||||
table.insert(things,object:get_luaentity().itemstring)
|
||||
end
|
||||
end
|
||||
|
||||
return things
|
||||
end
|
||||
|
||||
function magic.organice_items(things)
|
||||
local did = false
|
||||
local itemlist = {}
|
||||
|
||||
for i, n in pairs(things) do
|
||||
did = false
|
||||
|
||||
for j in ipairs(itemlist) do
|
||||
if itemlist[j].name == n then
|
||||
itemlist[j].val = itemlist[j].val + 1
|
||||
did = true
|
||||
end
|
||||
end
|
||||
|
||||
if not did then
|
||||
itemlist[#itemlist+1] = {name = n, val = 1}
|
||||
end
|
||||
end
|
||||
|
||||
return itemlist
|
||||
end
|
||||
|
||||
function magic.check_ritual(itemlist)
|
||||
for ritual_id, ritual_content in pairs(magic.rituals) do
|
||||
if #ritual_content[1] == #itemlist then
|
||||
local check = false
|
||||
for i in ipairs(itemlist) do
|
||||
check = magic.check_item_in_ritual(itemlist[i], ritual_content[1])
|
||||
|
||||
if not check then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if check then
|
||||
return ritual_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
function magic.check_item_in_ritual(item, itemlist)
|
||||
for i in ipairs(itemlist) do
|
||||
if itemlist[i].name == item.name and itemlist[i].val == item.val then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function magic.clear_altar(node)
|
||||
local pos = node.under
|
||||
local things = {}
|
||||
|
||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
|
||||
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
|
||||
object:get_luaentity().itemstring = ""
|
||||
object:remove()
|
||||
end
|
||||
end
|
||||
|
||||
return things
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
-- HOME WARP ----------------------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
|
||||
function magic.warp(player)
|
||||
local playerName = player:get_player_name()
|
||||
local home = magic.checkHome(playerName)
|
||||
if home == -1 then
|
||||
minetest.chat_send_player(playerName, "[Mod Magic] Unknown home")
|
||||
return
|
||||
end
|
||||
|
||||
player:setpos(magic.playerHomes[home].homepos)
|
||||
player:set_look_yaw(0)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
-- TIER REGISTERING UTILS ---------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
|
||||
function magic.add_group_to_node(n, group)
|
||||
local def = minetest.registered_items[n]
|
||||
if not def then
|
||||
return false
|
||||
end
|
||||
|
||||
local dg = def.groups or {}
|
||||
for _group, value in pairs(group) do
|
||||
if value ~= 0 then
|
||||
dg[_group] = value
|
||||
else
|
||||
dg[_group] = nil
|
||||
end
|
||||
end
|
||||
|
||||
minetest.override_item(n, {groups = dg})
|
||||
return true
|
||||
end
|
||||
|
||||
function magic.add_group(group, node_list)
|
||||
for i in ipairs(node_list) do
|
||||
magic.add_group_to_node(node_list[i], group)
|
||||
end
|
||||
end
|
||||
dofile(magic.path.."/functions/homewarp.lua")
|
||||
dofile(magic.path.."/functions/multiblock.lua")
|
||||
dofile(magic.path.."/functions/altar_rituals.lua")
|
||||
dofile(magic.path.."/functions/tiers.lua")
|
||||
dofile(magic.path.."/functions/enchantments.lua")
|
||||
|
||||
-----------------------------------------------------------------
|
||||
-- OTHER UTILITIES ----------------------------------------------
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
-----------------------------------------------------------------
|
||||
-- ALTAR RITUALS ------------------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
function magic.register_ritual(name, ritual, action)
|
||||
magic.rituals[name] = {ritual, action}
|
||||
end
|
||||
|
||||
function magic.do_ritual(node, player)
|
||||
local things = magic.get_items(node)
|
||||
|
||||
if #things < 1 then
|
||||
minetest.chat_send_player(player:get_player_name(), "[Mod magic] The altar is empty")
|
||||
return
|
||||
end
|
||||
|
||||
local itemlist = magic.organice_items(things)
|
||||
local n_rit = magic.check_ritual(itemlist)
|
||||
|
||||
if n_rit then
|
||||
magic.rituals[n_rit][2](node, player)
|
||||
end
|
||||
end
|
||||
|
||||
function magic.get_items(node)
|
||||
local pos = node.under
|
||||
local things = {}
|
||||
|
||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
|
||||
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
|
||||
table.insert(things,object:get_luaentity().itemstring)
|
||||
end
|
||||
end
|
||||
|
||||
return things
|
||||
end
|
||||
|
||||
function magic.organice_items(things)
|
||||
local did = false
|
||||
local itemlist = {}
|
||||
|
||||
for i, n in pairs(things) do
|
||||
did = false
|
||||
|
||||
for j in ipairs(itemlist) do
|
||||
if itemlist[j].name == n then
|
||||
itemlist[j].val = itemlist[j].val + 1
|
||||
did = true
|
||||
end
|
||||
end
|
||||
|
||||
if not did then
|
||||
itemlist[#itemlist+1] = {name = n, val = 1}
|
||||
end
|
||||
end
|
||||
|
||||
return itemlist
|
||||
end
|
||||
|
||||
function magic.check_ritual(itemlist)
|
||||
for ritual_id, ritual_content in pairs(magic.rituals) do
|
||||
if #ritual_content[1] == #itemlist then
|
||||
local check = false
|
||||
for i in ipairs(itemlist) do
|
||||
check = magic.check_item_in_ritual(itemlist[i], ritual_content[1])
|
||||
|
||||
if not check then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if check then
|
||||
return ritual_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
function magic.check_item_in_ritual(item, itemlist)
|
||||
for i in ipairs(itemlist) do
|
||||
if itemlist[i].name == item.name and itemlist[i].val == item.val then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function magic.clear_altar(node)
|
||||
local pos = node.under
|
||||
local things = {}
|
||||
|
||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
|
||||
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
|
||||
object:get_luaentity().itemstring = ""
|
||||
object:remove()
|
||||
end
|
||||
end
|
||||
|
||||
return things
|
||||
end
|
|
@ -0,0 +1,171 @@
|
|||
-----------------------------------------------------------------
|
||||
-- ENCHANTMENTS LOGIC -------------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||
magic.use_tool(pos, oldnode, digger)
|
||||
end)
|
||||
|
||||
function magic.use_tool(pos, oldnode, digger)
|
||||
local item = digger:get_wielded_item()
|
||||
local meta = item:get_meta()
|
||||
if item:to_string() == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local actions = {}
|
||||
local nodeinfo = {
|
||||
name = oldnode.name,
|
||||
drop = minetest.get_node_drops(oldnode.name, name)[1],
|
||||
}
|
||||
|
||||
for e_id, enchantment in pairs(magic.enchants) do
|
||||
if enchantment.type == "on_dig" then
|
||||
local value = meta:get_string(e_id)
|
||||
if value ~= "" then
|
||||
actions[#actions + 1] = {val = tonumber(value), action = enchantment.action}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if #actions == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
for i in ipairs(actions) do
|
||||
actions[i].action(actions[i].val, pos, oldnode, digger, nodeinfo)
|
||||
end
|
||||
|
||||
minetest.add_item(pos, nodeinfo.drop)
|
||||
end
|
||||
|
||||
function magic.register_on_dig_enchant(enchant_id, enchant_type, value_max, action_function, ingredient, enchantables)
|
||||
magic.enchants[enchant_id] =
|
||||
{
|
||||
type = enchant_type,
|
||||
max = value_max,
|
||||
action = action_function
|
||||
}
|
||||
|
||||
if #enchantables == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
for i in ipairs(enchantables) do
|
||||
magic.register_ritual(enchant_id .. "_" .. enchantables[i],
|
||||
{
|
||||
{name = enchantables[i], val = 1},
|
||||
{name = ingredient, val = 1},
|
||||
},
|
||||
|
||||
function(node, player)
|
||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(node.under, 1)) do
|
||||
if not object:is_player() and object:get_luaentity() and
|
||||
object:get_luaentity().name == "__builtin:item" then
|
||||
if object:get_luaentity().itemstring == enchantables[i] then
|
||||
local item = ItemStack(object:get_luaentity().itemstring)
|
||||
local meta = item:get_meta()
|
||||
local def = minetest.registered_items[item:get_name()]
|
||||
meta:set_string("description", def.description .. " (" .. enchant_id .. ")")
|
||||
meta:set_string("inventory_image", def.inventory_image.."^[colorize:#551A8B:120")
|
||||
meta:set_string(enchant_id, "3")
|
||||
|
||||
object:remove()
|
||||
minetest.env:add_item(node.under, item)
|
||||
else
|
||||
object:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
-- ENCHANTMENTS -------------------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
magic.register_on_dig_enchant("luck", "on_dig", 3,
|
||||
function(luck_value, pos, oldnode, digger, nodeinfo)
|
||||
local drop_count = math.random(2, luck_value + 1)
|
||||
nodeinfo.drop = nodeinfo.drop.." "..drop_count
|
||||
return nodeinfo
|
||||
end,
|
||||
|
||||
"default:cobble",
|
||||
|
||||
{
|
||||
"default:pick_diamond",
|
||||
"default:shovel_diamond",
|
||||
"default:axe_diamond",
|
||||
|
||||
"default:pick_steel",
|
||||
"default:shovel_steel",
|
||||
"default:axe_steel",
|
||||
|
||||
"default:pick_stone",
|
||||
"default:shovel_stone",
|
||||
"default:axe_stone",
|
||||
|
||||
"default:pick_wood",
|
||||
"default:shovel_wood",
|
||||
"default:axe_wood"
|
||||
}
|
||||
)
|
||||
magic.register_on_dig_enchant("silk_touch", "on_dig", 3,
|
||||
function(luck_value, pos, oldnode, digger, nodeinfo)
|
||||
nodeinfo.drop = oldnode.name
|
||||
return nodeinfo
|
||||
end,
|
||||
|
||||
"default:wood",
|
||||
|
||||
{
|
||||
"default:pick_diamond",
|
||||
"default:shovel_diamond",
|
||||
"default:axe_diamond",
|
||||
|
||||
"default:pick_steel",
|
||||
"default:shovel_steel",
|
||||
"default:axe_steel",
|
||||
|
||||
"default:pick_stone",
|
||||
"default:shovel_stone",
|
||||
"default:axe_stone",
|
||||
|
||||
"default:pick_wood",
|
||||
"default:shovel_wood",
|
||||
"default:axe_wood"
|
||||
}
|
||||
)
|
||||
magic.register_on_dig_enchant("cook", "on_dig", 3,
|
||||
function(luck_value, pos, oldnode, digger, nodeinfo)
|
||||
local temper, _ = minetest.get_craft_result({ method = "cooking", width = 1, items = {nodeinfo.drop}})
|
||||
|
||||
if temper and temper.item:to_table() then
|
||||
temper = temper.item:to_table().name
|
||||
nodeinfo.drop = temper
|
||||
end
|
||||
|
||||
return nodeinfo
|
||||
end,
|
||||
|
||||
"default:coal_lump",
|
||||
|
||||
{
|
||||
"default:pick_diamond",
|
||||
"default:shovel_diamond",
|
||||
"default:axe_diamond",
|
||||
|
||||
"default:pick_steel",
|
||||
"default:shovel_steel",
|
||||
"default:axe_steel",
|
||||
|
||||
"default:pick_stone",
|
||||
"default:shovel_stone",
|
||||
"default:axe_stone",
|
||||
|
||||
"default:pick_wood",
|
||||
"default:shovel_wood",
|
||||
"default:axe_wood"
|
||||
}
|
||||
)
|
|
@ -49,4 +49,16 @@ function magic.checkHome(player)
|
|||
end
|
||||
|
||||
return -1
|
||||
end
|
||||
|
||||
function magic.warp(player)
|
||||
local playerName = player:get_player_name()
|
||||
local home = magic.checkHome(playerName)
|
||||
if home == -1 then
|
||||
minetest.chat_send_player(playerName, "[Mod Magic] Unknown home")
|
||||
return
|
||||
end
|
||||
|
||||
player:setpos(magic.playerHomes[home].homepos)
|
||||
player:set_look_yaw(0)
|
||||
end
|
|
@ -0,0 +1,123 @@
|
|||
-----------------------------------------------------------------
|
||||
-- MULTIBLOCK RECIPES -------------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
function magic.register_recipe(name, recipe, action)
|
||||
magic.recipes[name] = {recipe, action}
|
||||
end
|
||||
|
||||
function magic.do_spell(itemstack, placer, pointed_thing)
|
||||
local name
|
||||
|
||||
if pointed_thing.type == "object" then
|
||||
return
|
||||
elseif pointed_thing.type == "node" then
|
||||
name = minetest.get_node(pointed_thing.under).name
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
local npos = pointed_thing.under
|
||||
local npos2 = pointed_thing.above
|
||||
|
||||
local facedir = {x = npos.x - npos2.x, y = npos.y - npos2.y, z = npos.z - npos2.z}
|
||||
|
||||
local coincidences = magic.find_possible_recipes(pointed_thing)
|
||||
|
||||
if #coincidences > 0 then
|
||||
for n_rec, rec in ipairs(coincidences) do
|
||||
local pt = pointed_thing
|
||||
|
||||
if magic.check_recipe(rec, pt) then
|
||||
magic.recipes[rec][2](pt, placer, facedir)
|
||||
--return
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
function magic.check_recipe(recipe_id, target)
|
||||
local recipe = magic.recipes[recipe_id][1]
|
||||
|
||||
local posx = target.under.x
|
||||
local posy = target.under.y
|
||||
local posz = target.under.z
|
||||
|
||||
local reference = {x = posx - math.floor(#recipe[1][1] / 2),
|
||||
y = posy - math.floor(#recipe / 2),
|
||||
z = posz - math.floor(#recipe[1] / 2)}
|
||||
|
||||
local i = 0
|
||||
local j = 0
|
||||
local k = 0
|
||||
|
||||
k = 0
|
||||
for n_lin, lin in ipairs(recipe) do
|
||||
posy = reference.y + k
|
||||
|
||||
j = 0
|
||||
for n_col, col in ipairs(lin) do
|
||||
posz = reference.z + j
|
||||
|
||||
i = 0
|
||||
for n_elem, elem in ipairs(col) do
|
||||
posx = reference.x + i
|
||||
|
||||
if elem ~= "" then
|
||||
local nodedef = minetest.registered_nodes[minetest.get_node({x = posx,y = posy,z = posz}).name]
|
||||
local grupo = false;
|
||||
for g, _ in pairs(nodedef.groups) do
|
||||
if elem == g then
|
||||
grupo = true;
|
||||
end
|
||||
end
|
||||
|
||||
if elem ~= minetest.get_node({x = posx,y = posy,z = posz}).name and not grupo then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
i = i + 1
|
||||
end
|
||||
j = j + 1
|
||||
end
|
||||
k = k + 1
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function magic.find_possible_recipes(node)
|
||||
local to_ret = {}
|
||||
local coincide
|
||||
local nodedef = minetest.registered_nodes[minetest.get_node(node.under).name]
|
||||
|
||||
for n_rec, rec in pairs(magic.recipes) do
|
||||
coincide = false
|
||||
|
||||
for n_lin, lin in ipairs(rec[1]) do
|
||||
for n_col, col in ipairs(lin) do
|
||||
for n_elem, elem in ipairs(col) do
|
||||
local grupo = false;
|
||||
for g, _ in pairs(nodedef.groups) do
|
||||
if elem == g then
|
||||
grupo = true;
|
||||
end
|
||||
end
|
||||
if elem == minetest.get_node(node.under).name or grupo then
|
||||
to_ret[#to_ret+1] = n_rec
|
||||
|
||||
coincide = true
|
||||
end
|
||||
|
||||
if coincide then break end
|
||||
end
|
||||
|
||||
if coincide then break end
|
||||
end
|
||||
|
||||
if coincide then break end
|
||||
end
|
||||
end
|
||||
|
||||
return to_ret
|
||||
end
|
|
@ -0,0 +1,45 @@
|
|||
-----------------------------------------------------------------
|
||||
-- TIER REGISTERING UTILS ---------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
function magic.add_group_to_node(n, group)
|
||||
local def = minetest.registered_items[n]
|
||||
if not def then
|
||||
return false
|
||||
end
|
||||
|
||||
local dg = def.groups or {}
|
||||
for _group, value in pairs(group) do
|
||||
if value ~= 0 then
|
||||
dg[_group] = value
|
||||
else
|
||||
dg[_group] = nil
|
||||
end
|
||||
end
|
||||
|
||||
minetest.override_item(n, {groups = dg})
|
||||
return true
|
||||
end
|
||||
|
||||
function magic.add_group(group, node_list)
|
||||
for i in ipairs(node_list) do
|
||||
magic.add_group_to_node(node_list[i], group)
|
||||
end
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
-- TIERS --------------------------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
magic.add_group(
|
||||
{tier1 = 1},
|
||||
{"default:stone", "default:cobble", "default:stonebrick", "default:stone_block", "default:mossycobble", "default:desert_stone", "default:desert_cobble", "default:desert_stonebrick", "default:desert_stone_block", "default:sandstone", "default:sandstonebrick", "default:sandstone_block", "default:dirt", "default:dirt_with_grass", "default:dirt_with_grass_footsteps", "default:dirt_with_dry_grass", "default:sand", "default:desert_sand", "default:silver_sand", "default:gravel", "default:clay"}
|
||||
)
|
||||
|
||||
magic.add_group(
|
||||
{tier2 = 1},
|
||||
{"default:coalblock","default:diamondblock","default:goldblock","default:obsidian_block"}
|
||||
)
|
||||
|
||||
magic.add_group(
|
||||
{t_altar = 1},
|
||||
{"default:stone", "default:cobble", "default:mossycobble"}
|
||||
)
|
8
init.lua
8
init.lua
|
@ -1,13 +1,16 @@
|
|||
-- Definitions made by this mod that other mods can use too
|
||||
magic = {}
|
||||
|
||||
magic.recipes = {}
|
||||
magic.rituals = {}
|
||||
|
||||
magic.playerHomes = {}
|
||||
magic.enchants = {}
|
||||
|
||||
magic.path = minetest.get_modpath("magic")
|
||||
magic.worldpath = minetest.get_worldpath()
|
||||
|
||||
-- Load files
|
||||
dofile(magic.path.."/functions/homewarp.lua")
|
||||
dofile(magic.path.."/api.lua")
|
||||
|
||||
dofile(magic.path.."/items/wand.lua")
|
||||
|
@ -25,14 +28,15 @@ dofile(magic.path.."/recipes/t0_begining.lua")
|
|||
dofile(magic.path.."/recipes/t1_altar.lua")
|
||||
dofile(magic.path.."/recipes/t1_big_tree.lua")
|
||||
dofile(magic.path.."/recipes/t1_compass.lua")
|
||||
dofile(magic.path.."/recipes/t1_extension.lua")
|
||||
dofile(magic.path.."/recipes/t1_home_stone.lua")
|
||||
dofile(magic.path.."/recipes/t1_home_warp.lua")
|
||||
dofile(magic.path.."/recipes/t1_laputa.lua")
|
||||
dofile(magic.path.."/recipes/t1_perforator.lua")
|
||||
dofile(magic.path.."/recipes/t1_prospector.lua")
|
||||
dofile(magic.path.."/recipes/t2_hopperbloom.lua")
|
||||
dofile(magic.path.."/recipes/t2_lightbloom.lua")
|
||||
|
||||
dofile(magic.path.."/tiers.lua")
|
||||
|
||||
magic.loadHomes()
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ minetest.register_node("magic:hopperbloom", {
|
|||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
buildable_to = true,
|
||||
stack_max = 64,
|
||||
groups = {snappy = 3, flower = 1, flora = 1, attached_node = 1},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
|
|
|
@ -10,7 +10,6 @@ minetest.register_node("magic:lightbloom", {
|
|||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
buildable_to = true,
|
||||
stack_max = 64,
|
||||
groups = {snappy = 3, flower = 1, flora = 1, attached_node = 1},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
-----------------------------------------------------------------
|
||||
-- EXTENSION RECIPE ---------------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
local function extension_action(node, player, facedir)
|
||||
local posx = node.under.x
|
||||
local posy = node.under.y
|
||||
local posz = node.under.z
|
||||
|
||||
local base = {}
|
||||
base[0] = minetest.get_node({x = posx - facedir.z, y = posy - 1, z = posz - facedir.x}).name
|
||||
base[1] = minetest.get_node({x = posx , y = posy - 1, z = posz}).name
|
||||
base[2] = minetest.get_node({x = posx + facedir.z, y = posy - 1, z = posz + facedir.x}).name
|
||||
|
||||
local n = ""
|
||||
n = minetest.get_node({x = posx, y = posy + 1, z = posz}).name
|
||||
|
||||
local range = 5
|
||||
if n == "default:coalblock" then
|
||||
range = range * 2
|
||||
elseif n == "default:goldblock" then
|
||||
range = range * 4
|
||||
elseif n == "default:diamondblock" then
|
||||
range = range * 8
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
local item = ""
|
||||
for i = 1, range do
|
||||
item = minetest.get_node({x = posx + facedir.z + facedir.x*i, y = posy - 1, z = posz - facedir.x + facedir.z*i}).name
|
||||
if item == "air" then
|
||||
minetest.set_node({x = posx + facedir.z + facedir.x*i, y = posy - 1, z = posz - facedir.x + facedir.z*i},{name = base[0]})
|
||||
end
|
||||
|
||||
item = minetest.get_node({x = posx + facedir.x*i, y = posy - 1, z = posz + facedir.z*i}).name
|
||||
if item == "air" then
|
||||
minetest.set_node({x = posx + facedir.x*i, y = posy - 1, z = posz + facedir.z*i},{name = base[1]})
|
||||
end
|
||||
|
||||
item = minetest.get_node({x = posx - facedir.z + facedir.x*i, y = posy - 1, z = posz + facedir.x + facedir.z*i}).name
|
||||
if item == "air" then
|
||||
minetest.set_node({x = posx - facedir.z + facedir.x*i, y = posy - 1, z = posz + facedir.x + facedir.z*i},{name = base[2]})
|
||||
end
|
||||
end
|
||||
--minetest.set_node({x = posx, y = posy + 1, z = posz}, {name="air"})
|
||||
end
|
||||
|
||||
magic.register_recipe("extension",
|
||||
{
|
||||
{
|
||||
{"", "",""},
|
||||
{"default:obsidian", "default:obsidian","default:obsidian"},
|
||||
{"", "", ""},
|
||||
},
|
||||
},
|
||||
function(node, player, facedir)
|
||||
extension_action(node, player, facedir)
|
||||
end
|
||||
)
|
||||
|
||||
magic.register_recipe("extension2",
|
||||
{
|
||||
{
|
||||
{"", "default:obsidian",""},
|
||||
{"", "default:obsidian",""},
|
||||
{"", "default:obsidian", ""},
|
||||
},
|
||||
},
|
||||
function(node, player, facedir)
|
||||
extension_action(node, player, facedir)
|
||||
end
|
||||
)
|
|
@ -36,7 +36,6 @@ magic.register_recipe("laputa",
|
|||
if minetest.get_node({x = posx + 1, y = posy, z = posz}).name ~= n or
|
||||
minetest.get_node({x = posx, y = posy, z = posz - 1}).name ~= n or
|
||||
minetest.get_node({x = posx, y = posy, z = posz + 1}).name ~= n then
|
||||
minetest.chat_send_all("Nop")
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
-----------------------------------------------------------------
|
||||
-- PROSPECTOR RECIPE --------------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
|
||||
magic.register_recipe("perforator",
|
||||
{
|
||||
{
|
||||
{"", "",""},
|
||||
{"", "default:obsidian",""},
|
||||
{"", "", ""},
|
||||
},
|
||||
},
|
||||
function(node, player, facedir)
|
||||
local posx = node.under.x
|
||||
local posy = node.under.y
|
||||
local posz = node.under.z
|
||||
|
||||
local n = ""
|
||||
local modif = {x = 2, y = 2, z = 2}
|
||||
if facedir.x ~= 0 then
|
||||
modif.x = 0
|
||||
n = minetest.get_node({x = posx, y = posy, z = posz + 1}).name
|
||||
if minetest.get_node({x = posx, y = posy, z = posz - 1}).name ~= n then
|
||||
return
|
||||
end
|
||||
elseif facedir.z ~= 0 then
|
||||
modif.z = 0
|
||||
n = minetest.get_node({x = posx + 1, y = posy, z = posz}).name
|
||||
if minetest.get_node({x = posx - 1, y = posy, z = posz}).name ~= n then
|
||||
return
|
||||
end
|
||||
elseif facedir.y ~= 0 then
|
||||
modif.y = 0
|
||||
n = minetest.get_node({x = posx - 1, y = posy, z = posz}).name
|
||||
if n ~= "air" then
|
||||
if minetest.get_node({x = posx + 1, y = posy, z = posz}).name ~= n then
|
||||
return
|
||||
end
|
||||
else
|
||||
n = minetest.get_node({x = posx, y = posy, z = posz - 1}).name
|
||||
if minetest.get_node({x = posx, y = posy, z = posz + 1}).name ~= n then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local range = 5
|
||||
if n == "default:coalblock" then
|
||||
range = range * 2
|
||||
elseif n == "default:goldblock" then
|
||||
range = range * 4
|
||||
elseif n == "default:diamondblock" then
|
||||
range = range * 8
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
local item = ""
|
||||
for i = 0, range do
|
||||
for eq = modif.x*-1, modif.x do
|
||||
for iy = modif.y*-1, modif.y do
|
||||
for zz = modif.z*-1, modif.z do
|
||||
item = minetest.get_node({x = posx + eq + facedir.x*i, y = posy + iy + facedir.y*i, z = posz + zz + facedir.z*i})
|
||||
if item.name ~= "air" and item.description ~= "" then
|
||||
if i ~= 0 then
|
||||
minetest.env:add_item({x=posx + (math.random(-3,3)/10),y=posy+(math.random(25,75)/100),z=posz + (math.random(-3,3)/10)}, item.name)
|
||||
end
|
||||
minetest.set_node({x = posx + eq + facedir.x*i, y = posy + iy+ facedir.y*i, z = posz + zz + facedir.z*i},{name = "air"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
|
@ -2,7 +2,7 @@
|
|||
-- PROSPECTOR RECIPE --------------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
|
||||
magic.register_recipe("compass",
|
||||
magic.register_recipe("prospector",
|
||||
{
|
||||
{
|
||||
{"", "default:cobble", "","default:cobble",""},
|
||||
|
|
14
tiers.lua
14
tiers.lua
|
@ -1,14 +0,0 @@
|
|||
magic.add_group(
|
||||
{tier1 = 1},
|
||||
{"default:stone", "default:cobble", "default:stonebrick", "default:stone_block", "default:mossycobble", "default:desert_stone", "default:desert_cobble", "default:desert_stonebrick", "default:desert_stone_block", "default:sandstone", "default:sandstonebrick", "default:sandstone_block", "default:dirt", "default:dirt_with_grass", "default:dirt_with_grass_footsteps", "default:dirt_with_dry_grass", "default:sand", "default:desert_sand", "default:silver_sand", "default:gravel", "default:clay"}
|
||||
)
|
||||
|
||||
magic.add_group(
|
||||
{tier2 = 1},
|
||||
{"default:coalblock","default:diamondblock","default:goldblock","default:obsidian_block"}
|
||||
)
|
||||
|
||||
magic.add_group(
|
||||
{t_altar = 1},
|
||||
{"default:stone", "default:cobble", "default:mossycobble"}
|
||||
)
|
Loading…
Reference in New Issue