node.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. -- LUALOCALS < ---------------------------------------------------------
  2. local ipairs, minetest, nodecore, pairs, type
  3. = ipairs, minetest, nodecore, pairs, type
  4. -- LUALOCALS > ---------------------------------------------------------
  5. local modname = minetest.get_current_modname()
  6. local function regterrain(def)
  7. def.name = def.name or def.description:gsub("%W", "_"):lower()
  8. def.fullname = modname .. ":" .. def.name
  9. def.tiles = def.tiles or {def.fullname:gsub("%W", "_") .. ".png"}
  10. def.is_ground_content = true
  11. if def.liquidtype then
  12. def.liquid_alternative_flowing = def.fullname .. "_flowing"
  13. def.liquid_alternative_source = def.fullname .. "_source"
  14. def.fullname = def.fullname .. "_" .. def.liquidtype
  15. def.special_tiles = def.special_tiles or {def.tiles[1], def.tiles[1]}
  16. end
  17. def.mapgen = def.mapgen or {def.name}
  18. minetest.register_node(def.fullname, def)
  19. for _, v in pairs(def.mapgen) do
  20. minetest.register_alias("mapgen_" .. v, def.fullname)
  21. end
  22. end
  23. local function clone(t)
  24. local c = minetest.deserialize(minetest.serialize(t))
  25. for k, v in pairs(t) do
  26. if type(v) == "function" then c[k] = v end
  27. end
  28. return c
  29. end
  30. local function regliquid(def)
  31. local t = clone(def)
  32. t.drawtype = "liquid"
  33. t.liquidtype = "source"
  34. regterrain(t)
  35. t = clone(def)
  36. t.mapgen = {}
  37. t.drawtype = "flowingliquid"
  38. t.liquidtype = "flowing"
  39. t.paramtype2 = "flowingliquid"
  40. t.buildable_to = true
  41. regterrain(t)
  42. end
  43. --[[
  44. STONE GROUPS:
  45. rock: all rocky/stony things, including stone, cobble, brick, etc.
  46. stone: variants of smooth stone, including ones with inclusions (ore).
  47. hard_stone: deeper strata that trigger the hint.
  48. smoothstone: smooth stone that can be chiseled to bricks.
  49. --]]
  50. local strata = {}
  51. regterrain({
  52. description = "Stone",
  53. mapgen = {
  54. "stone",
  55. "stone_with_coal",
  56. "stone_with_iron",
  57. "desert_stone",
  58. "sandstone",
  59. "mese",
  60. },
  61. groups = {
  62. stone = 1,
  63. rock = 1,
  64. smoothstone = 1,
  65. cracky = 2
  66. },
  67. drop_in_place = modname .. ":cobble",
  68. strata = strata,
  69. sounds = nodecore.sounds("nc_terrain_stony")
  70. })
  71. strata[1] = modname .. ":stone"
  72. for i = 1, nodecore.hard_stone_strata do
  73. regterrain({
  74. name = "hard_stone_" .. i,
  75. description = "Stone",
  76. tiles = {nodecore.hard_stone_tile(i)},
  77. silktouch = false,
  78. groups = {
  79. stone = i + 1,
  80. rock = i,
  81. cracky = i + 2,
  82. hard_stone = i
  83. },
  84. drop_in_place = modname .. ((i > 1)
  85. and (":hard_stone_" .. (i - 1)) or ":stone"),
  86. sounds = nodecore.sounds("nc_terrain_stony")
  87. })
  88. strata[i + 1] = modname .. ":hard_stone_" .. i
  89. end
  90. regterrain({
  91. description = "Cobble",
  92. tiles = {modname .. "_gravel.png^" .. modname .. "_cobble.png"},
  93. mapgen = {
  94. "sandstonebrick",
  95. "stair_sandstone_block",
  96. "cobble",
  97. "stair_cobble",
  98. "stair_desert_stone",
  99. "mossycobble"
  100. },
  101. groups = {
  102. cobble = 1,
  103. rock = 1,
  104. cracky = 1,
  105. cobbley = 1
  106. },
  107. alternate_loose = {
  108. repack_level = 2,
  109. groups = {
  110. cracky = 0,
  111. crumbly = 2,
  112. falling_repose = 3
  113. },
  114. sounds = nodecore.sounds("nc_terrain_chompy")
  115. },
  116. crush_damage = 2,
  117. sounds = nodecore.sounds("nc_terrain_stony")
  118. })
  119. for _, v in ipairs({
  120. "snow",
  121. "snowblock",
  122. "junglegrass",
  123. "tree",
  124. "jungletree",
  125. "pine_tree",
  126. "leaves",
  127. "apple",
  128. "jungleleaves",
  129. "pine_needles"
  130. }) do
  131. minetest.register_alias("mapgen_" .. v, "air")
  132. end
  133. regterrain({
  134. description = "Dirt",
  135. alternate_loose = {
  136. groups = {
  137. dirt_loose = 1,
  138. falling_repose = 2,
  139. soil = 2,
  140. grassable = 1
  141. }
  142. },
  143. mapgen = {
  144. "dirt",
  145. "ice",
  146. },
  147. groups = {
  148. dirt = 1,
  149. crumbly = 1,
  150. soil = 1,
  151. grassable = 1
  152. },
  153. crush_damage = 1,
  154. sounds = nodecore.sounds("nc_terrain_crunchy")
  155. })
  156. regterrain({
  157. name = "dirt_with_grass",
  158. description = "Grass",
  159. tiles = {
  160. modname .. "_grass_top.png",
  161. modname .. "_dirt.png",
  162. modname .. "_dirt.png^(" .. modname .. "_grass_top.png^[mask:"
  163. .. modname .. "_grass_sidemask.png)"
  164. },
  165. mapgen = {
  166. "dirt_with_grass",
  167. "dirt_with_snow"
  168. },
  169. groups = {
  170. crumbly = 2,
  171. soil = 1,
  172. green = 1
  173. },
  174. drop_in_place = modname .. ":dirt",
  175. sounds = nodecore.sounds("nc_terrain_grassy")
  176. })
  177. regterrain({
  178. description = "Gravel",
  179. alternate_loose = {
  180. groups = {
  181. crumbly = 2,
  182. falling_repose = 2
  183. }
  184. },
  185. groups = {
  186. gravel = 1,
  187. crumbly = 1,
  188. falling_node = 1
  189. },
  190. crush_damage = 1,
  191. sounds = nodecore.sounds("nc_terrain_chompy")
  192. })
  193. regterrain({
  194. description = "Sand",
  195. alternate_loose = {
  196. groups = {
  197. falling_repose = 1
  198. }
  199. },
  200. groups = {
  201. sand = 1,
  202. crumbly = 1,
  203. falling_node = 1
  204. },
  205. mapgen = {
  206. "sand",
  207. "clay",
  208. "desert_sand"
  209. },
  210. crush_damage = 0.5,
  211. sounds = nodecore.sounds("nc_terrain_swishy")
  212. })
  213. local function anim(name, len)
  214. return {
  215. name = name,
  216. animation = {
  217. type = "vertical_frames",
  218. aspect_w = 16,
  219. aspect_h = 16,
  220. length = len
  221. }
  222. }
  223. end
  224. local function gray(suff)
  225. local t = modname .. "_water" .. suff .. ".png"
  226. local g = modname .. "_water_gray" .. suff .. ".png"
  227. return t .. "^(" .. g .. "^[opacity:64)"
  228. end
  229. regliquid({
  230. description = "Water",
  231. mapgen = {"river_water_source", "water_source"},
  232. tiles = {anim(modname .. "_water.png", 4)},
  233. special_tiles = {
  234. anim(modname .. "_water_flow.png", 4),
  235. anim(modname .. "_water_flow.png", 4)
  236. },
  237. paramtype = "light",
  238. liquid_viscosity = 1,
  239. liquid_renewable = true,
  240. alpha = 192,
  241. walkable = false,
  242. pointable = false,
  243. buildable_to = true,
  244. drowning = 2,
  245. drop = "",
  246. groups = {coolant = 1, water = 2, moist = 2},
  247. post_effect_color = {a = 103, r = 30, g = 76, b = 90},
  248. sounds = nodecore.sounds("nc_terrain_watery")
  249. })
  250. regliquid({
  251. name = "water_gray",
  252. description = "Water",
  253. tiles = {anim(gray(""), 4)},
  254. special_tiles = {
  255. anim(gray("_flow"), 4),
  256. anim(gray("_flow"), 4)
  257. },
  258. paramtype = "light",
  259. liquid_viscosity = 1,
  260. liquid_renewable = false,
  261. alpha = 160,
  262. walkable = false,
  263. pointable = false,
  264. buildable_to = true,
  265. drowning = 2,
  266. drop = "",
  267. groups = {coolant = 1, water = 2, moist = 2},
  268. post_effect_color = {a = 103, r = 91, g = 97, b = 103},
  269. sounds = nodecore.sounds("nc_terrain_watery")
  270. })
  271. regliquid({
  272. name = "lava",
  273. tiles = {anim(modname .. "_lava.png", 8)},
  274. special_tiles = {
  275. anim(modname .. "_lava_flow.png", 8),
  276. anim(modname .. "_lava_flow.png", 8)
  277. },
  278. description = "Pumwater",
  279. mapgen = {"lava_source"},
  280. paramtype = "light",
  281. liquid_viscosity = 7,
  282. liquid_renewable = false,
  283. light_source = 13,
  284. walkable = false,
  285. drowning = 2,
  286. damage_per_second = 8,
  287. drop = "",
  288. groups = {
  289. igniter = 1,
  290. lava = 2,
  291. stack_as_node = 1,
  292. damage_touch = 1,
  293. damage_radiant = 8
  294. },
  295. stack_max = 1,
  296. post_effect_color = {a = 240, r = 255, g = 64, b = 0},
  297. sounds = nodecore.sounds("nc_terrain_bubbly")
  298. })