@@ -264,78 +264,86 @@ end
264
264
---- ----------------------------------------------------------------------------
265
265
266
266
if minetest then
267
- local dirs1 = { 9 , 18 , 7 , 12 }
268
- local dirs2 = { 20 , 23 , 22 , 21 }
267
+ local dirs1 = {9 , 18 , 7 , 12 }
268
+ local dirs2 = {20 , 23 , 22 , 21 }
269
269
270
- function minetest .rotate_and_place (itemstack , placer , pointed_thing , infinitestacks , orient_flags )
270
+ function minetest .rotate_and_place (itemstack , placer , pointed_thing ,
271
+ infinitestacks , orient_flags )
271
272
orient_flags = orient_flags or {}
272
273
273
- local node = minetest .get_node (pointed_thing .under )
274
- if not minetest . registered_nodes [ node . name ]
275
- or not minetest . registered_nodes [ node . name ]. on_rightclick then
276
-
277
- local above = pointed_thing . above
278
- local under = pointed_thing . under
279
- local pitch = placer : get_look_pitch ()
280
- local pname = minetest . get_node ( under ). name
281
- local node = minetest . get_node ( above )
282
- local fdir = minetest . dir_to_facedir ( placer : get_look_dir ())
283
- local wield_name = itemstack : get_name ()
284
- local reg_node = minetest .registered_nodes [ pname ]
285
-
286
- if not reg_node or not reg_node . on_rightclick then
287
-
288
- local iswall = ( above . x ~= under . x ) or ( above . z ~= under . z )
289
- local isceiling = (above .x == under .x ) and ( above . z == under . z )
290
- and (pitch > 0 )
291
- local pos1 = above
292
-
293
- if reg_node and reg_node . buildable_to then
294
- pos1 = under
295
- iswall = false
296
- end
274
+ local unode = minetest .get_node_or_nil (pointed_thing .under )
275
+ if not unode then
276
+ return
277
+ end
278
+ local undef = minetest . registered_nodes [ unode . name ]
279
+ if undef and undef . on_rightclick then
280
+ undef . on_rightclick ( pointed_thing . under , node , placer ,
281
+ itemstack )
282
+ return
283
+ end
284
+ local pitch = placer : get_look_pitch ()
285
+ local fdir = minetest .dir_to_facedir ( placer : get_look_dir ())
286
+ local wield_name = itemstack : get_name ()
287
+
288
+ local above = pointed_thing . above
289
+ local under = pointed_thing . under
290
+ local iswall = (above .y == under .y )
291
+ local isceiling = not iswall and (above . y < under . y )
292
+ local anode = minetest . get_node_or_nil ( above )
293
+ if not anode then
294
+ return
295
+ end
296
+ local pos = pointed_thing . above
297
+ local node = anode
297
298
298
- reg_node = minetest .registered_nodes [minetest .get_node (pos1 ).name ]
299
- if not reg_node or not reg_node .buildable_to then
300
- return
301
- end
299
+ if undef and undef .buildable_to then
300
+ pos = pointed_thing .under
301
+ node = unode
302
+ iswall = false
303
+ end
302
304
303
- if orient_flags .force_floor then
304
- iswall = false
305
- isceiling = false
306
- elseif orient_flags .force_ceiling then
307
- iswall = false
308
- isceiling = true
309
- elseif orient_flags .force_wall then
310
- iswall = true
311
- isceiling = false
312
- elseif orient_flags .invert_wall then
313
- iswall = not iswall
314
- end
305
+ local ndef = minetest .registered_nodes [node .name ]
306
+ if not ndef or not ndef .buildable_to then
307
+ return
308
+ end
315
309
316
- if iswall then
317
- minetest .add_node (pos1 , {name = wield_name , param2 = dirs1 [fdir + 1 ] })
318
- elseif isceiling then
319
- if orient_flags .force_facedir then
320
- minetest .add_node (pos1 , {name = wield_name , param2 = 20 })
321
- else
322
- minetest .add_node (pos1 , {name = wield_name , param2 = dirs2 [fdir + 1 ] })
323
- end
324
- else -- place right side up
325
- if orient_flags .force_facedir then
326
- minetest .add_node (pos1 , {name = wield_name , param2 = 0 })
327
- else
328
- minetest .add_node (pos1 , {name = wield_name , param2 = fdir })
329
- end
330
- end
310
+ if orient_flags .force_floor then
311
+ iswall = false
312
+ isceiling = false
313
+ elseif orient_flags .force_ceiling then
314
+ iswall = false
315
+ isceiling = true
316
+ elseif orient_flags .force_wall then
317
+ iswall = true
318
+ isceiling = false
319
+ elseif orient_flags .invert_wall then
320
+ iswall = not iswall
321
+ end
331
322
332
- if not infinitestacks then
333
- itemstack :take_item ()
334
- return itemstack
335
- end
323
+ if iswall then
324
+ minetest .set_node (pos , {name = wield_name ,
325
+ param2 = dirs1 [fdir + 1 ]})
326
+ elseif isceiling then
327
+ if orient_flags .force_facedir then
328
+ minetest .set_node (pos , {name = wield_name ,
329
+ param2 = 20 })
330
+ else
331
+ minetest .set_node (pos , {name = wield_name ,
332
+ param2 = dirs2 [fdir + 1 ]})
336
333
end
337
- else
338
- minetest .registered_nodes [node .name ].on_rightclick (pointed_thing .under , node , placer , itemstack )
334
+ else -- place right side up
335
+ if orient_flags .force_facedir then
336
+ minetest .set_node (pos , {name = wield_name ,
337
+ param2 = 0 })
338
+ else
339
+ minetest .set_node (pos , {name = wield_name ,
340
+ param2 = fdir })
341
+ end
342
+ end
343
+
344
+ if not infinitestacks then
345
+ itemstack :take_item ()
346
+ return itemstack
339
347
end
340
348
end
341
349
@@ -348,8 +356,8 @@ if minetest then
348
356
349
357
minetest .rotate_node = function (itemstack , placer , pointed_thing )
350
358
minetest .rotate_and_place (itemstack , placer , pointed_thing ,
351
- minetest .setting_getbool (" creative_mode" ),
352
- {invert_wall = placer :get_player_control ().sneak })
359
+ minetest .setting_getbool (" creative_mode" ),
360
+ {invert_wall = placer :get_player_control ().sneak })
353
361
return itemstack
354
362
end
355
363
end
0 commit comments