init.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. computer = {}
  2. computer.register = function (name, def)
  3. if (name:sub(1, 1) == ":") then name = name:sub(2) end
  4. local modname, basename = name:match("^([^:]+):(.*)")
  5. local TEXPFX = modname.."_"..basename.."_"
  6. local ONSTATE = modname..":"..basename
  7. local OFFSTATE = modname..":"..basename.."_off"
  8. local cdef = table.copy(def)
  9. minetest.register_node(ONSTATE, {
  10. drawtype = "nodebox",
  11. paramtype = "light",
  12. paramtype2 = "facedir",
  13. description = cdef.description,
  14. inventory_image = cdef.inventory_image,
  15. groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
  16. tiles = {
  17. TEXPFX.."tp.png",
  18. TEXPFX.."bt.png",
  19. TEXPFX.."rt.png",
  20. TEXPFX.."lt.png",
  21. TEXPFX.."bk.png",
  22. TEXPFX.."ft.png"
  23. },
  24. node_box = cdef.node_box,
  25. selection_box = cdef.node_box,
  26. on_rightclick = function (pos, node, clicker, itemstack)
  27. if cdef.on_turn_off and cdef.on_turn_off(pos, node, clicker, itemstack) then
  28. return itemstack
  29. end
  30. node.name = OFFSTATE
  31. minetest.set_node(pos, node)
  32. return itemstack
  33. end
  34. })
  35. minetest.register_node(OFFSTATE, {
  36. drawtype = "nodebox",
  37. paramtype = "light",
  38. paramtype2 = "facedir",
  39. groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
  40. tiles = {
  41. (TEXPFX.."tp"..(cdef.tiles_off.top and "_off" or "")..".png"),
  42. (TEXPFX.."bt"..(cdef.tiles_off.bottom and "_off" or "")..".png"),
  43. (TEXPFX.."rt"..(cdef.tiles_off.right and "_off" or "")..".png"),
  44. (TEXPFX.."lt"..(cdef.tiles_off.left and "_off" or "")..".png"),
  45. (TEXPFX.."bk"..(cdef.tiles_off.back and "_off" or "")..".png"),
  46. (TEXPFX.."ft"..(cdef.tiles_off.front and "_off" or "")..".png")
  47. },
  48. node_box = cdef.node_box_off or cdef.node_box,
  49. selection_box = cdef.node_box_off or cdef.node_box,
  50. on_rightclick = function (pos, node, clicker, itemstack)
  51. if cdef.on_turn_on and cdef.on_turn_on(pos, node, clicker, itemstack) then
  52. return itemstack
  53. end
  54. node.name = ONSTATE
  55. minetest.set_node(pos, node)
  56. return itemstack
  57. end,
  58. drop = ONSTATE
  59. })
  60. end
  61. computer.register_handheld = function (name, def)
  62. if (name:sub(1, 1) == ":") then name = name:sub(2) end
  63. local modname, basename = name:match("^([^:]+):(.*)")
  64. local TEXPFX = modname.."_"..basename.."_inv"
  65. local ONSTATE = modname..":"..basename
  66. minetest.register_craftitem(ONSTATE, {
  67. description = def.description,
  68. inventory_image = TEXPFX..".png",
  69. wield_image = TEXPFX..".png"
  70. })
  71. end
  72. computer.pixelnodebox = function (size, boxes)
  73. local fixed = { }
  74. for _, box in ipairs(boxes) do
  75. local x, y, z, w, h, l = unpack(box)
  76. fixed[#fixed + 1] = {
  77. (x / size) - 0.5,
  78. (y / size) - 0.5,
  79. (z / size) - 0.5,
  80. ((x + w) / size) - 0.5,
  81. ((y + h) / size) - 0.5,
  82. ((z + l) / size) - 0.5
  83. }
  84. end
  85. return {
  86. type = "fixed",
  87. fixed = fixed
  88. }
  89. end
  90. local MODPATH = minetest.get_modpath("computer")
  91. dofile(MODPATH.."/computers.lua")
  92. dofile(MODPATH.."/printers.lua")
  93. dofile(MODPATH.."/recipes.lua")
  94. dofile(MODPATH.."/tetris.lua")