falling_light/staves.lua

245 lines
6.9 KiB
Lua
Raw Normal View History

function bomf(pos,radius)
minetest.add_particlespawner(
200, --amount
0.1, --time
{x=pos.x-radius/2, y=pos.y-radius/2, z=pos.z-radius/2}, --minpos
{x=pos.x+radius/2, y=pos.y+radius/2, z=pos.z+radius/2}, --maxpos
{x=-0, y=-0, z=-0}, --minvel
{x=1, y=1, z=1}, --maxvel
{x=-0.5,y=5,z=-0.5}, --minacc
{x=0.5,y=5,z=0.5}, --maxacc
0.1, --minexptime
1, --maxexptime
3, --minsize
4, --maxsize
false, --collisiondetection
"tnt_smoke.png" --texture
)
minetest.sound_play("vivarium_pom", {
pos = pos,
max_hear_distance = 10
})
end
function canstaff(player)
return minetest.check_player_privs(player:get_player_name(), {creative=true})
end
2016-08-16 18:57:33 +01:00
-- Staff of X (based on Staff of Light by Xanthin)
2016-08-20 12:00:03 +01:00
2016-08-18 18:46:04 +01:00
minetest.register_tool("vivarium:staff_stack", { -- this will be the wall staff
description = "Column Staff",
2016-08-18 18:35:39 +01:00
inventory_image = "water_staff.png^[colorize:yellow:90",
wield_image = "water_staff.png^[colorize:yellow:90",
range = 12,
2016-08-18 18:35:39 +01:00
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
if not canstaff(user) then return; end
2016-08-18 18:35:39 +01:00
if pointed_thing.type ~= "node" then
if pointed_thing.type == "object" then
local newpos = pointed_thing.ref:getpos()
bomf(newpos,2 )
local luae = pointed_thing.ref:get_luaentity()
luae.type="npc"
luae.attacks_monsters=true
2016-08-20 12:00:03 +01:00
luae.state="walk"
end
2016-08-18 18:35:39 +01:00
return
end
local pos = pointed_thing.under
local pname = user:get_player_name()
if minetest.is_protected(pos, pname) then
minetest.record_protection_violation(pos, pname)
return
end
local height = 5
2016-08-18 18:35:39 +01:00
local targetnode = minetest.get_node(pos).name
local userpos = user:getpos()
2016-08-18 18:46:04 +01:00
2016-08-18 18:35:39 +01:00
local relpos = (userpos.y - pos.y)/math.sqrt((userpos.y - pos.y)^2)
2016-08-18 18:46:04 +01:00
local lower = 0 ; local higher = 0
if relpos < 0 then
2016-08-18 20:47:32 +01:00
-- minetest.chat_send_player(pname, "Stack down")
2016-08-18 18:46:04 +01:00
lower = -1*height
elseif relpos > 0 then
2016-08-18 20:47:32 +01:00
-- minetest.chat_send_player(pname, "Stack up")
2016-08-18 18:46:04 +01:00
higher = height
end
2016-08-18 18:35:39 +01:00
local airnodes = minetest.find_nodes_in_area(
2016-08-18 18:46:04 +01:00
{x = pos.x, y = pos.y+lower, z = pos.z},
{x = pos.x, y = pos.y+higher, z = pos.z},
2016-08-18 18:35:39 +01:00
{"air"}
)
bomf(pos,2)
2016-08-18 18:35:39 +01:00
for _,fpos in pairs(airnodes) do
minetest.swap_node(fpos, {name = targetnode })
end
return itemstack
end,
})
2016-08-16 18:57:33 +01:00
minetest.register_tool("vivarium:staff_clone", { -- this will be the floor staff
description = "Staff of Cloning",
2016-08-18 18:35:39 +01:00
inventory_image = "water_staff.png^[colorize:green:90",
wield_image = "water_staff.png^[colorize:green:90",
range = 12,
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
if not canstaff(user) then return; end
if pointed_thing.type ~= "node" then
if pointed_thing.type == "object" then
local newpos = pointed_thing.ref:getpos()
newpos = {x=newpos.x+math.random(-1,1), y=newpos.y+0.5, z=newpos.z+math.random(-1,1)}
bomf(newpos,2 )
minetest.add_entity(newpos, pointed_thing.ref:get_luaentity().name)
end
return
end
local pos = pointed_thing.under
local pname = user:get_player_name()
if minetest.is_protected(pos, pname) then
minetest.record_protection_violation(pos, pname)
return
end
2016-08-16 18:57:33 +01:00
local breadth = 2 -- full square is 2*breadth+1 on side
local targetnode = minetest.get_node(pos).name
local userpos = user:getpos()
--[[
2016-08-16 18:57:33 +01:00
local relpos = 0
if (userpos.y - pos.y)^2 > 2 then -- if clearly above/below
relpos = (userpos.y - pos.y)/math.sqrt((userpos.y - pos.y)^2)
end
--]]
2016-08-16 18:57:33 +01:00
local airnodes = minetest.find_nodes_in_area(
{x = pos.x - breadth, y = pos.y, z = pos.z - breadth},
{x = pos.x + breadth, y = pos.y, z = pos.z + breadth},
2016-08-16 18:57:33 +01:00
{"air"}
)
bomf(pos,breadth*2)
2016-08-16 18:57:33 +01:00
for _,fpos in pairs(airnodes) do
minetest.swap_node(fpos, {name = targetnode })
end
return itemstack
end,
})
2016-08-18 19:35:08 +01:00
minetest.register_tool("vivarium:staff_boom", { -- this will be the floor staff
description = "Bomf Staff (remove nodes of pointed type)",
inventory_image = "water_staff.png^[colorize:black:140",
wield_image = "water_staff.png^[colorize:black:140",
range = 12,
2016-08-18 19:35:08 +01:00
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
if not canstaff(user) then return; end
2016-08-18 19:35:08 +01:00
if pointed_thing.type ~= "node" then
if pointed_thing.type == "object" then
bomf(pointed_thing.ref:getpos(),1 )
pointed_thing.ref:remove()
end
2016-08-18 19:35:08 +01:00
return
end
local pos = pointed_thing.under
local pname = user:get_player_name()
if minetest.is_protected(pos, pname) then
minetest.record_protection_violation(pos, pname)
return
end
local radius = 3
local targetnode = minetest.get_node(pos).name
local userpos = user:getpos()
local targetnodes = minetest.find_nodes_in_area(
{x = pos.x - radius, y = pos.y-radius, z = pos.z - radius},
{x = pos.x + radius, y = pos.y+radius, z = pos.z + radius},
{targetnode}
)
bomf(pos,radius)
2016-08-18 19:35:08 +01:00
for _,fpos in pairs(targetnodes) do
minetest.swap_node(fpos, {name = "air" })
end
return itemstack
end,
})
2016-08-16 18:57:33 +01:00
-- quick and dirty tool to repair carnage caused by NSSM ice mobs
minetest.register_tool("vivarium:staff_melt", {
description = "Staff of Melting (replace snow/ice with node under it, or above it)",
2016-08-18 18:35:39 +01:00
inventory_image = "water_staff.png^[colorize:blue:90",
wield_image = "water_staff.png^[colorize:blue:90",
2016-08-16 18:57:33 +01:00
range = 12,
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
if not canstaff(user) then return; end
2016-08-16 18:57:33 +01:00
if pointed_thing.type ~= "node" then
return
end
2016-08-16 18:57:33 +01:00
local pos = pointed_thing.under
local pname = user:get_player_name()
if minetest.is_protected(pos, pname) then
minetest.record_protection_violation(pos, pname)
return
end
local breadth = 2 -- full square is 2*breadth+1 on side
2016-08-18 18:35:39 +01:00
local frostarea = minetest.find_nodes_in_area(
2016-08-16 18:57:33 +01:00
{x = pos.x - breadth, y = pos.y, z = pos.z - breadth},
{x = pos.x + breadth, y = pos.y, z = pos.z + breadth},
{"default:ice","default:snowblock"}
)
bomf(pos,breadth*2)
2016-08-18 18:35:39 +01:00
for _,fpos in pairs(frostarea) do
2016-08-16 18:57:33 +01:00
local replname = minetest.get_node({x=fpos.x,y=fpos.y-1,z=fpos.z}).name
if replname == "default:ice" or replname == "default:snowblock" then
2016-08-18 18:35:39 +01:00
local newreplname = minetest.get_node({x=fpos.x,y=fpos.y+1,z=fpos.z}).name
if newreplname ~= "air" then -- don't dig down so much
-- TODO if replname == air, then get average node around that is not air, use that
replname = newreplname
end
2016-08-16 18:57:33 +01:00
end
2016-08-18 18:35:39 +01:00
local sealevel = 0 -- TODO get the custom setting for sealevel
if fpos.y > 0 and replname == "default:water_source" then -- don't bother with water above sea level
2016-08-16 18:57:33 +01:00
replname = "air"
end
minetest.swap_node(fpos, {name = replname })
end
return itemstack
end,
})
2016-08-16 18:57:33 +01:00
minetest.register_alias("vivarium:water_staff","vivarium:staff_melt")