brasier.lua 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. if not minetest.get_modpath("fire") then return end
  2. -- internationalization boilerplate
  3. local MP = minetest.get_modpath(minetest.get_current_modname())
  4. local S, NS = dofile(MP.."/intllib.lua")
  5. local brasier_longdesc = S("A brasier for producing copious amounts of light and heat.")
  6. local brasier_usagehelp = S("To ignite the brasier place a flammable fuel in its inventory slot. A lump of coal will burn for about half an hour.")
  7. local brasier_nodebox = {
  8. type = "fixed",
  9. fixed = {
  10. {-0.25, 0, -0.25, 0.25, 0.125, 0.25}, -- base
  11. {-0.375, 0.125, -0.375, 0.375, 0.25, 0.375}, -- mid
  12. {-0.5, 0.25, -0.5, 0.5, 0.375, 0.5}, -- plat
  13. {-0.5, 0.375, 0.375, 0.5, 0.5, 0.5}, -- edge
  14. {-0.5, 0.375, -0.5, 0.5, 0.5, -0.375}, -- edge
  15. {0.375, 0.375, -0.375, 0.5, 0.5, 0.375}, -- edge
  16. {-0.5, 0.375, -0.375, -0.375, 0.5, 0.375}, -- edge
  17. {0.25, -0.5, -0.375, 0.375, 0.125, -0.25}, -- leg
  18. {-0.375, -0.5, 0.25, -0.25, 0.125, 0.375}, -- leg
  19. {0.25, -0.5, 0.25, 0.375, 0.125, 0.375}, -- leg
  20. {-0.375, -0.5, -0.375, -0.25, 0.125, -0.25}, -- leg
  21. {-0.125, -0.0625, -0.125, 0.125, 0, 0.125}, -- bottom_knob
  22. }
  23. }
  24. local brasier_selection_box = {
  25. type = "fixed",
  26. fixed = {
  27. {-0.375, -0.5, -0.375, 0.375, 0.25, 0.375}, -- mid
  28. {-0.5, 0.25, -0.5, 0.5, 0.5, 0.5}, -- plat
  29. }
  30. }
  31. local brasier_burn = function(pos)
  32. local pos_above = {x=pos.x, y=pos.y+1, z=pos.z}
  33. local node_above = minetest.get_node(pos_above)
  34. local timer = minetest.get_node_timer(pos)
  35. if timer:is_started() and node_above.name == "epic:permanent_flame" then return end -- already burning, don't burn a new thing.
  36. local inv = minetest.get_inventory({type="node", pos=pos})
  37. local item = inv:get_stack("fuel", 1)
  38. local fuel_burned = minetest.get_craft_result({method="fuel", width=1, items={item:peek_item(1)}}).time
  39. if fuel_burned > 0 and (node_above.name == "air" or node_above.name == "epic:permanent_flame") then
  40. item:set_count(item:get_count() - 1)
  41. inv:set_stack("fuel", 1, item)
  42. timer:start(fuel_burned * 60) -- one minute of flame per second of burn time, for balance.
  43. if node_above.name == "air" then
  44. minetest.set_node(pos_above, {name = "epic:permanent_flame"})
  45. end
  46. else
  47. if node_above.name == "epic:permanent_flame" then
  48. minetest.set_node(pos_above, {name = "air"})
  49. end
  50. end
  51. end
  52. local brasier_on_construct = function(pos)
  53. local inv = minetest.get_meta(pos):get_inventory()
  54. inv:set_size("fuel", 1)
  55. local meta = minetest.get_meta(pos)
  56. meta:set_string("formspec",
  57. "size[8,5.3]" ..
  58. default.gui_bg ..
  59. default.gui_bg_img ..
  60. default.gui_slots ..
  61. "list[current_name;fuel;3.5,0;1,1;]" ..
  62. "list[current_player;main;0,1.15;8,1;]" ..
  63. "list[current_player;main;0,2.38;8,3;8]" ..
  64. "listring[current_name;main]" ..
  65. "listring[current_player;main]" ..
  66. default.get_hotbar_bg(0,1.15)
  67. )
  68. end
  69. local brasier_on_destruct = function(pos, oldnode)
  70. local pos_above = {x=pos.x, y=pos.y+1, z=pos.z}
  71. local node_above = minetest.get_node(pos_above)
  72. if node_above.name == "epic:permanent_flame" then
  73. minetest.set_node(pos_above, {name = "air"})
  74. end
  75. end
  76. local brasier_can_dig = function(pos, player)
  77. local inv = minetest.get_meta(pos):get_inventory()
  78. return inv:is_empty("fuel")
  79. end
  80. -- Only allow fuel items to be placed in fuel
  81. local brasier_allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  82. if listname == "fuel" then
  83. if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
  84. return stack:get_count()
  85. else
  86. return 0
  87. end
  88. end
  89. return 0
  90. end
  91. minetest.register_node("castle_lighting:brasier_floor", {
  92. description = S("Floor Brasier"),
  93. _doc_items_longdesc = brasier_longdesc,
  94. _doc_items_usagehelp = brasier_usagehelp,
  95. tiles = {
  96. "castle_steel.png^(castle_coal_bed.png^[mask:castle_brasier_bed_mask.png)",
  97. "castle_steel.png",
  98. "castle_steel.png",
  99. "castle_steel.png",
  100. "castle_steel.png",
  101. "castle_steel.png",
  102. },
  103. drawtype = "nodebox",
  104. groups = {cracky=2},
  105. paramtype = "light",
  106. node_box = brasier_nodebox,
  107. selection_box = brasier_selection_box,
  108. on_construct = brasier_on_construct,
  109. on_destruct = brasier_on_destruct,
  110. can_dig = brasier_can_dig,
  111. allow_metadata_inventory_put = brasier_allow_metadata_inventory_put,
  112. on_metadata_inventory_put = brasier_burn,
  113. on_timer = brasier_burn,
  114. })
  115. minetest.register_craft({
  116. output = "castle_lighting:brasier_floor",
  117. recipe = {
  118. {"default:steel_ingot", "default:torch", "default:steel_ingot"},
  119. {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
  120. }
  121. })
  122. if minetest.get_modpath("hopper") and hopper ~= nil and hopper.add_container ~= nil then
  123. hopper:add_container({
  124. {"top", "castle_lighting:brasier_floor", "fuel"},
  125. {"bottom", "castle_lighting:brasier_floor", "fuel"},
  126. {"side", "castle_lighting:brasier_floor", "fuel"},
  127. })
  128. end
  129. ------------------------------------------------------------------------------------------------------
  130. -- Masonry brasiers
  131. local materials
  132. if minetest.get_modpath("castle_masonry") then
  133. materials = castle_masonry.materials
  134. else
  135. materials = {{name="stonebrick", desc=S("Stonebrick"), tile="default_stone_brick.png", craft_material="default:stonebrick"}}
  136. end
  137. local get_material_properties = function(material)
  138. local composition_def
  139. local burn_time
  140. if material.composition_material ~= nil then
  141. composition_def = minetest.registered_nodes[material.composition_material]
  142. burn_time = minetest.get_craft_result({method="fuel", width=1, items={ItemStack(material.composition_material)}}).time
  143. else
  144. composition_def = minetest.registered_nodes[material.craft_material]
  145. burn_time = minetest.get_craft_result({method="fuel", width=1, items={ItemStack(material.craft_materia)}}).time
  146. end
  147. local tiles = material.tile
  148. if tiles == nil then
  149. tiles = composition_def.tile
  150. elseif type(tiles) == "string" then
  151. tiles = {tiles}
  152. end
  153. -- Apply bed of coals to the texture.
  154. if table.getn(tiles) == 1 then
  155. tiles = {tiles[1].."^(castle_coal_bed.png^[mask:castle_brasier_bed_mask.png)", tiles[1], tiles[1], tiles[1], tiles[1], tiles[1]}
  156. else
  157. tiles[1] = tiles[1].."^(castle_coal_bed.png^[mask:castle_brasier_bed_mask.png)"
  158. end
  159. local desc = material.desc
  160. if desc == nil then
  161. desc = composition_def.description
  162. end
  163. return composition_def, burn_time, tiles, desc
  164. end
  165. local pillar_brasier_nodebox = {
  166. type = "fixed",
  167. fixed = {
  168. {-0.375, 0.125, -0.375, 0.375, 0.25, 0.375}, -- mid
  169. {-0.5, 0.25, -0.5, 0.5, 0.375, 0.5}, -- plat
  170. {-0.5, 0.375, 0.375, 0.5, 0.5, 0.5}, -- edge
  171. {-0.5, 0.375, -0.5, 0.5, 0.5, -0.375}, -- edge
  172. {0.375, 0.375, -0.375, 0.5, 0.5, 0.375}, -- edge
  173. {-0.5, 0.375, -0.375, -0.375, 0.5, 0.375}, -- edge
  174. {-0.25,-0.5,-0.25,0.25,0.125,0.25}, -- support
  175. }
  176. }
  177. local pillar_brasier_selection_box = {
  178. type = "fixed",
  179. fixed = {
  180. {-0.375, 0.125, -0.375, 0.375, 0.25, 0.375}, -- mid
  181. {-0.5, 0.25, -0.5, 0.5, 0.5, 0.5}, -- plat
  182. {-0.25,-0.5,-0.25,0.25,0.125,0.25}, -- support
  183. }
  184. }
  185. castle_lighting.register_pillar_brasier = function(material)
  186. local composition_def, burn_time, tile, desc = get_material_properties(material)
  187. if burn_time > 0 or composition_def.groups.puts_out_fire then return end -- No wooden brasiers, snow brasiers, or ice brasiers, alas.
  188. local crossbrace_connectable_groups = {}
  189. for group, val in pairs(composition_def.groups) do
  190. crossbrace_connectable_groups[group] = val
  191. end
  192. crossbrace_connectable_groups.crossbrace_connectable = 1
  193. local mod_name = minetest.get_current_modname()
  194. minetest.register_node(mod_name..":"..material.name.."_pillar_brasier", {
  195. drawtype = "nodebox",
  196. description = S("@1 Brasier", desc),
  197. _doc_items_longdesc = brasier_longdesc,
  198. _doc_items_usagehelp = brasier_usagehelp,
  199. tiles = tile,
  200. paramtype = "light",
  201. paramtype2 = "facedir",
  202. groups = crossbrace_connectable_groups,
  203. sounds = composition_def.sounds,
  204. node_box = pillar_brasier_nodebox,
  205. selection_box = pillar_brasier_selection_box,
  206. on_construct = brasier_on_construct,
  207. on_destruct = brasier_on_destruct,
  208. can_dig = brasier_can_dig,
  209. allow_metadata_inventory_put = brasier_allow_metadata_inventory_put,
  210. on_metadata_inventory_put = brasier_burn,
  211. on_timer = brasier_burn,
  212. })
  213. minetest.register_craft({
  214. output = mod_name..":"..material.name.."_pillar_brasier 5",
  215. recipe = {
  216. {material.craft_material,"default:torch",material.craft_material},
  217. {material.craft_material,material.craft_material,material.craft_material},
  218. },
  219. })
  220. if minetest.get_modpath("hopper") and hopper ~= nil and hopper.add_container ~= nil then
  221. hopper:add_container({
  222. {"top", mod_name..":"..material.name.."_pillar_brasier", "fuel"},
  223. {"bottom", mod_name..":"..material.name.."_pillar_brasier", "fuel"},
  224. {"side", mod_name..":"..material.name.."_pillar_brasier", "fuel"},
  225. })
  226. end
  227. end
  228. for _, material in pairs(materials) do
  229. castle_lighting.register_pillar_brasier(material)
  230. end