gate_slots.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. local MP, S, NS = nil
  2. if (minetest.get_modpath("intllib") == nil) then
  3. S = minetest.get_translator("castle_gates")
  4. else
  5. -- internationalization boilerplate
  6. MP = minetest.get_modpath(minetest.get_current_modname())
  7. S, NS = dofile(MP.."/intllib.lua")
  8. end
  9. -- copied from castle_masonry in case that mod is not loaded
  10. local get_material_properties = function(material)
  11. local composition_def
  12. local burn_time
  13. if material.composition_material ~= nil then
  14. composition_def = minetest.registered_nodes[material.composition_material]
  15. burn_time = minetest.get_craft_result({method="fuel", width=1, items={ItemStack(material.composition_material)}}).time
  16. else
  17. composition_def = minetest.registered_nodes[material.craft_material]
  18. burn_time = minetest.get_craft_result({method="fuel", width=1, items={ItemStack(material.craft_materia)}}).time
  19. end
  20. local tiles = material.tile
  21. if tiles == nil then
  22. tiles = composition_def.tile
  23. elseif type(tiles) == "string" then
  24. tiles = {tiles}
  25. end
  26. local desc = material.desc
  27. if desc == nil then
  28. desc = composition_def.description
  29. end
  30. return composition_def, burn_time, tiles, desc
  31. end
  32. local materials
  33. if minetest.get_modpath("castle_masonry") then
  34. materials = castle_masonry.materials
  35. else
  36. materials = {{name="stonebrick", desc=S("Stonebrick"), tile="default_stone_brick.png", craft_material="default:stonebrick"}}
  37. end
  38. castle_gates.register_gate_slot = function(material)
  39. local composition_def, burn_time, tile, desc = get_material_properties(material)
  40. local mod_name = minetest.get_current_modname()
  41. minetest.register_node(mod_name..":"..material.name.."_gate_slot", {
  42. drawtype = "nodebox",
  43. description = S("@1 Gate Slot", desc),
  44. _doc_items_longdesc = castle_gates.doc.gate_slot_longdesc,
  45. _doc_items_usagehelp = castle_gates.doc.gate_slot_usagehelp,
  46. tiles = tile,
  47. paramtype = "light",
  48. paramtype2 = "facedir",
  49. groups = composition_def.groups,
  50. sounds = composition_def.sounds,
  51. node_box = {
  52. type = "fixed",
  53. fixed = {
  54. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, -- body
  55. {-0.5, -0.5, -0.75, 0.5, 0.5, -1.5}, -- bracket
  56. }
  57. },
  58. collision_box = {
  59. type = "fixed",
  60. fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 1.5}, -- body
  61. },
  62. })
  63. minetest.register_node(mod_name..":"..material.name.."_gate_slot_reverse", {
  64. drawtype = "nodebox",
  65. description = S("@1 Gate Slot Reverse", desc),
  66. _doc_items_longdesc = castle_gates.doc.gate_slot_reverse_longdesc,
  67. _doc_items_usagehelp = castle_gates.doc.gate_slot_reverse_usagehelp,
  68. tiles = tile,
  69. paramtype = "light",
  70. paramtype2 = "facedir",
  71. groups = composition_def.groups,
  72. sounds = composition_def.sounds,
  73. node_box = {
  74. type = "fixed",
  75. fixed = {
  76. {-0.5, -0.5, -1.25, 0.5, 0.5, 0.5}, -- body
  77. }
  78. },
  79. collision_box = {
  80. type = "fixed",
  81. fixed = {-0.5, -0.5, -1.25, 0.5, 0.5, 0.5}, -- body
  82. },
  83. })
  84. minetest.register_craft({
  85. output = mod_name..":"..material.name.."_gate_slot 2",
  86. recipe = {
  87. {material.craft_material,"",material.craft_material},
  88. {material.craft_material,"",material.craft_material},
  89. },
  90. })
  91. minetest.register_craft({
  92. output = mod_name..":"..material.name.."_gate_slot",
  93. type = "shapeless",
  94. recipe = {mod_name..":"..material.name.."_gate_slot_reverse"},
  95. })
  96. minetest.register_craft({
  97. output = mod_name..":"..material.name.."_gate_slot_reverse",
  98. type = "shapeless",
  99. recipe = {mod_name..":"..material.name.."_gate_slot"},
  100. })
  101. if burn_time > 0 then
  102. minetest.register_craft({
  103. type = "fuel",
  104. recipe = mod_name..":"..material.name.."_gate_slot",
  105. burntime = burn_time * 2,
  106. })
  107. minetest.register_craft({
  108. type = "fuel",
  109. recipe = mod_name..":"..material.name.."_gate_slot_reverse",
  110. burntime = burn_time * 2,
  111. })
  112. end
  113. end
  114. castle_gates.register_gate_slot_alias = function(old_mod_name, old_material_name, new_mod_name, new_material_name)
  115. minetest.register_alias(old_mod_name..":"..old_material_name.."_gate_slot", new_mod_name..":"..new_material_name.."_gate_slot")
  116. minetest.register_alias(old_mod_name..":"..old_material_name.."_gate_slot_reverse", new_mod_name..":"..new_material_name.."_gate_slot_reverse")
  117. end
  118. castle_gates.register_gate_slot_alias_force = function(old_mod_name, old_material_name, new_mod_name, new_material_name)
  119. minetest.register_alias_force(old_mod_name..":"..old_material_name.."_gate_slot", new_mod_name..":"..new_material_name.."_gate_slot")
  120. minetest.register_alias_force(old_mod_name..":"..old_material_name.."_gate_slot_reverse", new_mod_name..":"..new_material_name.."_gate_slot_reverse")
  121. end
  122. for _, material in pairs(materials) do
  123. castle_gates.register_gate_slot(material)
  124. end