utils.lua 760 B

12345678910111213141516171819202122232425262728
  1. function decoblocks.place_and_rotate(itemstack, placer, pointed_thing)
  2. local p0 = pointed_thing.under
  3. local p1 = pointed_thing.above
  4. local param2 = 0
  5. if placer then
  6. local placer_pos = placer:get_pos()
  7. if placer_pos then
  8. param2 = minetest.dir_to_facedir(vector.subtract(p1, placer_pos))
  9. end
  10. local finepos = minetest.pointed_thing_to_face_pos(placer, pointed_thing)
  11. local fpos = finepos.y % 1
  12. if p0.y - 1 == p1.y or (fpos > 0 and fpos < 0.5)
  13. or (fpos < -0.5 and fpos > -0.999999999) then
  14. param2 = param2 + 20
  15. if param2 == 21 then
  16. param2 = 23
  17. elseif param2 == 23 then
  18. param2 = 21
  19. end
  20. end
  21. end
  22. return minetest.item_place(itemstack, placer, pointed_thing, param2)
  23. end