Update init.lua

This commit is contained in:
NoctisLabs 2019-10-01 13:05:19 -07:00 committed by GitHub
parent 5b4fe97bc0
commit 4748b4f3d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,7 +21,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- an_televator/init.lua -- an_televator/init.lua
local delay = {} local delay = {}
local itemset local itemset
if minetest.get_modpath("default") then if minetest.get_modpath("default") then
itemset = { itemset = {
@ -36,17 +35,14 @@ end
--- Functions --- Functions
--- ---
-- [function] Get near televators
local function get_near_televators(pos, which) local function get_near_televators(pos, which)
for i = 1, 32 do for i = 1, 32 do
local cpos = vector.new(pos) local cpos = vector.new(pos)
if which == "above" then if which == "above" then
cpos.y = cpos.y + i cpos.y = cpos.y + i
elseif which == "below" then elseif which == "below" then
cpos.y = cpos.y - i cpos.y = cpos.y - i
end end
local name = minetest.get_node(cpos).name local name = minetest.get_node(cpos).name
if (which == "above" and name == "an_televator:televator") if (which == "above" and name == "an_televator:televator")
or (which == "below" and i ~= 1 and name == "an_televator:televator") then or (which == "below" and i ~= 1 and name == "an_televator:televator") then
@ -56,17 +52,14 @@ local function get_near_televators(pos, which)
end end
end end
-- [function] Televator safe
local function is_safe(pos) local function is_safe(pos)
for i = 0, 1 do for i = 0, 1 do
local tpos = vector.new(pos) local tpos = vector.new(pos)
tpos.y = tpos.y + i tpos.y = tpos.y + i
if minetest.get_node(tpos).name ~= "air" then if minetest.get_node(tpos).name ~= "air" then
return return
end end
end end
return true return true
end end
@ -74,7 +67,6 @@ end
--- Registrations --- Registrations
--- ---
-- [register] Televator node
minetest.register_node("an_televator:televator", { minetest.register_node("an_televator:televator", {
description = "Televator\n".. description = "Televator\n"..
minetest.colorize("grey","Place up to 32 nodes apart.\n" minetest.colorize("grey","Place up to 32 nodes apart.\n"
@ -86,7 +78,6 @@ minetest.register_node("an_televator:televator", {
end, end,
}) })
-- [register] Recipe
if itemset then if itemset then
minetest.register_craft({ minetest.register_craft({
output = "an_televator:televator", output = "an_televator:televator",
@ -98,18 +89,15 @@ if itemset then
}) })
end end
-- [register] Globalstep
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do for _, player in pairs(minetest.get_connected_players()) do
local pos = player:get_pos() local pos = player:get_pos()
local name = player:get_player_name() local name = player:get_player_name()
if not delay[name] then if not delay[name] then
delay[name] = 0.5 delay[name] = 0.5
else else
delay[name] = delay[name] + dtime delay[name] = delay[name] + dtime
end end
if not delay[name] or delay[name] > 0.5 then if not delay[name] or delay[name] > 0.5 then
if minetest.get_node({x = pos.x, y = pos.y - 0.5, z = pos.z}).name == "an_televator:televator" then if minetest.get_node({x = pos.x, y = pos.y - 0.5, z = pos.z}).name == "an_televator:televator" then
local where local where
@ -119,10 +107,9 @@ minetest.register_globalstep(function(dtime)
elseif controls.sneak then elseif controls.sneak then
where = "below" where = "below"
else return end else return end
local epos = get_near_televators(pos, where) local epos = get_near_televators(pos, where)
if epos and is_safe(epos) then if epos and is_safe(epos) then
player:set_pos(epos) -- Update player position player:set_pos(epos)
minetest.sound_play("televator_whoosh", { minetest.sound_play("televator_whoosh", {
gain = 0.75, gain = 0.75,
pos = epos, pos = epos,
@ -135,8 +122,7 @@ minetest.register_globalstep(function(dtime)
max_hear_distance = 5, max_hear_distance = 5,
}) })
end end
delay[name] = 0
delay[name] = 0 -- Restart delay
end end
end end
end end