mirror of
https://github.com/NoctisLabs/an_televator.git
synced 2024-11-22 13:13:43 +01:00
Fix indentation
This commit is contained in:
parent
9af26c9596
commit
c2dbf41d84
164
init.lua
164
init.lua
@ -4,12 +4,12 @@ local delay = {}
|
|||||||
|
|
||||||
local itemset
|
local itemset
|
||||||
if minetest.get_modpath("default") then
|
if minetest.get_modpath("default") then
|
||||||
itemset = {
|
itemset = {
|
||||||
steel = "default:steel_ingot",
|
steel = "default:steel_ingot",
|
||||||
gold = "default:gold_ingot",
|
gold = "default:gold_ingot",
|
||||||
copper = "default:copper_ingot",
|
copper = "default:copper_ingot",
|
||||||
glass = "default:glass",
|
glass = "default:glass",
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -18,38 +18,38 @@ end
|
|||||||
|
|
||||||
-- [function] Get near elevators
|
-- [function] Get near elevators
|
||||||
local function get_near_elevators(pos, which)
|
local function get_near_elevators(pos, which)
|
||||||
for i = 1, 16 do
|
for i = 1, 16 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 == "televator:elevator")
|
if (which == "above" and name == "televator:elevator")
|
||||||
or (which == "below" and i ~= 1 and name == "televator:elevator") then
|
or (which == "below" and i ~= 1 and name == "televator:elevator") then
|
||||||
cpos.y = cpos.y + 1
|
cpos.y = cpos.y + 1
|
||||||
return cpos
|
return cpos
|
||||||
elseif name ~= "air" and name ~= "televator:elevator" then
|
elseif name ~= "air" and name ~= "televator:elevator" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- [function] Elevator safe
|
-- [function] Elevator 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
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -58,69 +58,69 @@ end
|
|||||||
|
|
||||||
-- [register] Elevator node
|
-- [register] Elevator node
|
||||||
minetest.register_node("televator:elevator", {
|
minetest.register_node("televator:elevator", {
|
||||||
description = "Elevator\n"..
|
description = "Elevator\n"..
|
||||||
minetest.colorize("grey","Can be placed up to 16 nodes apart\n"
|
minetest.colorize("grey","Can be placed up to 16 nodes apart\n"
|
||||||
.."Jump to go up, sneak to go down"),
|
.."Jump to go up, sneak to go down"),
|
||||||
tiles = {"televator_elevator.png"},
|
tiles = {"televator_elevator.png"},
|
||||||
groups = {cracky = 2, disable_jump = 1},
|
groups = {cracky = 2, disable_jump = 1},
|
||||||
after_place_node = function(pos)
|
after_place_node = function(pos)
|
||||||
-- Set infotext
|
-- Set infotext
|
||||||
minetest.get_meta(pos):set_string("infotext", "Elevator")
|
minetest.get_meta(pos):set_string("infotext", "Elevator")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- [register] Recipe
|
-- [register] Recipe
|
||||||
if itemset then
|
if itemset then
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "televator:elevator 2",
|
output = "televator:elevator 2",
|
||||||
recipe = {
|
recipe = {
|
||||||
{itemset.steel, itemset.glass, itemset.steel},
|
{itemset.steel, itemset.glass, itemset.steel},
|
||||||
{itemset.steel, itemset.gold, itemset.steel},
|
{itemset.steel, itemset.gold, itemset.steel},
|
||||||
{itemset.steel, itemset.copper, itemset.steel,}
|
{itemset.steel, itemset.copper, itemset.steel,}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- [register] Globalstep
|
-- [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 - 1, z = pos.z}).name == "televator:elevator" then
|
if minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name == "televator:elevator" then
|
||||||
local where
|
local where
|
||||||
local controls = player:get_player_control()
|
local controls = player:get_player_control()
|
||||||
if controls.jump then
|
if controls.jump then
|
||||||
where = "above"
|
where = "above"
|
||||||
elseif controls.sneak then
|
elseif controls.sneak then
|
||||||
where = "below"
|
where = "below"
|
||||||
else return end
|
else return end
|
||||||
|
|
||||||
local epos = get_near_elevators(pos, where)
|
local epos = get_near_elevators(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) -- Update player position
|
||||||
|
|
||||||
-- Play sound
|
-- Play sound
|
||||||
minetest.sound_play("televator_whoosh", {
|
minetest.sound_play("televator_whoosh", {
|
||||||
gain = 0.75,
|
gain = 0.75,
|
||||||
pos = epos,
|
pos = epos,
|
||||||
max_hear_distance = 5,
|
max_hear_distance = 5,
|
||||||
})
|
})
|
||||||
elseif epos then
|
elseif epos then
|
||||||
minetest.chat_send_player(name, "Elevator blocked by obstruction")
|
minetest.chat_send_player(name, "Elevator blocked by obstruction")
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, "Could not find elevator")
|
minetest.chat_send_player(name, "Could not find elevator")
|
||||||
end
|
end
|
||||||
|
|
||||||
delay[name] = 0 -- Restart delay
|
delay[name] = 0 -- Restart delay
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user