blueprints.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. minetest.register_craftitem("bitumen:blueprint_paper", {
  2. description = "Blueprint Paper",
  3. stack_max = 99,
  4. inventory_image = "default_paper.png^[colorize:blue:120",
  5. groups = {flammable = 3},
  6. })
  7. minetest.register_craftitem("bitumen:blueprint_book", {
  8. description = "Blueprint Paper",
  9. stack_max = 99,
  10. inventory_image = "default_book.png^[colorize:blue:120",
  11. groups = {flammable = 3},
  12. })
  13. bitumen.registered_blueprints = {
  14. -- ["bitumen:cement_mixer_blueprint"] = 1,
  15. }
  16. -- registers the blueprint item, adds it to the bookshelf, and registers the constructor craft recipe
  17. bitumen.register_blueprint = function(def)
  18. local name = def.name.."_blueprint"
  19. local parent_def = minetest.registered_nodes[def.name]
  20. if parent_def == nil then
  21. print("Warning: parent node not registered yet. Place bitumen.register_blueprint call after node registration.")
  22. return
  23. end
  24. minetest.register_craftitem(name, {
  25. description = parent_def.description.." Blueprint",
  26. stack_max = 1,
  27. inventory_image = parent_def.inventory_image .. "^bitumen_blueprint.png",
  28. groups = {flammable = 3},
  29. })
  30. if not def.no_constructor_craft then
  31. -- the actual constructor must be registered elsewhere
  32. minetest.register_craft({
  33. output = def.name..'_constructor',
  34. recipe = {
  35. {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
  36. {'default:steel_ingot', name, 'default:steel_ingot'},
  37. {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
  38. }
  39. })
  40. end
  41. bitumen.registered_blueprints[name] = def
  42. end
  43. local blueprint_bookshelf_formspec =
  44. "size[8,8;]" ..
  45. default.gui_bg ..
  46. default.gui_bg_img ..
  47. default.gui_slots ..
  48. "list[context;blueprints;0,0.3;8,3;]" ..
  49. "list[current_player;main;0,3.85;8,1;]" ..
  50. "list[current_player;main;0,5.08;8,3;8]" ..
  51. "listring[context;blueprints]" ..
  52. "listring[current_player;main]" ..
  53. default.get_hotbar_bg(0,3.85)
  54. minetest.register_node("bitumen:blueprint_bookshelf", {
  55. description = "Blueprint Bookshelf",
  56. tiles = {"default_junglewood.png", "default_junglewood.png", "default_junglewood.png",
  57. "default_junglewood.png", "default_bookshelf.png^[colorize:blue:120", "default_junglewood.png"},
  58. paramtype2 = "facedir",
  59. is_ground_content = false,
  60. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
  61. sounds = default.node_sound_wood_defaults(),
  62. stack_max = 1,
  63. on_construct = function(pos)
  64. local meta = minetest.get_meta(pos)
  65. meta:set_string("formspec", blueprint_bookshelf_formspec)
  66. local inv = meta:get_inventory()
  67. inv:set_size("blueprints", 8 * 3)
  68. -- fill in the known blueprints
  69. local list = {}
  70. for name,def in pairs(bitumen.registered_blueprints) do
  71. table.insert(list, name)
  72. end
  73. inv:set_list("blueprints", list)
  74. end,
  75. allow_metadata_inventory_put = function(pos, listname, index, stack)
  76. return 0
  77. end,
  78. allow_metadata_inventory_move = function(pos, listname, index, stack)
  79. return 0
  80. end,
  81. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  82. -- print(" -- "..listname.. " " ..index.." "..dump(stack))
  83. local meta = minetest.get_meta(pos)
  84. local inv = meta:get_inventory(meta)
  85. inv:set_stack(listname, index, stack)
  86. end,
  87. })