-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
72 lines (59 loc) · 1.57 KB
/
init.lua
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
local M = {}
gnode_augment = M
M.players = {}
local callbacks = {}
function M.register_callback(f)
table.insert(callbacks, f)
return #callbacks
end
function M.remove_callback(idx)
table.remove(callbacks, idx)
end
local step_time = tonumber(minetest.settings:get("gnode_augment.step_time")) or 0.3
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < step_time then
return
end
timer = 0
for _,player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local data = M.players[name]
if data then
local prop = player:get_properties()
local pos = player:get_pos()
local stand_pos = vector.round(vector.add(pos, vector.new(0, -0.1, 0)))
data.nodes = {
top = minetest.get_node(vector.add(pos, vector.new(0, prop.eye_height, 0))),
bottom = minetest.get_node(vector.add(pos, vector.new(0, prop.stepheight / 2, 0))),
stand = minetest.get_node(stand_pos),
stand_pos = stand_pos,
}
local stand_def = minetest.registered_nodes[data.nodes.stand.name]
if stand_def and stand_def._on_standing then
stand_def._on_standing(stand_pos, data.nodes.stand, player)
end
for _,f in ipairs(callbacks) do
f(player, data)
end
end
end
end)
local ignore = {
name = "ignore",
param1 = 0,
param2 = 0,
}
minetest.register_on_joinplayer(function(player)
M.players[player:get_player_name()] = {
nodes = {
top = ignore,
bottom = ignore,
stand = ignore,
},
}
end)
minetest.register_on_leaveplayer(function(player)
M.players[player:get_player_name()] = nil
end)