init.lua 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. local modpath = minetest.get_modpath("bitumen")
  2. bitumen = {}
  3. -- coal = 38
  4. -- crude 44
  5. bitumen.energy_density = {
  6. tar = 20,
  7. heavy_oil = 25,
  8. light_oil = 30,
  9. diesel = 36,
  10. kerosene = 38,
  11. gasoline = 34,
  12. mineral_spirits = 42,
  13. lpg = 45,
  14. ["bitumen:tar"] = 20,
  15. ["bitumen:heavy_oil"] = 25,
  16. ["bitumen:light_oil"] = 30,
  17. ["bitumen:diesel"] = 36,
  18. ["bitumen:kerosene"] = 38,
  19. ["bitumen:gasoline"] = 34,
  20. ["bitumen:mineral_spirits"] = 42,
  21. ["bitumen:lpg"] = 45,
  22. }
  23. -- a coal lump burns for 40 seconds
  24. -- a bitumen:heat burns for 10 seconds
  25. -- multiply the energy density by this factor to find the number of bitumen:heats
  26. bitumen.coal_equivalency = .1
  27. bitumen.fluid_to_heat = function(fluid, amount)
  28. local d = bitumen.energy_density[fluid]
  29. if d == nil then
  30. return 0
  31. end
  32. return bitumen.coal_equivalency * d * amount
  33. end
  34. local function vmin(a, b)
  35. return {
  36. x = math.min(a.x, b.x),
  37. y = math.min(a.y, b.y),
  38. z = math.min(a.z, b.z),
  39. }
  40. end
  41. local function vmax(a, b)
  42. return {
  43. x = math.max(a.x, b.x),
  44. y = math.max(a.y, b.y),
  45. z = math.max(a.z, b.z),
  46. }
  47. end
  48. bitumen.check_foundation = function(p1, p2, accept)
  49. local low = vmin(p1, p2)
  50. local high = vmax(p1, p2)
  51. --print(dump(low) .. "\n" .. dump(high))
  52. for x = low.x, high.x do
  53. for y = low.y, high.y do
  54. for z = low.z, high.z do
  55. local n = minetest.get_node({x=x, y=y, z=z})
  56. if accept[n.name] == nil then
  57. return false
  58. end
  59. end
  60. end
  61. end
  62. return true
  63. end
  64. -- first initialize the internal APIs
  65. dofile(modpath.."/craftitems.lua")
  66. dofile(modpath.."/magic_nodes.lua")
  67. dofile(modpath.."/blueprints.lua")
  68. dofile(modpath.."/pipes.lua")
  69. dofile(modpath.."/burner.lua")
  70. -- dofile(modpath.."/pipeline.lua")
  71. -- next core nodes
  72. dofile(modpath.."/fluids.lua")
  73. dofile(modpath.."/spills.lua")
  74. dofile(modpath.."/concrete.lua")
  75. dofile(modpath.."/vapors.lua")
  76. -- now the kitchen sink
  77. dofile(modpath.."/barrel.lua")
  78. dofile(modpath.."/heater.lua")
  79. dofile(modpath.."/pump.lua")
  80. dofile(modpath.."/oilshale.lua")
  81. dofile(modpath.."/wells.lua")
  82. dofile(modpath.."/cylinder_tank.lua")
  83. dofile(modpath.."/sphere_tank.lua")
  84. dofile(modpath.."/refinery.lua")
  85. dofile(modpath.."/lights.lua")
  86. dofile(modpath.."/rock_crusher.lua")
  87. -----------------------------------
  88. -- --
  89. -- * * * * * LOOK HERE * * * * * --
  90. -- --
  91. -----------------------------------
  92. -- where players should look for information
  93. dofile(modpath.."/crafts.lua")
  94. dofile(modpath.."/ore_gen.lua")
  95. -- completely unrelated experiments:
  96. minetest.register_node("bitumen:glass", {
  97. description = "Glass",
  98. drawtype = "glasslike_framed_optional",
  99. tiles = {"default_glass.png", "default_glass_detail.png"},
  100. special_tiles = {"default_stone.png"},
  101. paramtype = "light",
  102. paramtype2 = "glasslikeliquidlevel",
  103. --param2 = 30;
  104. sunlight_propagates = true,
  105. use_texture_alpha = true,
  106. is_ground_content = false,
  107. groups = {cracky = 3, oddly_breakable_by_hand = 3},
  108. sounds = default.node_sound_glass_defaults(),
  109. on_construct = function(pos)
  110. --local n = minetest.get_node(pos)
  111. --n.param2 = 32
  112. --minetest.set_node_level(pos, 32)
  113. --minetest.swap_node(pos, {name = "bitumen:glass", param2 = 120})
  114. end,
  115. })
  116. -- igore this; test for structure algorithm
  117. local support = {}
  118. minetest.register_abm({
  119. nodenames = {"bitumen:glass"},
  120. interval = 1,
  121. chance = 1,
  122. action = function(pos)
  123. -- minetest.set_node_level(pos, 30)
  124. local sides = {}
  125. local on = minetest.get_node(pos)
  126. local npos = {
  127. {x=pos.x+1, y=pos.y, z=pos.z},
  128. {x=pos.x-1, y=pos.y, z=pos.z},
  129. {x=pos.x, y=pos.y, z=pos.z+1},
  130. {x=pos.x, y=pos.y, z=pos.z-1},
  131. }
  132. pos.y = pos.y - 1
  133. local ym = minetest.get_node(pos)
  134. local sb = support[minetest.hash_node_position(pos)]
  135. pos.y = pos.y + 1
  136. local hash = minetest.hash_node_position(pos)
  137. if ym.name == "air" then
  138. local nb = {}
  139. -- print("air below")
  140. for _,p in ipairs(npos) do
  141. local n = minetest.get_node(p)
  142. nb[n.name] = (nb[n.name] or 0) + 1
  143. end
  144. if (nb["air"] or 0) == 4 then
  145. support[hash] = nil
  146. minetest.spawn_falling_node(pos, on)
  147. return
  148. end
  149. if (nb["bitumen:glass"] or 0) > 0 then
  150. for _,p in ipairs(npos) do
  151. local s = support[minetest.hash_node_position(p)]
  152. if s ~= nil then
  153. print("found support: " .. s)
  154. support[hash] = math.min(support[hash] or 999, s + 1)
  155. end
  156. end
  157. end
  158. if support[hash] == nil or support[hash] > 4 then
  159. support[hash] = nil
  160. minetest.spawn_falling_node(pos, on)
  161. return
  162. end
  163. else
  164. --print("setting support to 0")
  165. support[hash] = sb or 0
  166. end
  167. --minetest.swap_node(pos, {name = "bitumen:glass", param2 = math.random(255)})
  168. end
  169. })
  170. local function get_chest_formspec(pos)
  171. local spos = pos.x .. "," .. pos.y .. "," .. pos.z
  172. local formspec =
  173. "size[14,12]" ..
  174. default.gui_bg ..
  175. default.gui_bg_img ..
  176. default.gui_slots ..
  177. "list[nodemeta:" .. spos .. ";main;0,0.3;14,7;]" ..
  178. "list[current_player;main;3,7.85;8,1;]" ..
  179. "list[current_player;main;3,9.08;8,3;8]" ..
  180. "listring[nodemeta:" .. spos .. ";main]" ..
  181. "listring[current_player;main]" ..
  182. default.get_hotbar_bg(3,7.85)
  183. return formspec
  184. end
  185. minetest.register_node("bitumen:large_chest", {
  186. description = "Large Chest",
  187. drawtype = "nodebox",
  188. tiles = {"default_chest_side.png"},
  189. is_ground_content = false,
  190. groups = {cracky = 2, oddly_breakable_by_hand = 3},
  191. sounds = default.node_sound_glass_defaults(),
  192. on_construct = function(pos)
  193. local meta = minetest.get_meta(pos)
  194. local inv = meta:get_inventory()
  195. inv:set_size("main", 14*7 )
  196. meta:set_string("formspec", get_chest_formspec(pos))
  197. end,
  198. can_dig = function(pos,player)
  199. local meta = minetest.get_meta(pos);
  200. local inv = meta:get_inventory()
  201. return inv:is_empty("main") and
  202. default.can_interact_with_node(player, pos)
  203. end,
  204. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  205. local name = stack:get_name()
  206. local meta = minetest.get_meta(pos)
  207. local minv = meta:get_inventory()
  208. local pinv = player:get_inventory()
  209. local sz = pinv:get_size("main")
  210. for i = 1,sz do
  211. local s = pinv:get_stack("main", i)
  212. if s and s:get_name() == name then
  213. local lo = minv:add_item("main", s)
  214. if lo and lo:get_count() > 0 then
  215. pinv:set_stack("main", i, lo)
  216. break
  217. else
  218. pinv:set_stack("main", i, nil)
  219. end
  220. end
  221. end
  222. end,
  223. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  224. local name = stack:get_name()
  225. local meta = minetest.get_meta(pos)
  226. local minv = meta:get_inventory()
  227. local pinv = player:get_inventory()
  228. local sz = minv:get_size("main")
  229. for i = 1,sz do
  230. local s = minv:get_stack("main", i)
  231. if s and s:get_name() == name then
  232. local lo = pinv:add_item("main", s)
  233. if lo and lo:get_count() > 0 then
  234. minv:set_stack("main", i, lo)
  235. break
  236. else
  237. minv:set_stack("main", i, nil)
  238. end
  239. end
  240. end
  241. end,
  242. })
  243. minetest.register_craft({
  244. output = 'bitumen:large_chest',
  245. recipe = {
  246. {'group:wood', 'group:wood', 'group:wood'},
  247. {'group:wood', 'default:chest', 'group:wood'},
  248. {'group:wood', 'group:wood', 'group:wood'},
  249. }
  250. })