minetest_teletool/init.lua

69 lines
2.2 KiB
Lua
Raw Normal View History

2014-07-14 07:32:20 -07:00
if (minetest.get_modpath("intllib")) then
dofile(minetest.get_modpath("intllib").."/intllib.lua")
S = intllib.Getter(minetest.get_current_modname())
else
S = function ( s ) return s end
end
2014-10-12 14:23:01 -07:00
teletool = {}
function teletool.teleport(player, pointed_thing)
local pos = pointed_thing.above
local over1 = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
local over2 = minetest.get_node({x=pos.x,y=pos.y+2,z=pos.z})
local src = player:getpos()
local dest = {x=pos.x, y=math.ceil(pos.y)-0.5, z=pos.z}
minetest.sound_play( {name="teletool_teleport1", gain=1}, {pos=src, max_hear_distance=12})
player:setpos(dest)
minetest.after(0.5, function(dest) minetest.sound_play( {name="teletool_teleport2", gain=1}, {pos=dest, max_hear_distance=12}) end, dest)
end
if(minetest.get_modpath("technic") ~= nil) then
technic.register_power_tool("teletool:teletool", 50000)
teletool.on_refill = technic.refill_RE_charge
else
teletool.on_refill = nil
end
2014-07-14 07:32:20 -07:00
minetest.register_tool("teletool:teletool", {
description = S("point teleporter"),
range = 20.0,
tool_capabilities = {},
wield_image = "teletool_teletool.png",
inventory_image = "teletool_teletool.png",
on_use = function(itemstack, user, pointed_thing)
if(pointed_thing.type == "node") then
2014-10-12 14:23:01 -07:00
local has_technic = minetest.get_modpath("technic") ~= nil
if(has_technic) then
local meta = minetest.deserialize(itemstack:get_metadata())
if not meta or not meta.charge then return end
if meta.charge >= 1000 then
meta.charge = meta.charge - 1000
teletool.teleport(user, pointed_thing)
technic.set_RE_wear(itemstack, meta.charge, 50000)
itemstack:set_metadata(minetest.serialize(meta))
end
else
teletool.teleport(user, pointed_thing)
end
return itemstack
2014-07-14 07:32:20 -07:00
end
end,
-- Technic data
wear_represents = "technic_RE_charge",
2014-10-12 14:23:01 -07:00
on_refill = teletool.on_refill,
2014-07-14 07:32:20 -07:00
})
if(minetest.get_modpath("default") ~= nil and minetest.get_modpath("technic") ~= nil) then
minetest.register_craft({
output = "teletool:teletool",
recipe = {
{"", "default:mese_crystal", ""},
{"technic:stainless_steel_ingot", "technic:red_energy_crystal", "technic:stainless_steel_ingot"},
{"technic:stainless_steel_ingot", "technic:battery", "technic:stainless_steel_ingot"}
}
})
end