/games/devtest/mods/testnodes/

c8b (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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
--clipboard = {trainlen = number, [n] = {type = string, flipped = bool, properties = {}, bike_painter_livery = string, custom_info = <optional custom data>}

-- Yaw is in radians. There are 2pi rad in a circle. North is the 0 point and the angle increases anticlockwise.
-- 4.712389 = 1.5pi; sin(1.5pi) = -1
-- 7.853981 = 2.5pi; sin(2.5pi) = 1

-- Get current translator
local S = advtrains.translate

minetest.register_tool("advtrains:copytool", {
	description = S("Train copy/paste tool\n\nLeft-click: copy train\nRight-click: paste train"),
	inventory_image = "advtrains_copytool.png",
	wield_image = "advtrains_copytool.png",
	stack_max = 1,
	-- Paste: Take the clipboard and the player yaw, and attempt to place a new train in the world.
	-- The front of the train is used as the start of the new train and it proceeds backwards from
	-- the direction of travel.
	on_place = function(itemstack, placer, pointed_thing)
			if ((not pointed_thing.type == "node") or (not placer.get_player_name)) then
				return
			end
			local pname = placer:get_player_name()

			local node=minetest.get_node_or_nil(pointed_thing.under)
			if not node then atprint("[advtrains]Ignore at placer position") return itemstack end
			local nodename=node.name
			if(not advtrains.is_track(nodename)) then
				atprint("no track here, not placing.")
				return itemstack
			end
			if not minetest.check_player_privs(placer, {train_operator = true }) then
				minetest.chat_send_player(pname, S("You do not have the @1 privilege.", "train_operator"))
				return itemstack
			end
			if not minetest.check_player_privs(placer, {train_admin = true }) and minetest.is_protected(pointed_thing.under, placer:get_player_name()) then
				return itemstack
			end
			local tconns=advtrains.get_track_connections(node.name, node.param2)
			local yaw = placer:get_look_horizontal()
			local plconnid = advtrains.yawToClosestConn(yaw, tconns)

			local prevpos = advtrains.get_adjacent_rail(pointed_thing.under, tconns, plconnid, {default=true})
			if not prevpos then
				minetest.chat_send_player(pname, S("The track you are trying to place the wagon on is not long enough."))
				return