Add optional Mana support
This commit is contained in:
parent
86a3f1406a
commit
0e15ae99cd
@ -1,3 +1,4 @@
|
||||
intllib?
|
||||
technic?
|
||||
default?
|
||||
mana?
|
||||
|
23
init.lua
23
init.lua
@ -6,6 +6,15 @@ else
|
||||
end
|
||||
|
||||
teletool = {}
|
||||
teletool.settings = {}
|
||||
|
||||
--[[ Tool Mode:
|
||||
- "technic": Use Technic mod, each shot costs energy, tool must be recharged
|
||||
- "mana": Each shot depletes the player's mana reserves
|
||||
- "infinite": There are no limits on using this tool.
|
||||
- "auto" (default): Based on mod availabilty, it will try these modes in this order: "technic", "mana", "infinity"
|
||||
]]
|
||||
teletool.settings.toolmode = "auto"
|
||||
|
||||
function teletool.teleport(player, pointed_thing)
|
||||
local pos = pointed_thing.above
|
||||
@ -61,7 +70,8 @@ minetest.register_tool("teletool:teletool", {
|
||||
local failure = false
|
||||
if(pointed_thing.type == "node") then
|
||||
local has_technic = minetest.get_modpath("technic") ~= nil
|
||||
if(has_technic) then
|
||||
local has_mana = minetest.get_modpath("mana") ~= nil
|
||||
if(has_technic and (teletool.settings.toolmode == "auto" or teletool.settings.toolmode=="technic")) then
|
||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||
if not meta or not meta.charge then return end
|
||||
if meta.charge >= 1000 then
|
||||
@ -72,8 +82,17 @@ minetest.register_tool("teletool:teletool", {
|
||||
else
|
||||
failure = true
|
||||
end
|
||||
else
|
||||
elseif(has_mana and (teletool.settings.toolmode == "auto" or teletool.settings.toolmode=="mana")) then
|
||||
if(mana.subtract(user:get_player_name(), 20)) then
|
||||
teletool.teleport(user, pointed_thing)
|
||||
else
|
||||
failure = true
|
||||
end
|
||||
elseif(teletool.settings.toolmode == "auto" or teletool.settings.toolmode=="infinite") then
|
||||
teletool.teleport(user, pointed_thing)
|
||||
else
|
||||
minetest.log("error", "[teletool] Incorrect tool mode set!")
|
||||
failure = true
|
||||
end
|
||||
else
|
||||
failure = true
|
||||
|
Loading…
x
Reference in New Issue
Block a user