init.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. castle_masonry = {}
  2. local MP = minetest.get_modpath(minetest.get_current_modname())
  3. dofile(MP.."/pillars.lua")
  4. dofile(MP.."/arrow_slits.lua")
  5. dofile(MP.."/murder_holes.lua")
  6. dofile(MP.."/stone_wall.lua")
  7. dofile(MP.."/paving.lua")
  8. local S, NS = dofile(MP.."/intllib.lua")
  9. local read_setting = function(name, default)
  10. local setting = minetest.settings:get_bool(name)
  11. if setting == nil then return default end
  12. return setting
  13. end
  14. -- Material definition:
  15. -- {
  16. -- name=, -- the name that will be part of the resulting node names
  17. -- desc=, -- Player-facing name of the material
  18. -- tile=, -- Optional - the texture tile to use for the resulting blocks (can be a single texture or a table, as a normal node definition's tile def). If not set this will be taken from the material it's made out of.
  19. -- craft_material=, -- What source block is used to craft these blocks.
  20. -- composition_material=, -- Optional, this will override the properties of the product with a specific material. Useful if you want to use a group for the craft material (eg, "group:wood")
  21. --}
  22. castle_masonry.materials = {}
  23. if read_setting("castle_masonry_stonewall", true) then
  24. table.insert(castle_masonry.materials, {name="stonewall", desc=S("Stonewall"), tile="castle_stonewall.png", craft_material="castle_masonry:stonewall"})
  25. end
  26. if read_setting("castle_masonry_cobble", true) then
  27. table.insert(castle_masonry.materials, {name="cobble", desc=S("Cobble"), tile="default_cobble.png", craft_material="default:cobble"})
  28. end
  29. if read_setting("castle_masonry_stonebrick", true) then
  30. table.insert(castle_masonry.materials, {name="stonebrick", desc=S("Stonebrick"), tile="default_stone_brick.png", craft_material="default:stonebrick"})
  31. end
  32. if read_setting("castle_masonry_sandstonebrick", true) then
  33. table.insert(castle_masonry.materials, {name="sandstonebrick", desc=S("Sandstone Brick"), tile="default_sandstone_brick.png", craft_material="default:sandstonebrick"})
  34. end
  35. if read_setting("castle_masonry_desertstonebrick", true) then
  36. table.insert(castle_masonry.materials, {name="desertstonebrick", desc=S("Desert Stone Brick"), tile="default_desert_stone_brick.png", craft_material="default:desert_stonebrick"})
  37. end
  38. if read_setting("castle_masonry_desertsandstonebrick", true) then
  39. table.insert(castle_masonry.materials, {name="desertsandstonebrick", desc=S("Desert Sandstone Brick"), tile="default_desert_sandstone_brick.png", craft_material="default:desert_sandstone_brick"})
  40. end
  41. if read_setting("castle_masonry_silversandstonebrick", true) then
  42. table.insert(castle_masonry.materials, {name="silversandstonebrick", desc=S("Silver Sandstone Brick"), tile="default_silver_sandstone_brick.png", craft_material="default:silver_sandstone_brick"})
  43. end
  44. if read_setting("castle_masonry_stone", true) then
  45. table.insert(castle_masonry.materials, {name="stone", desc=S("Stone"), tile="default_stone.png", craft_material="default:stone"})
  46. end
  47. if read_setting("castle_masonry_sandstone", true) then
  48. table.insert(castle_masonry.materials, {name="sandstone", desc=S("Sandstone"), tile="default_sandstone.png", craft_material="default:sandstone"})
  49. end
  50. if read_setting("castle_masonry_desertstone", true) then
  51. table.insert(castle_masonry.materials, {name="desertstone", desc=S("Desert Stone"), tile="default_desert_stone.png", craft_material="default:desert_stone"})
  52. end
  53. if read_setting("castle_masonry_desertsandstone", true) then
  54. table.insert(castle_masonry.materials, {name="desertsandstone", desc=S("Desert Sandstone"), tile="default_desert_sandstone.png", craft_material="default:desert_sandstone"})
  55. end
  56. if read_setting("castle_masonry_silversandstone", true) then
  57. table.insert(castle_masonry.materials, {name="silversandstone", desc=S("Silver Sandstone"), tile="default_silver_sandstone.png", craft_material="default:silver_sandstone"})
  58. end
  59. if read_setting("castle_masonry_wood", false) then
  60. table.insert(castle_masonry.materials, {name="wood", desc=S("Wood"), tile="default_wood.png", craft_material="group:wood", composition_material="default:wood"})
  61. end
  62. if read_setting("castle_masonry_ice", false) then
  63. table.insert(castle_masonry.materials, {name="ice", desc=S("Ice"), tile="default_ice.png", craft_material="default:ice"})
  64. end
  65. if read_setting("castle_masonry_snow", false) then
  66. table.insert(castle_masonry.materials, {name="snow", desc=S("Snow"), tile="default_snow.png", craft_material="default:snow"})
  67. end
  68. if read_setting("castle_masonry_obsidianbrick", false) then
  69. table.insert(castle_masonry.materials, {name="obsidianbrick", desc=S("Obsidian Brick"), tile="default_obsidian_brick.png", craft_material="default:obsidianbrick"})
  70. end
  71. table.insert(castle_masonry.materials, {name="obsidianbrick", desc=S("Obsidian Brick"), tile="default_obsidian_brick.png", craft_material="default:obsidianbrick"})
  72. castle_masonry.get_material_properties = function(material)
  73. local composition_def
  74. local burn_time
  75. if material.composition_material ~= nil then
  76. composition_def = minetest.registered_nodes[material.composition_material]
  77. burn_time = minetest.get_craft_result({method="fuel", width=1, items={ItemStack(material.composition_material)}}).time
  78. else
  79. composition_def = minetest.registered_nodes[material.craft_material]
  80. burn_time = minetest.get_craft_result({method="fuel", width=1, items={ItemStack(material.craft_materia)}}).time
  81. end
  82. local tiles = material.tile
  83. if tiles == nil then
  84. tiles = composition_def.tile
  85. elseif type(tiles) == "string" then
  86. tiles = {tiles}
  87. end
  88. local desc = material.desc
  89. if desc == nil then
  90. desc = composition_def.description
  91. end
  92. return composition_def, burn_time, tiles, desc
  93. end
  94. if read_setting("castle_masonry_pillar", true) then
  95. for _, material in pairs(castle_masonry.materials) do
  96. castle_masonry.register_pillar(material)
  97. end
  98. end
  99. if read_setting("castle_masonry_arrowslit", true) then
  100. for _, material in pairs(castle_masonry.materials) do
  101. castle_masonry.register_arrowslit(material)
  102. end
  103. end
  104. if read_setting("castle_masonry_murderhole", true) then
  105. for _, material in pairs(castle_masonry.materials) do
  106. castle_masonry.register_murderhole(material)
  107. end
  108. end
  109. minetest.register_alias("castle:pillars_bottom", "castle_masonry:pillars_stonewall_bottom")
  110. minetest.register_alias("castle:pillars_top", "castle_masonry:pillars_stonewall_top")
  111. minetest.register_alias("castle:pillars_middle", "castle_masonry:pillars_stonewall_middle")
  112. minetest.register_alias("castle:arrowslit", "castle_masonry:arrowslit_stonewall")
  113. minetest.register_alias("castle:arrowslit_hole", "castle_masonry:arrowslit_stonewall_hole")
  114. minetest.register_alias("castle:arrowslit_cross", "castle_masonry:arrowslit_stonewall_cross")
  115. for _, material in pairs(castle_masonry.materials) do
  116. castle_masonry.register_murderhole_alias("castle", material.name, "castle_masonry", material.name)
  117. castle_masonry.register_pillar_alias("castle", material.name, "castle_masonry", material.name)
  118. -- Arrowslit upgrade has special handling because the castle mod arrow slit is reversed relative to current build-from-inside standard
  119. local lbm_def = {
  120. name = "castle_masonry:arrowslit_flip_front_to_back"..material.name,
  121. nodenames = {
  122. "castle:arrowslit_"..material.name,
  123. "castle:arrowslit_"..material.name.."_cross",
  124. "castle:arrowslit_"..material.name.."_hole",
  125. },
  126. action = function(pos, node)
  127. local flip_front_to_back = {[0]=2, 3, 0, 1, 6, 7, 4, 5, 10, 7, 8, 9, 14, 15, 12, 13, 18, 19, 16, 17, 22, 23, 20, 21}
  128. node.param2 = flip_front_to_back[node.param2]
  129. node.name = "castle_masonry" .. string.sub(node.name, 7, -1)
  130. minetest.swap_node(pos, node)
  131. end
  132. }
  133. minetest.register_lbm(lbm_def)
  134. end