2019-09-30 19:26:22 +02:00
|
|
|
--[[
|
|
|
|
MIT License
|
|
|
|
Copyright (c) 2017 Elijah Duffy
|
|
|
|
Copyright (c) 2019 Noctis Labs
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
|
|
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
|
|
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
|
|
portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
|
|
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
--]]
|
|
|
|
|
|
|
|
-- an_televator/init.lua
|
2017-05-16 03:36:12 +02:00
|
|
|
|
|
|
|
local delay = {}
|
|
|
|
local itemset
|
|
|
|
|
|
|
|
---
|
|
|
|
--- Functions
|
|
|
|
---
|
|
|
|
|
2019-09-30 19:26:22 +02:00
|
|
|
local function get_near_televators(pos, which)
|
|
|
|
for i = 1, 32 do
|
2017-05-17 01:20:54 +02:00
|
|
|
local cpos = vector.new(pos)
|
|
|
|
if which == "above" then
|
|
|
|
cpos.y = cpos.y + i
|
|
|
|
elseif which == "below" then
|
|
|
|
cpos.y = cpos.y - i
|
|
|
|
end
|
|
|
|
local name = minetest.get_node(cpos).name
|
2019-09-30 19:26:22 +02:00
|
|
|
if (which == "above" and name == "an_televator:televator")
|
|
|
|
or (which == "below" and i ~= 1 and name == "an_televator:televator") then
|
2017-05-17 01:20:54 +02:00
|
|
|
cpos.y = cpos.y + 1
|
|
|
|
return cpos
|
|
|
|
end
|
|
|
|
end
|
2017-05-16 03:36:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function is_safe(pos)
|
2017-05-17 01:20:54 +02:00
|
|
|
for i = 0, 1 do
|
|
|
|
local tpos = vector.new(pos)
|
|
|
|
tpos.y = tpos.y + i
|
|
|
|
if minetest.get_node(tpos).name ~= "air" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
2017-05-16 03:36:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
---
|
|
|
|
--- Registrations
|
|
|
|
---
|
|
|
|
|
2019-09-30 19:26:22 +02:00
|
|
|
minetest.register_node("an_televator:televator", {
|
2019-10-06 17:35:38 +02:00
|
|
|
description = "Televator",
|
2019-09-30 19:26:22 +02:00
|
|
|
tiles = {"televator_televator.png"},
|
2017-05-17 01:20:54 +02:00
|
|
|
groups = {cracky = 2, disable_jump = 1},
|
|
|
|
after_place_node = function(pos)
|
2019-09-30 19:26:22 +02:00
|
|
|
minetest.get_meta(pos):set_string("infotext", "Televator")
|
2017-05-17 01:20:54 +02:00
|
|
|
end,
|
2017-05-16 03:36:12 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_globalstep(function(dtime)
|
2017-05-17 01:20:54 +02:00
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
|
|
|
local pos = player:get_pos()
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if not delay[name] then
|
|
|
|
delay[name] = 0.5
|
|
|
|
else
|
|
|
|
delay[name] = delay[name] + dtime
|
|
|
|
end
|
|
|
|
if not delay[name] or delay[name] > 0.5 then
|
2019-10-01 05:38:54 +02:00
|
|
|
if minetest.get_node({x = pos.x, y = pos.y - 0.5, z = pos.z}).name == "an_televator:televator" then
|
2017-05-17 01:20:54 +02:00
|
|
|
local where
|
|
|
|
local controls = player:get_player_control()
|
|
|
|
if controls.jump then
|
|
|
|
where = "above"
|
|
|
|
elseif controls.sneak then
|
|
|
|
where = "below"
|
|
|
|
else return end
|
2019-09-30 19:26:22 +02:00
|
|
|
local epos = get_near_televators(pos, where)
|
2017-05-17 01:20:54 +02:00
|
|
|
if epos and is_safe(epos) then
|
2019-10-01 22:05:19 +02:00
|
|
|
player:set_pos(epos)
|
2017-05-17 01:20:54 +02:00
|
|
|
minetest.sound_play("televator_whoosh", {
|
|
|
|
gain = 0.75,
|
|
|
|
pos = epos,
|
|
|
|
max_hear_distance = 5,
|
|
|
|
})
|
|
|
|
else
|
2019-09-30 19:26:22 +02:00
|
|
|
minetest.sound_play("televator_error", {
|
|
|
|
gain = 0.75,
|
|
|
|
pos = epos,
|
|
|
|
max_hear_distance = 5,
|
|
|
|
})
|
2017-05-17 01:20:54 +02:00
|
|
|
end
|
2019-10-01 22:05:19 +02:00
|
|
|
delay[name] = 0
|
2017-05-17 01:20:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-16 03:36:12 +02:00
|
|
|
end)
|