@@ -34,55 +34,30 @@ minetest.register_node("mapserver:train", {
34
34
groups = {cracky = 3 ,oddly_breakable_by_hand = 3 },
35
35
sounds = moditems .sound_glass (),
36
36
can_dig = mapserver .can_interact ,
37
- after_place_node = mapserver .after_place_node ,
38
37
39
- on_construct = function (pos )
38
+ after_place_node = function (pos , placer , itemstack , pointed_thing )
40
39
local meta = minetest .get_meta (pos )
41
40
42
- local find_nearest_player = function (block_pos , radius )
43
- -- adapted from https://forum.minetest.net/viewtopic.php?t=23319
44
-
45
- local closest_d = radius + 1
46
- local closest_name
47
-
48
- for i , obj in ipairs (minetest .get_objects_inside_radius (block_pos , radius )) do
49
- -- 0.4.x compatibility:
50
- -- if obj:get_player_name() ~= "" then
51
-
52
- -- 5.0.0+ method:
53
- if minetest .is_player (obj ) then
54
- local distance = vector .distance (obj :get_pos (), block_pos )
55
- if distance < closest_d then
56
- closest_d = distance
57
- closest_name = obj :get_player_name ()
58
- end
59
- end
60
- end
61
-
62
- -- if 'closest_name' is nil, there's no player inside that radius
63
- return closest_name
64
- end
65
-
66
- -- 10 should be the max possible interaction distance
67
- local name = find_nearest_player (pos , 10 )
68
-
69
41
local last_index = 0
70
42
local last_line = " "
71
43
local last_color = " "
72
44
73
- if name ~= nil then
74
- name = string.lower (name )
75
- if last_set_by [name ] ~= nil then
76
- last_index = last_set_by [name ].index + 5
77
- last_line = last_set_by [name ].line
78
- last_color = last_set_by [name ].color
79
- else
80
- last_set_by [name ] = {}
81
- end
45
+ if minetest .is_player (placer ) then
46
+ local name = placer :get_player_name ()
47
+ if name ~= nil then
48
+ name = string.lower (name )
49
+ if last_set_by [name ] ~= nil then
50
+ last_index = last_set_by [name ].index + 5
51
+ last_line = last_set_by [name ].line
52
+ last_color = last_set_by [name ].color
53
+ else
54
+ last_set_by [name ] = {}
55
+ end
82
56
83
- last_set_by [name ].index = last_index
84
- last_set_by [name ].line = last_line
85
- last_set_by [name ].color = last_color
57
+ last_set_by [name ].index = last_index
58
+ last_set_by [name ].line = last_line
59
+ last_set_by [name ].color = last_color
60
+ end
86
61
end
87
62
88
63
meta :set_string (" station" , " " )
@@ -91,6 +66,9 @@ minetest.register_node("mapserver:train", {
91
66
meta :set_string (" color" , last_color )
92
67
93
68
update_formspec (meta )
69
+
70
+
71
+ return mapserver .after_place_node (pos , placer , itemstack , pointed_thing )
94
72
end ,
95
73
96
74
on_receive_fields = function (pos , formname , fields , sender )
0 commit comments