init.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. local modname = minetest.get_current_modname()
  2. local function on_place(itemstack, placer, pointed_thing)
  3. if not placer then
  4. return
  5. end
  6. local ctrl = placer:get_player_control()
  7. local param2
  8. if ctrl.aux1 then
  9. --place just like pointed slab
  10. minetest.chat_send_all("a")
  11. local pointed = minetest.get_node(pointed_thing.under)
  12. if minetest.get_item_group(pointed.name, "slab") > 0 then
  13. param2 = pointed.param2
  14. end
  15. end
  16. return minetest.item_place_node(itemstack, placer, pointed_thing, param2)
  17. end
  18. local slabs = {}
  19. _G[modname] = slabs
  20. --registeres a slab node for an aleready registered node
  21. function slabs.slabify(S, name, def, description)
  22. name = name .. "_slab"
  23. def = table.copy(def)
  24. def.description = description
  25. def.drawtype = "nodebox"
  26. def.paramtype = "light"
  27. def.paramtype2 = "wallmounted"
  28. def.node_box = {
  29. type = "wallmounted",
  30. wall_bottom = {-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
  31. wall_top = {-0.5, 0, -0.5, 0.5, 0.5, 0.5},
  32. wall_side = {-0.5, -0.5, -0.5, 0, 0.5, 0.5},
  33. }
  34. def.groups["slab"] = 1
  35. def.on_place = on_place
  36. minetest.register_node(name, def)
  37. end
  38. function slabs.register_slabs(node_list)
  39. for name, description in pairs(node_list)
  40. do
  41. local def = minetest.registered_nodes[name]
  42. slabs.slabify(S, name, def, description)
  43. end
  44. end