blob: 5215c1af1b19a144e41c38362e28c037cc6669cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
-- Try to teleport player away from any closed (on) elevator node.
elevator.teleport_player_from_elevator = function(player)
local function solid(pos)
if not minetest.registered_nodes[minetest.get_node(pos).name] then
return true
end
return minetest.registered_nodes[minetest.get_node(pos).name].walkable
end
local pos = vector.round(player:get_pos())
local node = minetest.get_node(pos)
-- elevator_off is like a shaft, so the player would already be falling.
if node.name == "elevator:elevator_on" then
local front = vector.subtract(pos, minetest.facedir_to_dir(node.param2))
local front_above = vector.add(front, {x=0, y=1, z=0})
-- local front_below = vector.subtract(front, {x=0, y=1, z=0})
-- If the front isn't solid, it's ok to teleport the player.
if not solid(front) and not solid(front_above) then
player:set_pos(front)
end
end
end
elevator.phash = function(pos)
return minetest.pos_to_string(pos)
end
elevator.punhash = function(pos)
return minetest.string_to_pos(pos)
end
-- Helper function to read unloaded nodes.
elevator.get_node = function(pos)
local node = minetest.get_node_or_nil(pos)
if node then return node end
local _,_ = VoxelManip():read_from_map(pos, pos)
return minetest.get_node_or_nil(pos)
end
|