init.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. local random, max = math.random, math.max
  2. local pairs, table = pairs, table
  3. local minetest = minetest
  4. local technic = technic
  5. local modname = minetest.get_current_modname()
  6. local modpath = minetest.get_modpath(modname)
  7. local setting_melt_difficulty = 10
  8. forge = {}
  9. local melt_total = {}
  10. local melt_yields = {}
  11. local meltable_ores = {}
  12. local cools_to = {}
  13. local melt_densities = {}
  14. local melt_energy_requirement = {}
  15. local molten_sources = {}
  16. forge.meltable_ores = meltable_ores
  17. dofile(modpath .. "/shell.lua")
  18. dofile(modpath.."/coke.lua")
  19. dofile(modpath.."/burners.lua")
  20. dofile(modpath.."/spout.lua")
  21. -- technic support
  22. dofile(modpath.."/electrode.lua")
  23. forge.random_melt_product = function(name)
  24. if melt_total[name] == 0 or melt_total[name] == nil then
  25. return modname..":molten_slag"
  26. end
  27. local r = random(melt_total[name])
  28. for k,v in pairs(melt_yields[name]) do
  29. r = r - v
  30. if r <= 0 then
  31. return modname..":molten_"..k
  32. end
  33. end
  34. return modname..":molten_slag"
  35. end
  36. local random_melt_product = forge.random_melt_product
  37. forge.max_heat = 0
  38. forge.register_ore = function(name, eu_to_melt, yields)
  39. local y2 = {}
  40. local total = 0
  41. for k,v in pairs(yields) do
  42. total = total + v
  43. y2[k] = v
  44. end
  45. table.insert(meltable_ores, name)
  46. melt_yields[name] = y2
  47. melt_total[name] = total
  48. melt_energy_requirement[name] = eu_to_melt * setting_melt_difficulty
  49. forge.max_heat = max(forge.max_heat, melt_energy_requirement[name] * 1.5)
  50. end
  51. -- registers the molten liquids and densities
  52. function forge.register_metal(opts)
  53. cools_to[modname..":molten_"..opts.name] = opts.cools
  54. melt_densities[modname..":molten_"..opts.name] = opts.density
  55. table.insert(molten_sources, modname..":molten_"..opts.name)
  56. minetest.register_node(modname..":molten_"..opts.name, {
  57. description = "Molten " .. opts.Name,
  58. inventory_image = minetest.inventorycube("default_lava.png"),
  59. drawtype = "liquid",
  60. tiles = {
  61. {
  62. name = "default_lava_source_animated.png",
  63. animation = {
  64. type = "vertical_frames",
  65. aspect_w = 16,
  66. aspect_h = 16,
  67. length = 3.0,
  68. },
  69. },
  70. },
  71. special_tiles = {
  72. -- New-style lava source material (mostly unused)
  73. {
  74. name = "default_lava_source_animated.png",
  75. animation = {
  76. type = "vertical_frames",
  77. aspect_w = 16,
  78. aspect_h = 16,
  79. length = 3.0,
  80. },
  81. backface_culling = false,
  82. },
  83. },
  84. paramtype = "light",
  85. light_source = default.LIGHT_MAX - 3,
  86. --walkable = false,
  87. --pointable = false,
  88. diggable = false,
  89. -- buildable_to = true,
  90. is_ground_content = false,
  91. drop = "",
  92. drowning = 1,
  93. liquidtype = "source",
  94. liquid_alternative_flowing = modname..":molten_"..opts.name.."_flowing",
  95. liquid_alternative_source = modname..":molten_"..opts.name,
  96. liquid_viscosity = 2,
  97. liquid_renewable = false,
  98. liquid_range = 2,
  99. damage_per_second = 2 * 2,
  100. post_effect_color = {a = 192, r = 255, g = 64, b = 0},
  101. groups = {
  102. lava = 2, liquid = 2, hot = 3, igniter = 1, not_in_creative_inventory = 1,
  103. molten_ore=3, molten_ore_source=1,
  104. },
  105. })
  106. minetest.register_node(modname..":molten_"..opts.name.."_flowing", {
  107. description = "Molten "..opts.Name,
  108. inventory_image = minetest.inventorycube("default_lava.png"),
  109. drawtype = "flowingliquid",
  110. tiles = {"default_lava.png"},
  111. special_tiles = {
  112. {
  113. name = "default_lava_flowing_animated.png",
  114. backface_culling = false,
  115. animation = {
  116. type = "vertical_frames",
  117. aspect_w = 16,
  118. aspect_h = 16,
  119. length = 3.3,
  120. },
  121. },
  122. {
  123. name = "default_lava_flowing_animated.png",
  124. backface_culling = true,
  125. animation = {
  126. type = "vertical_frames",
  127. aspect_w = 16,
  128. aspect_h = 16,
  129. length = 3.3,
  130. },
  131. },
  132. },
  133. paramtype = "light",
  134. paramtype2 = "flowingliquid",
  135. light_source = default.LIGHT_MAX - 3,
  136. -- walkable = false,
  137. -- pointable = false,
  138. diggable = false,
  139. -- buildable_to = true,
  140. is_ground_content = false,
  141. drop = "",
  142. drowning = 1,
  143. liquidtype = "flowing",
  144. liquid_alternative_flowing = modname..":molten_"..opts.name.."_flowing",
  145. liquid_alternative_source = modname..":molten_"..opts.name,
  146. liquid_viscosity = 2,
  147. liquid_renewable = false,
  148. liquid_range = 2,
  149. damage_per_second = 1 * 2,
  150. post_effect_color = {a = 192, r = 255, g = 64, b = 0},
  151. groups = {
  152. lava = 2, liquid = 2, hot = 3, igniter = 1,
  153. molten_ore=1, molten_ore_flowing=1,
  154. not_in_creative_inventory = 1
  155. },
  156. })
  157. -- ingot molds
  158. if nil ~= opts.ingot then
  159. -- TODO: hot
  160. minetest.register_node(modname..":mold_"..opts.name, {
  161. description = "Ingot Mold",
  162. tiles = {
  163. "default_silver_sand.png^(forge_ingots.png^[colorize:"..opts.ingot_color..")", "default_silver_sand.png",
  164. "default_silver_sand.png", "default_silver_sand.png",
  165. "default_silver_sand.png", "default_silver_sand.png"
  166. },
  167. groups = {crumbly=3, refractory=1, falling_node=1},
  168. is_ground_content = false,
  169. sounds = default.node_sound_stone_defaults(),
  170. drop = {
  171. max_items = 2,
  172. items = {
  173. {items = {"default:silver_sand"}},
  174. {items = {opts.ingot.." 9"}}
  175. }
  176. },
  177. --[[on_punch = function(pos, node, puncher)
  178. local inv = puncher:get_inventory()
  179. inv:add_item("main", opts.ingot.." 9")
  180. minetest.set_node(pos, {name = modname..":mold"})
  181. end,]]
  182. })
  183. minetest.register_abm({
  184. nodenames = {modname..":molten_"..opts.name},
  185. neightbors = {modname..":mold"},
  186. interval = 2,
  187. chance = 1,
  188. action = function(pos, node)
  189. -- look one node out
  190. local molds = minetest.find_nodes_in_area(
  191. {x=pos.x - 1, y=pos.y, z=pos.z - 1},
  192. {x=pos.x + 1, y=pos.y + 1, z=pos.z + 1},
  193. modname..":mold"
  194. )
  195. if #molds == 0 then
  196. return
  197. end
  198. local mold = molds[math.random(#molds)]
  199. minetest.set_node(mold, {name = modname..":mold_"..opts.name})
  200. minetest.set_node(pos, {name = "air"})
  201. end,
  202. })
  203. minetest.register_craft({
  204. output = modname..":mold 1",
  205. type = "shapeless",
  206. recipe = {
  207. 'default:silver_sand',
  208. opts.ingot
  209. },
  210. replacements = {{opts.ingot, opts.ingot}},
  211. })
  212. end
  213. end -- forge.register_metal
  214. assert(loadfile(modpath .. "/slag.lua"))(forge)
  215. assert(loadfile(modpath .. "/materials.lua"))(forge)
  216. assert(loadfile(modpath .. "/physics.lua"))(cools_to, melt_densities, random_melt_product)
  217. assert(loadfile(modpath .. "/electrode.lua"))(forge, melt_energy_requirement, meltable_ores, random_melt_product)