-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodes.lua
76 lines (67 loc) · 2.85 KB
/
nodes.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
73
74
75
76
local update_script={}
update_script.timeline={}
minetest.register_on_dignode(function(pos,oldnode,digger)
if oldnode.name=="tenent_timetravel:reverser" then
return
end
local update_interval=tenent_timetravel.update_interval
rounded_time=update_interval*math.floor(tenent_timetravel.current_time/update_interval+0.5)
minetest.after(tenent_timetravel.update_interval, function()
if tenent_timetravel.time_rate>0 then
if not update_script.timeline[rounded_time] then
update_script.timeline[rounded_time]={{pos=pos,oldnode=oldnode,newnode="air"}}
else
table.insert(update_script.timeline[rounded_time],{pos=pos,oldnode=oldnode,newnode="air"})
end
else
if not update_script.timeline[rounded_time] then
update_script.timeline[rounded_time]={{pos=pos,oldnode="air",newnode=oldnode}}
else
table.insert(update_script.timeline[rounded_time],{pos=pos,oldnode="air",newnode=oldnode})
end
end
end)
end)
minetest.register_on_placenode(function(pos,newnode,placer,oldnode)
if newnode.name=="tenent_timetravel:reverser" then
return
end
local update_interval=tenent_timetravel.update_interval
rounded_time=update_interval*math.floor(tenent_timetravel.current_time/update_interval+0.5)
minetest.after(tenent_timetravel.update_interval, function()
if tenent_timetravel.time_rate>0 then
if not update_script.timeline[rounded_time] then
update_script.timeline[rounded_time]={{pos=pos,oldnode=oldnode,newnode=newnode}}
else
table.insert(update_script.timeline[rounded_time],{pos=pos,oldnode=oldnode,newnode=newnode})
end
else
if not update_script.timeline[rounded_time] then
update_script.timeline[rounded_time]={{pos=pos,oldnode=newnode,newnode=oldnode}}
else
table.insert(update_script.timeline[rounded_time],{pos=pos,oldnode=newnode,newnode=oldnode})
end
end
end)
end)
update_script.update=function(rounded_time)
local nodechanges=update_script.timeline[rounded_time]
if nodechanges then
if tenent_timetravel.time_rate>0 then
for _,nodechange in pairs(nodechanges) do
if nodechange.pos and nodechange.newnode and nodechange.newnode.name then
minetest.set_node(nodechange.pos,nodechange.newnode)
end
end
else
for _,nodechange in pairs(nodechanges) do
if nodechange.pos and nodechange.oldnode and nodechange.oldnode.name then
minetest.set_node(nodechange.pos,nodechange.oldnode)
end
end
end
end
end
update_script.reverse=function()
end
return update_script