1
0
mirror of https://repo.or.cz/minetest_returnmirror.git synced 2024-11-15 04:40:17 +01:00
minetest_returnmirror/init.lua

113 lines
3.6 KiB
Lua
Raw Normal View History

2015-02-13 21:43:24 +01:00
returnmirror = {}
2015-02-14 03:22:32 +01:00
returnmirror.cost_teleport = 200
2015-02-14 00:25:55 +01:00
returnmirror.cost_set = 20
2015-02-13 21:43:24 +01:00
2015-02-14 00:40:19 +01:00
if tonumber(minetest.setting_get("returnmirror_cost_teleport")) ~= nil then
returnmirror.cost_teleport = tonumber(minetest.setting_get("returnmirror_cost_teleport"))
end
if tonumber(minetest.setting_get("returnmirror_cost_set")) ~= nil then
returnmirror.cost_set = tonumber(minetest.setting_get("returnmirror_cost_set"))
end
2015-02-14 00:02:35 +01:00
if minetest.get_modpath("mana") ~= nil then
returnmirror.mana = true
else
returnmirror.mana = false
end
2015-02-14 00:25:55 +01:00
returnmirror.mana_check = function(player, cost)
local allowed
if returnmirror.mana then
if mana.subtract(player:get_player_name(), cost) then
allowed = true
else
allowed = false
end
else
allowed = true
end
return allowed
end
returnmirror.set_position_inactive = function(itemstack, user, pointed_thing)
if returnmirror.mana_check(user, returnmirror.cost_set) then
local pos = user:getpos()
local newitem = ItemStack("returnmirror:mirror_active")
newitem:set_metadata(minetest.pos_to_string(pos))
minetest.sound_play( {name="returnmirror_set", gain=1}, {pos=pos, max_hear_distance=12})
return newitem
end
end
returnmirror.set_position_active = function(itemstack, user, pointed_thing)
if returnmirror.mana_check(user, returnmirror.cost_set) then
local pos = user:getpos()
itemstack:set_metadata(minetest.pos_to_string(pos))
minetest.sound_play( {name="returnmirror_set", gain=1}, {pos=pos, max_hear_distance=12})
return itemstack
end
end
minetest.register_tool("returnmirror:mirror_inactive", {
description = "Mirror of Returning",
inventory_image = "returnmirror_mirror_inactive.png",
wield_image = "returnmirror_mirror_inactive.png",
tool_capabilities = {},
range = 0,
on_use = function() end,
on_place = returnmirror.set_position_inactive,
on_secondary_use = returnmirror.set_position_inactive,
})
minetest.register_tool("returnmirror:mirror_active", {
2015-02-13 21:43:24 +01:00
description = "Mirror of Returning",
stack_max = 1,
inventory_image = "returnmirror_mirror_active.png",
wield_image = "returnmirror_mirror_active.png",
2015-02-13 21:43:24 +01:00
tool_capabilities = {},
range = 0,
2015-02-13 21:43:24 +01:00
on_use = function(itemstack, user, pointed_thing)
2015-02-13 23:21:25 +01:00
local dest_string = itemstack:get_metadata()
local dest = minetest.string_to_pos(dest_string)
if dest ~= nil then
2015-02-14 00:25:55 +01:00
if returnmirror.mana_check(user, returnmirror.cost_teleport) then
2015-02-13 23:21:25 +01:00
local src = user:getpos()
minetest.sound_play( {name="returnmirror_teleport", gain=1}, {pos=src, max_hear_distance=30})
2015-02-13 23:53:53 +01:00
minetest.add_particlespawner({
amount = 50,
time = 0.1,
minpos = {x=src.x-0.4, y=src.y+0.25, z=src.z-0.4},
maxpos = {x=src.x+0.4, y=src.y+0.75, z=src.z+0.4},
minvel = {x=-0.2, y=-0.2, z=-0.2},
maxvel = {x=0.2, y=0.2, z=0.2},
minexptime=3,
maxexptime=4.5,
minsize=1,
maxsize=1.25,
texture = "returnmirror_particle_departure.png",
})
2015-02-13 23:21:25 +01:00
user:setpos(dest)
minetest.sound_play( {name="returnmirror_teleport", gain=1}, {pos=dest, max_hear_distance=30})
2015-02-13 23:53:53 +01:00
minetest.add_particlespawner({
amount = 100,
time = 0.1,
minpos = {x=dest.x-0.4, y=dest.y+0.25, z=dest.z-0.4},
maxpos = {x=dest.x+0.4, y=dest.y+0.75, z=dest.z+0.4},
minvel = {x=-0.4, y=-0.3, z=-0.4},
maxvel = {x=0.4, y=0.3, z=0.4},
minexptime=6,
maxexptime=12,
minsize=1,
maxsize=1.25,
texture = "returnmirror_particle_arrival.png",
})
2015-02-13 23:07:54 +01:00
end
2015-02-13 21:43:24 +01:00
end
end,
on_place = returnmirror.set_position_active,
on_secondary_use = returnmirror.set_position_active,
groups = { not_in_creative_inventory = 1 },
2015-02-13 21:43:24 +01:00
})
minetest.register_alias("returnmirror:mirror_inactive", "returnmirror:returnmirror")