nodes.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. -- Code by Mossmanikin & Neuromancer
  2. -- support for i18n
  3. local S = minetest.get_translator("trunks")
  4. -----------------------------------------------------------------------------------------------
  5. -- TWiGS
  6. -----------------------------------------------------------------------------------------------
  7. -- For compatibility with older stuff
  8. minetest.register_alias("trunks:twig", "trunks:twig_1")
  9. local flat_stick = {-1/2, -1/2, -1/2, 1/2, -7/16, 1/2}
  10. local NoDe = { {1}, {2}, {3}, {4}, {5}, --[[{6},]] {7}, {8}, {9}, {10}, {11}, {12}, {13} }
  11. for i in pairs(NoDe) do
  12. local NR = NoDe[i][1]
  13. local iNV = NR - 1
  14. minetest.register_node("trunks:twig_"..NR, {
  15. description = S("Twig"),
  16. inventory_image = "trunks_twig_"..NR..".png",
  17. wield_image = "trunks_twig_"..NR..".png",
  18. drawtype = "nodebox",
  19. tiles = {
  20. "trunks_twig_"..NR..".png",
  21. "trunks_twig_"..NR..".png^[transformFY", -- mirror
  22. "trunks_twig_6.png" -- empty
  23. },
  24. paramtype = "light",
  25. paramtype2 = "facedir",
  26. walkable = false,
  27. sunlight_propagates = true,
  28. buildable_to = true,
  29. node_box = {type = "fixed", fixed = flat_stick},
  30. groups = {
  31. choppy=2,
  32. oddly_breakable_by_hand=2,
  33. flammable=3,
  34. attached_node=1,
  35. not_in_creative_inventory=iNV
  36. },
  37. drop = "trunks:twig_1",
  38. sounds = default.node_sound_leaves_defaults(),
  39. liquids_pointable = true,
  40. on_place = function(itemstack, placer, pointed_thing)
  41. local pt = pointed_thing
  42. if not placer then return end
  43. local playername = placer:get_player_name()
  44. if minetest.is_protected(pt.above, playername) then
  45. minetest.record_protection_violation(pt.above, playername)
  46. return
  47. end
  48. local direction = minetest.dir_to_facedir(placer:get_look_dir())
  49. if minetest.get_node(pt.above).name=="air" then
  50. minetest.swap_node(pt.above, {name="trunks:twig_"..math.random(1,4), param2=direction})
  51. if not minetest.setting_getbool("creative_mode") then
  52. itemstack:take_item()
  53. end
  54. return itemstack
  55. end
  56. end,
  57. })
  58. end
  59. -----------------------------------------------------------------------------------------------
  60. -- MoSS
  61. -----------------------------------------------------------------------------------------------
  62. local flat_moss = {-1/2, -1/2, -1/2, 1/2, -15/32--[[<-flickers if smaller]], 1/2}
  63. minetest.register_node("trunks:moss", {
  64. description = S("Moss"),
  65. drawtype = "nodebox",--"signlike",
  66. tiles = {"trunks_moss.png"},
  67. inventory_image = "trunks_moss.png",
  68. wield_image = "trunks_moss.png",
  69. paramtype = "light",
  70. paramtype2 = "facedir",--"wallmounted",
  71. sunlight_propagates = true,
  72. walkable = false,
  73. node_box = {type = "fixed", fixed = flat_moss},
  74. selection_box = {type = "fixed", fixed = flat_stick},--{type = "wallmounted"},
  75. groups = {snappy = 3, flammable = 3 },
  76. sounds = default.node_sound_leaves_defaults(),
  77. })
  78. -----------------------------------------------------------------------------------------------
  79. -- MoSS & FuNGuS
  80. -----------------------------------------------------------------------------------------------
  81. minetest.register_node("trunks:moss_fungus", {
  82. description = S("Moss with Fungus"),
  83. drawtype = "nodebox",--"signlike",
  84. tiles = {"trunks_moss_fungus.png"},
  85. inventory_image = "trunks_moss_fungus.png",
  86. wield_image = "trunks_moss_fungus.png",
  87. paramtype = "light",
  88. paramtype2 = "facedir",--"wallmounted",
  89. sunlight_propagates = true,
  90. walkable = false,
  91. node_box = {type = "fixed", fixed = flat_moss},
  92. selection_box = {type = "fixed", fixed = flat_stick},--{type = "wallmounted"},
  93. groups = {snappy = 3, flammable = 3 },
  94. sounds = default.node_sound_leaves_defaults(),
  95. })
  96. -----------------------------------------------------------------------------------------------
  97. -- TWiGS BLoCK
  98. -----------------------------------------------------------------------------------------------
  99. minetest.register_alias("woodstuff:twigs", "trunks:twigs")
  100. minetest.register_node("trunks:twigs", {
  101. description = S("Twigs Block"),
  102. paramtype2 = "facedir",
  103. tiles = {"trunks_twigs.png"},
  104. groups = {choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1},
  105. sounds = default.node_sound_wood_defaults(),
  106. })
  107. -----------------------------------------------------------------------------------------------
  108. -- TWiGS SLaB
  109. -----------------------------------------------------------------------------------------------
  110. minetest.register_alias("woodstuff:twigs_slab", "trunks:twigs_slab")
  111. minetest.register_node("trunks:twigs_slab", {
  112. description = S("Twigs Slab"),
  113. drawtype = "nodebox",
  114. paramtype = "light",
  115. paramtype2 = "facedir",
  116. tiles = {"trunks_twigs.png"},
  117. node_box = {
  118. type = "fixed",
  119. fixed = {-1/2, -1/2, -1/2, 1/2, 0, 1/2},
  120. },
  121. groups = {choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1},
  122. sounds = default.node_sound_wood_defaults(),
  123. })
  124. -----------------------------------------------------------------------------------------------
  125. -- TWiGS RooF
  126. -----------------------------------------------------------------------------------------------
  127. minetest.register_alias("woodstuff:twigs_roof", "trunks:twigs_roof")
  128. minetest.register_node("trunks:twigs_roof", {
  129. description = S("Twigs Roof"),
  130. drawtype = "nodebox",
  131. paramtype = "light",
  132. paramtype2 = "facedir",
  133. tiles = {"trunks_twigs.png"},
  134. node_box = {
  135. type = "fixed",
  136. -- { left, bottom, front, right, top, back }
  137. fixed = {
  138. {-1/2, 0, 0, 1/2, 1/2, 1/2},
  139. {-1/2, -1/2, -1/2, 1/2, 0, 0},
  140. }
  141. },
  142. groups = {choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1},
  143. sounds = default.node_sound_wood_defaults(),
  144. })
  145. -----------------------------------------------------------------------------------------------
  146. -- TWiGS RooF CoRNeR
  147. -----------------------------------------------------------------------------------------------
  148. minetest.register_alias("woodstuff:twigs_roof_corner", "trunks:twigs_roof_corner")
  149. minetest.register_node("trunks:twigs_roof_corner", {
  150. description = S("Twigs Roof Corner 1"),
  151. drawtype = "nodebox",
  152. paramtype = "light",
  153. paramtype2 = "facedir",
  154. tiles = {
  155. "trunks_twigs_corner.png",
  156. "trunks_twigs_corner.png",
  157. "trunks_twigs.png"
  158. },
  159. node_box = {
  160. type = "fixed",
  161. -- { left, bottom, front, right, top, back }
  162. fixed = {
  163. {-1/2, 0, 0, 0, 1/2, 1/2},
  164. {0, -1/2, 0, 1/2, 0, 1/2},
  165. {-1/2, -1/2, -1/2, 0, 0, 0},
  166. }
  167. },
  168. groups = {choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1},
  169. sounds = default.node_sound_wood_defaults(),
  170. })
  171. -----------------------------------------------------------------------------------------------
  172. -- TWiGS RooF CoRNeR 2
  173. -----------------------------------------------------------------------------------------------
  174. minetest.register_alias("woodstuff:twigs_roof_corner_2", "trunks:twigs_roof_corner_2")
  175. minetest.register_node("trunks:twigs_roof_corner_2", {
  176. description = S("Twigs Roof Corner 2"),
  177. drawtype = "nodebox",
  178. paramtype = "light",
  179. paramtype2 = "facedir",
  180. tiles = {
  181. "trunks_twigs_corner.png",
  182. "trunks_twigs_corner.png",
  183. "trunks_twigs.png"
  184. },
  185. node_box = {
  186. type = "fixed",
  187. -- { left, bottom, front, right, top, back }
  188. fixed = {
  189. {-1/2, -1/2, 0, 0, 0, 1/2},
  190. {0, 0, 0, 1/2, 1/2, 1/2},
  191. {-1/2, 0, -1/2, 0, 1/2, 0},
  192. }
  193. },
  194. groups = {choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1},
  195. sounds = default.node_sound_wood_defaults(),
  196. })
  197. if Auto_Roof_Corner == true then
  198. local roof = "trunks:twigs_roof"
  199. local corner = "trunks:twigs_roof_corner"
  200. local corner_2 = "trunks:twigs_roof_corner_2"
  201. minetest.register_abm({
  202. nodenames = {roof},
  203. interval = 1,
  204. chance = 1,
  205. action = function(pos)
  206. local node_east = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z })
  207. local node_west = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z })
  208. local node_north = minetest.get_node({x=pos.x, y=pos.y, z=pos.z+1})
  209. local node_south = minetest.get_node({x=pos.x, y=pos.y, z=pos.z-1})
  210. -- corner 1
  211. if ((node_west.name == roof and node_west.param2 == 0)
  212. or (node_west.name == corner and node_west.param2 == 1))
  213. and ((node_north.name == roof and node_north.param2 == 3)
  214. or (node_north.name == corner and node_north.param2 == 3))
  215. then
  216. minetest.swap_node(pos, {name=corner, param2=0})
  217. end
  218. if ((node_north.name == roof and node_north.param2 == 1)
  219. or (node_north.name == corner and node_north.param2 == 2))
  220. and ((node_east.name == roof and node_east.param2 == 0)
  221. or (node_east.name == corner and node_east.param2 == 0))
  222. then
  223. minetest.swap_node(pos, {name=corner, param2=1})
  224. end
  225. if ((node_east.name == roof and node_east.param2 == 2)
  226. or (node_east.name == corner and node_east.param2 == 3))
  227. and ((node_south.name == roof and node_south.param2 == 1)
  228. or (node_south.name == corner and node_south.param2 == 1))
  229. then
  230. minetest.swap_node(pos, {name=corner, param2=2})
  231. end
  232. if ((node_south.name == roof and node_south.param2 == 3)
  233. or (node_south.name == corner and node_south.param2 == 0))
  234. and ((node_west.name == roof and node_west.param2 == 2)
  235. or (node_west.name == corner and node_west.param2 == 2))
  236. then
  237. minetest.swap_node(pos, {name=corner, param2=3})
  238. end
  239. -- corner 2
  240. if ((node_west.name == roof and node_west.param2 == 2)
  241. or (node_west.name == corner_2 and node_west.param2 == 1))
  242. and ((node_north.name == roof and node_north.param2 == 1)
  243. or (node_north.name == corner_2 and node_north.param2 == 3))
  244. then
  245. minetest.swap_node(pos, {name=corner_2, param2=0})
  246. end
  247. if ((node_north.name == roof and node_north.param2 == 3)
  248. or (node_north.name == corner_2 and node_north.param2 == 2))
  249. and ((node_east.name == roof and node_east.param2 == 2)
  250. or (node_east.name == corner_2 and node_east.param2 == 0))
  251. then
  252. minetest.swap_node(pos, {name=corner_2, param2=1})
  253. end
  254. if ((node_east.name == roof and node_east.param2 == 0)
  255. or (node_east.name == corner_2 and node_east.param2 == 3))
  256. and ((node_south.name == roof and node_south.param2 == 3)
  257. or (node_south.name == corner_2 and node_south.param2 == 1))
  258. then
  259. minetest.swap_node(pos, {name=corner_2, param2=2})
  260. end
  261. if ((node_south.name == roof and node_south.param2 == 1)
  262. or (node_south.name == corner_2 and node_south.param2 == 0))
  263. and ((node_west.name == roof and node_west.param2 == 0)
  264. or (node_west.name == corner_2 and node_west.param2 == 2))
  265. then
  266. minetest.swap_node(pos, {name=corner_2, param2=3})
  267. end
  268. end,
  269. })
  270. end
  271. -- MM: The following stuff is just for testing purposes for now; no generating of roots.
  272. -- I'm not satisfied with this; they should be either bigger or a different drawtype.
  273. -----------------------------------------------------------------------------------------------
  274. -- RooTS
  275. -----------------------------------------------------------------------------------------------
  276. if Roots == true then -- see settings.txt
  277. local roots_cube = {-2/16, -1/2, -3/16, 2/16, 1/16, 1/2}
  278. local roots_sheet = {0, -1/2, -1/2, 0, 1/16, 1/2}
  279. local TRuNKS = {
  280. -- MoD TRuNK
  281. {"default", "tree" },
  282. {"default", "jungletree" },
  283. {"default", "pine_tree" },
  284. {"trees", "tree_conifer" },
  285. {"trees", "tree_mangrove" },
  286. {"trees", "tree_palm" },
  287. {"moretrees", "apple_tree_trunk" },
  288. {"moretrees", "beech_trunk" },
  289. {"moretrees", "birch_trunk" },
  290. {"moretrees", "fir_trunk" },
  291. {"moretrees", "oak_trunk" },
  292. {"moretrees", "palm_trunk" },
  293. {"moretrees", "rubber_tree_trunk" },
  294. {"moretrees", "rubber_tree_trunk_empty" },
  295. {"moretrees", "sequoia_trunk" },
  296. {"moretrees", "spruce_trunk" },
  297. {"moretrees", "willow_trunk" },
  298. }
  299. for i in pairs(TRuNKS) do
  300. local MoD = TRuNKS[i][1]
  301. local TRuNK = TRuNKS[i][2]
  302. if minetest.get_modpath(MoD) ~= nil then
  303. local node = minetest.registered_nodes[MoD..":"..TRuNK]
  304. if node then
  305. local des = node.description
  306. minetest.register_node("trunks:"..TRuNK.."root", {
  307. description = S("@1 Root", des),
  308. paramtype = "light",
  309. paramtype2 = "facedir",
  310. tiles = {
  311. --[[top]] MoD.."_"..TRuNK..".png",
  312. --[[bottom]] MoD.."_"..TRuNK..".png",
  313. --[[right]] MoD.."_"..TRuNK..".png^trunks_root_mask.png^[makealpha:0,0,0",
  314. --[[left]] MoD.."_"..TRuNK..".png^trunks_root_mask.png^[transformFX^[makealpha:0,0,0",
  315. --[[back]] MoD.."_"..TRuNK..".png",
  316. --[[front]] MoD.."_"..TRuNK..".png"
  317. },
  318. drawtype = "nodebox",
  319. selection_box = {type = "fixed", fixed = roots_cube},
  320. node_box = {type = "fixed", fixed = roots_sheet},
  321. groups = {
  322. tree=1,
  323. snappy=1,
  324. choppy=2,
  325. oddly_breakable_by_hand=1,
  326. flammable=2--,
  327. --not_in_creative_inventory=1 -- atm in inv for testing
  328. },
  329. --drop = "trunks:twig_1", -- not sure about this yet
  330. sounds = default.node_sound_wood_defaults(),
  331. })
  332. else
  333. minetest.log("error", string.format("[Trunks] warning: tree type '%s:%s' not found", MoD, TRuNK))
  334. end
  335. end
  336. end
  337. end
  338. minetest.register_alias("trunks:pine_trunkroot", "trunks:pine_treeroot")