init.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. local override_original = false --change to "true" if you want original and placed fences replaced
  2. local function dockable(nodename)
  3. if nodename == "default:wood" or nodename == "default:brick" or nodename == "default:cobble" or nodename == "default:dirt" or nodename == "default:sandstone" or nodename == "default:stone" or string.find(nodename, "fences:fence_wood") or string.find(nodename, "fences:fencegate") then
  4. return true
  5. end
  6. end
  7. local function find_dock(pos, second)
  8. if pos == nil then
  9. return false
  10. end
  11. local h1 = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z})
  12. local v1 = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z})
  13. local r1 = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z+1})
  14. local l1 = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z-1})
  15. local code = 0
  16. if dockable(l1.name) then
  17. code = code+1
  18. if second < 2 then
  19. minetest.env:punch_node({x=pos.x, y=pos.y, z=pos.z-1})
  20. end
  21. end
  22. if dockable(r1.name) then
  23. code = code+2
  24. if second < 2 then
  25. minetest.env:punch_node({x=pos.x, y=pos.y, z=pos.z+1})
  26. end
  27. end
  28. if dockable(v1.name) then
  29. code = code+11
  30. if second < 2 then
  31. minetest.env:punch_node({x=pos.x-1, y=pos.y, z=pos.z})
  32. end
  33. end
  34. if dockable(h1.name) then
  35. code = code+21
  36. if second < 2 then
  37. minetest.env:punch_node({x=pos.x+1, y=pos.y, z=pos.z})
  38. end
  39. end
  40. local me = minetest.env:get_node(pos)
  41. if code > 0 then
  42. local tmp_name = "fences:fence_wood_"..code
  43. --minetest.chat_send_all(tmp_name)
  44. local tmp_node = {name=tmp_name, param1=me.param1, param2=me.param2}
  45. if second > 0 then
  46. local tmp_node = {name=tmp_name, param1=me.param1, param2=me.param2}
  47. minetest.env:set_node(pos, tmp_node)
  48. end
  49. elseif code == 0 then
  50. if second == 2 then
  51. local tmp_node = {name="fences:fence_wood", param1=me.param1, param2=me.param2}
  52. minetest.env:set_node(pos, tmp_node)
  53. end
  54. end
  55. end
  56. local function punch(pos, puncher)
  57. if not puncher ~= '' then
  58. find_dock(pos, 2)
  59. elseif not puncher:is_player() then
  60. find_dock(pos, 2)
  61. end
  62. end
  63. local p0 = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16}
  64. local p1 = {-2/16, 1/2, -2/16, -2/16, 1/2+8/16, -2/16}
  65. local p2 = {-2/16, 1/2, 2/16, -2/16, 1/2+8/16, 2/16}
  66. local p4 = {2/16, 1/2, -2/16, 2/16, 1/2+8/16, -2/16}
  67. local p5 = {2/16, 1/2, 2/16, 2/16, 1/2+8/16, 2/16}
  68. local x1 = {-2/16, 1/2-4/16, 1/16, -1/2, 1/2-1/16, -1/16} --oben(quer) -x
  69. local x12 = {-2/16, -1/2+6/16, 1/16, -1/2, -1/2+9/16, -1/16} --unten(quer) -x
  70. local x2 = {2/16, 1/2-4/16, -1/16, 1/2, 1/2-1/16, 1/16} --oben(quer) x
  71. local x22 = {2/16, -1/2+6/16, -1/16, 1/2, -1/2+9/16, 1/16} --unten(quer) x
  72. local z1 = {1/16, 1/2-4/16, -2/16, -1/16, 1/2-1/16, -1/2} --oben(quer) -z
  73. local z12 = {1/16, -1/2+6/16, -2/16, -1/16, -1/2+9/16, -1/2} --unten(quer) -z
  74. local z2 = {-1/16, 1/2-4/16, 2/16, 1/16, 1/2-1/16, 1/2} --oben(quer) z
  75. local z22 = {-1/16, -1/2+6/16, 2/16, 1/16, -1/2+9/16, 1/2} --unten(quer) z
  76. local bz1 = {1/16, 1/2-1/16, -6/16, 1/16, 1/2+8/16, -6/16} --oben_block(quer) -z 1seite
  77. local bz11 = {-1/16, 1/2-1/16, -6/16, -1/16, 1/2+8/16, -6/16} --oben_block(quer) -z 2seite
  78. local bz2 = {1/16, 1/2-1/16, 5/16, 1/16, 1/2+8/16, 5/16} --oben_block(quer) z 1seite
  79. local bz21 = {-1/16, 1/2-1/16, 5/16, -1/16, 1/2+8/16, 5/16} --oben_block(quer) z 2seite
  80. local bx1 = {-6/16, 1/2-1/16, 1/16, -6/16, 1/2+8/16, 1/16} --oben_block(quer) -x 1seite
  81. local bx11 = {-6/16, 1/2-1/16, -1/16, -6/16, 1/2+8/16, -1/16} --oben_block(quer) -x 2seite
  82. local bx2 = {5/16, 1/2-1/16, 1/16, 5/16, 1/2+8/16, 1/16} --oben_block(quer) x 1seite
  83. local bx21 = {5/16, 1/2-1/16, -1/16, 5/16, 1/2+8/16, -1/16} --oben_block(quer) x 2seite
  84. minetest.register_node("fences:fence_wood", {
  85. description = "Wooden Fence",
  86. tiles = {"default_wood.png"},
  87. inventory_image = "default_fence.png",
  88. wield_image = "default_fence.png",
  89. paramtype = "light",
  90. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1},
  91. drop = 'fences:fence_wood',
  92. sunlight_propagates = true,
  93. drawtype = "nodebox",
  94. node_box = {
  95. type = "fixed",
  96. fixed = {p0,p1,p2,p3,p4,p5,}
  97. },
  98. selection_box = {
  99. type = "fixed",
  100. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  101. },
  102. on_construct = function(pos)
  103. find_dock(pos, 1)
  104. end,
  105. on_punch = function(pos, puncher)
  106. punch(pos, puncher)
  107. end,
  108. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  109. find_dock(pos, -1)
  110. end
  111. })
  112. --different fence types- (1=left,2=right,3=top,4=bottom)
  113. minetest.register_node("fences:fence_wood_1", {
  114. tiles = {"default_wood.png"},
  115. paramtype = "light",
  116. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  117. drop = 'fences:fence_wood',
  118. sunlight_propagates = true,
  119. sounds = default.node_sound_wood_defaults(),
  120. drawtype = "nodebox",
  121. node_box = {
  122. type = "fixed",
  123. fixed = {
  124. p0,p1,p2,p3,p4,p5,
  125. z1,z12,
  126. bz1,bz11,
  127. }
  128. },
  129. selection_box = {
  130. type = "fixed",
  131. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  132. },
  133. on_punch = function(pos, puncher)
  134. punch(pos, puncher)
  135. end,
  136. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  137. find_dock(pos, -1)
  138. end
  139. })
  140. minetest.register_node("fences:fence_wood_2", {
  141. tiles = {"default_wood.png"},
  142. paramtype = "light",
  143. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  144. drop = 'fences:fence_wood',
  145. sunlight_propagates = true,
  146. sounds = default.node_sound_wood_defaults(),
  147. drawtype = "nodebox",
  148. node_box = {
  149. type = "fixed",
  150. fixed = {
  151. p0,p1,p2,p3,p4,p5,
  152. z2,z22,
  153. bz2,bz21,
  154. }
  155. },
  156. selection_box = {
  157. type = "fixed",
  158. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  159. },
  160. on_punch = function(pos, puncher)
  161. punch(pos, puncher)
  162. end,
  163. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  164. find_dock(pos, -1)
  165. end
  166. })
  167. minetest.register_node("fences:fence_wood_3", { --left+right(3)
  168. tiles = {"default_wood.png"},
  169. paramtype = "light",
  170. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  171. drop = 'fences:fence_wood',
  172. sunlight_propagates = true,
  173. sounds = default.node_sound_wood_defaults(),
  174. drawtype = "nodebox",
  175. node_box = {
  176. type = "fixed",
  177. fixed = {
  178. p0,p1,p2,p3,p4,p5,
  179. z1,z12,z2,z22,
  180. bz1,bz11,bz2,bz21,
  181. }
  182. },
  183. selection_box = {
  184. type = "fixed",
  185. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  186. },
  187. on_punch = function(pos, puncher)
  188. punch(pos, puncher)
  189. end,
  190. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  191. find_dock(pos, -1)
  192. end
  193. })
  194. minetest.register_node("fences:fence_wood_11", { --top
  195. tiles = {"default_wood.png"},
  196. paramtype = "light",
  197. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  198. drop = 'fences:fence_wood',
  199. sunlight_propagates = true,
  200. sounds = default.node_sound_wood_defaults(),
  201. drawtype = "nodebox",
  202. node_box = {
  203. type = "fixed",
  204. fixed = {
  205. p0,p1,p2,p3,p4,p5,
  206. x1,x12,
  207. bx1,bx11,
  208. }
  209. },
  210. selection_box = {
  211. type = "fixed",
  212. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  213. },
  214. on_punch = function(pos, puncher)
  215. punch(pos, puncher)
  216. end,
  217. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  218. find_dock(pos, -1)
  219. end
  220. })
  221. minetest.register_node("fences:fence_wood_21", { --bottom
  222. tiles = {"default_wood.png"},
  223. paramtype = "light",
  224. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  225. drop = 'fences:fence_wood',
  226. sunlight_propagates = true,
  227. sounds = default.node_sound_wood_defaults(),
  228. drawtype = "nodebox",
  229. node_box = {
  230. type = "fixed",
  231. fixed = {
  232. p0,p1,p2,p3,p4,p5,
  233. x2,x22,
  234. bx2,bx21,
  235. }
  236. },
  237. selection_box = {
  238. type = "fixed",
  239. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  240. },
  241. on_punch = function(pos, puncher)
  242. punch(pos, puncher)
  243. end,
  244. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  245. find_dock(pos, -1)
  246. end
  247. })
  248. minetest.register_node("fences:fence_wood_32", { --top+bottom(32)
  249. tiles = {"default_wood.png"},
  250. paramtype = "light",
  251. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  252. drop = 'fences:fence_wood',
  253. sunlight_propagates = true,
  254. sounds = default.node_sound_wood_defaults(),
  255. drawtype = "nodebox",
  256. node_box = {
  257. type = "fixed",
  258. fixed = {
  259. p0,p1,p2,p3,p4,p5,
  260. x1,x12,x2,x22,
  261. bx1,bx11,bx2,bx21,
  262. }
  263. },
  264. selection_box = {
  265. type = "fixed",
  266. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  267. },
  268. on_punch = function(pos, puncher)
  269. punch(pos, puncher)
  270. end,
  271. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  272. find_dock(pos, -1)
  273. end
  274. })
  275. minetest.register_node("fences:fence_wood_14", { --left+right(3)+ top(11) =14
  276. tiles = {"default_wood.png"},
  277. paramtype = "light",
  278. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  279. drop = 'fences:fence_wood',
  280. sunlight_propagates = true,
  281. sounds = default.node_sound_wood_defaults(),
  282. drawtype = "nodebox",
  283. node_box = {
  284. type = "fixed",
  285. fixed = {
  286. p0,p1,p2,p3,p4,p5,
  287. z1,z12,z2,z22,x1,x12,
  288. bz1,bz11,bz2,bz21,bx1,bx11,
  289. }
  290. },
  291. selection_box = {
  292. type = "fixed",
  293. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  294. },
  295. on_punch = function(pos, puncher)
  296. punch(pos, puncher)
  297. end,
  298. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  299. find_dock(pos, -1)
  300. end
  301. })
  302. minetest.register_node("fences:fence_wood_24", { --left+right(3)+ bottom(21) =24
  303. tiles = {"default_wood.png"},
  304. paramtype = "light",
  305. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  306. drop = 'fences:fence_wood',
  307. sunlight_propagates = true,
  308. sounds = default.node_sound_wood_defaults(),
  309. drawtype = "nodebox",
  310. node_box = {
  311. type = "fixed",
  312. fixed = {
  313. p0,p1,p2,p3,p4,p5,
  314. z1,z12,z2,z22,x2,x22,
  315. bz1,bz11,bz2,bz21,bx2,bx21,
  316. }
  317. },
  318. selection_box = {
  319. type = "fixed",
  320. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  321. },
  322. on_punch = function(pos, puncher)
  323. punch(pos, puncher)
  324. end,
  325. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  326. find_dock(pos, -1)
  327. end
  328. })
  329. minetest.register_node("fences:fence_wood_35", { --left+right(3)+top+bottom(32) = 35
  330. tiles = {"default_wood.png"},
  331. paramtype = "light",
  332. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  333. drop = 'fences:fence_wood',
  334. sunlight_propagates = true,
  335. sounds = default.node_sound_wood_defaults(),
  336. drawtype = "nodebox",
  337. node_box = {
  338. type = "fixed",
  339. fixed = {
  340. p0,p1,p2,p3,p4,p5,
  341. x1,x12,x2,x22,z1,z12,z2,z22,
  342. bz1,bz11,bz2,bz21,bx1,bx11,bx2,bx21,
  343. }
  344. },
  345. selection_box = {
  346. type = "fixed",
  347. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  348. },
  349. on_punch = function(pos, puncher)
  350. punch(pos, puncher)
  351. end,
  352. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  353. find_dock(pos, -1)
  354. end
  355. })
  356. minetest.register_node("fences:fence_wood_12", { --left(1)+top(11)=12
  357. tiles = {"default_wood.png"},
  358. paramtype = "light",
  359. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  360. drop = 'fences:fence_wood',
  361. sunlight_propagates = true,
  362. sounds = default.node_sound_wood_defaults(),
  363. drawtype = "nodebox",
  364. node_box = {
  365. type = "fixed",
  366. fixed = {
  367. p0,p1,p2,p3,p4,p5,
  368. z1,z12,x1,x12,
  369. bz1,bz11,bx1,bx11,
  370. }
  371. },
  372. selection_box = {
  373. type = "fixed",
  374. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  375. },
  376. on_punch = function(pos, puncher)
  377. punch(pos, puncher)
  378. end,
  379. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  380. find_dock(pos, -1)
  381. end
  382. })
  383. minetest.register_node("fences:fence_wood_22", { --left(1)+bottom(21)=22
  384. tiles = {"default_wood.png"},
  385. paramtype = "light",
  386. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  387. drop = 'fences:fence_wood',
  388. sunlight_propagates = true,
  389. sounds = default.node_sound_wood_defaults(),
  390. drawtype = "nodebox",
  391. node_box = {
  392. type = "fixed",
  393. fixed = {
  394. p0,p1,p2,p3,p4,p5,
  395. z1,z12,x2,x22,
  396. bz1,bz11,bx2,bx21,
  397. }
  398. },
  399. selection_box = {
  400. type = "fixed",
  401. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  402. },
  403. on_punch = function(pos, puncher)
  404. punch(pos, puncher)
  405. end,
  406. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  407. find_dock(pos, -1)
  408. end
  409. })
  410. minetest.register_node("fences:fence_wood_33", { --left(1)+top+bottom(32)=33
  411. tiles = {"default_wood.png"},
  412. paramtype = "light",
  413. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  414. drop = 'fences:fence_wood',
  415. sunlight_propagates = true,
  416. sounds = default.node_sound_wood_defaults(),
  417. drawtype = "nodebox",
  418. node_box = {
  419. type = "fixed",
  420. fixed = {
  421. p0,p1,p2,p3,p4,p5,
  422. z1,z12,x1,x12,x2,x21,
  423. bz1,bz11,bx1,bx11,bx2,bx21,
  424. }
  425. },
  426. selection_box = {
  427. type = "fixed",
  428. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  429. },
  430. on_punch = function(pos, puncher)
  431. punch(pos, puncher)
  432. end,
  433. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  434. find_dock(pos, -1)
  435. end
  436. })
  437. minetest.register_node("fences:fence_wood_34", { --right(2)+top+bottom(32)=34
  438. tiles = {"default_wood.png"},
  439. paramtype = "light",
  440. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  441. drop = 'fences:fence_wood',
  442. sunlight_propagates = true,
  443. sounds = default.node_sound_wood_defaults(),
  444. drawtype = "nodebox",
  445. node_box = {
  446. type = "fixed",
  447. fixed = {
  448. p0,p1,p2,p3,p4,p5,
  449. z2,z22,x1,x12,x2,x22,
  450. bz2,bz21,bx1,bx11,bx2,bx21,
  451. }
  452. },
  453. selection_box = {
  454. type = "fixed",
  455. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  456. },
  457. on_punch = function(pos, puncher)
  458. punch(pos, puncher)
  459. end,
  460. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  461. find_dock(pos, -1)
  462. end
  463. })
  464. minetest.register_node("fences:fence_wood_23", { --right(2)+bottom(21)=23
  465. tiles = {"default_wood.png"},
  466. paramtype = "light",
  467. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  468. drop = 'fences:fence_wood',
  469. sunlight_propagates = true,
  470. sounds = default.node_sound_wood_defaults(),
  471. drawtype = "nodebox",
  472. node_box = {
  473. type = "fixed",
  474. fixed = {
  475. p0,p1,p2,p3,p4,p5,
  476. z2,z22,x2,x22,
  477. bz2,bz21,bx2,bx21,
  478. }
  479. },
  480. selection_box = {
  481. type = "fixed",
  482. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  483. },
  484. on_punch = function(pos, puncher)
  485. punch(pos, puncher)
  486. end,
  487. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  488. find_dock(pos, -1)
  489. end
  490. })
  491. minetest.register_node("fences:fence_wood_13", { --right(2)+top(11)=13
  492. tiles = {"default_wood.png"},
  493. paramtype = "light",
  494. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  495. drop = 'fences:fence_wood',
  496. sunlight_propagates = true,
  497. sounds = default.node_sound_wood_defaults(),
  498. drawtype = "nodebox",
  499. node_box = {
  500. type = "fixed",
  501. fixed = {
  502. p0,p1,p2,p3,p4,p5,
  503. z2,z22,x1,x12,
  504. bz1,bz11,bx1,bx11,
  505. }
  506. },
  507. selection_box = {
  508. type = "fixed",
  509. fixed = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16},
  510. },
  511. on_punch = function(pos, puncher)
  512. punch(pos, puncher)
  513. end,
  514. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  515. find_dock(pos, -1)
  516. end
  517. })
  518. minetest.register_craft({
  519. output = 'fences:fence_wood 2',
  520. recipe = {
  521. {'default:stick', 'default:stick', 'default:stick'},
  522. {'default:stick', 'default:stick', 'default:stick'},
  523. {'', '', ''},
  524. }
  525. })
  526. minetest.register_craft({
  527. output = 'fences:fencegate',
  528. recipe = {
  529. {'default:stick', 'default:wood', 'default:stick'},
  530. {'default:stick', 'default:wood', 'default:stick'},
  531. {'', '', ''},
  532. }
  533. })
  534. local meta2
  535. local state2 = 0
  536. local function update_gate(pos, node)
  537. minetest.env:set_node(pos, node)
  538. end
  539. local function punch_gate(pos, node)
  540. meta2 = minetest.env:get_meta(pos)
  541. state2 = meta2:get_int("state")
  542. local tmp_node2
  543. if state2 == 1 then
  544. state2 = 0
  545. minetest.sound_play("door_close", {gain = 0.3, max_hear_distance = 10})
  546. tmp_node2 = {name="fences:fencegate", param1=node.param1, param2=node.param2}
  547. else
  548. state2 = 1
  549. minetest.sound_play("door_open", {gain = 0.3, max_hear_distance = 10})
  550. tmp_node2 = {name="fences:fencegate_open", param1=node.param1, param2=node.param2}
  551. end
  552. update_gate(pos, tmp_node2)
  553. meta2:set_int("state", state2)
  554. end
  555. minetest.register_node("fences:fencegate_open", {
  556. tiles = {"default_wood.png"},
  557. inventory_image = "default_fence.png",
  558. wield_image = "default_fence.png",
  559. paramtype = "light",
  560. paramtype2 = "facedir",
  561. sunlight_propagates = true,
  562. walkable = true,
  563. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1,not_in_inventory=1},
  564. drop = 'fences:fencegate',
  565. drawtype = "nodebox",
  566. node_box = {
  567. type = "fixed",
  568. fixed = {
  569. {-1/2, -1/2+5/16, -1/16, -1/2+2/16, 1/2, 1/16}, --links abschluss
  570. {1/2-2/16, -1/2+5/16, -1/16, 1/2, 1/2, 1/16}, --rechts abschluss
  571. {-1/2, 1/2-4/16, 1/16, -1/2+2/16, 1/2-1/16, 1/2-2/16}, --oben-links(quer) x
  572. {-1/2, -1/2+6/16, 1/16, -1/2+2/16, -1/2+9/16, 1/2-2/16}, --unten-links(quer) x
  573. {1/2-2/16, 1/2-4/16, 1/16, 1/2, 1/2-1/16, 1/2}, --oben-rechts(quer) x
  574. {1/2-2/16, -1/2+6/16, 1/16, 1/2, -1/2+9/16, 1/2}, --unten-rechts(quer) x
  575. {-1/2, -1/2+6/16, 6/16, -1/2+2/16, 1/2-1/16, 1/2}, --mitte links
  576. {1/2-2/16, 1/2-4/16, 1/2, 1/2, -1/2+9/16, 6/16}, --mitte rechts
  577. }
  578. },
  579. selection_box = {
  580. type = "fixed",
  581. fixed = {
  582. {-1/2, -1/2+5/16, -1/16, -1/2+2/16, 1/2, 1/2}, --links
  583. {1/2, -1/2+5/16, -1/16, 1/2, 1/2, 1/2-2/16}, --rechts
  584. }
  585. },
  586. --on_punch = function(pos, node, puncher)
  587. on_rightclick = function(pos, node, clicker)
  588. punch_gate(pos, node)
  589. end,
  590. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  591. find_dock(pos, -1)
  592. end
  593. })
  594. minetest.register_node("fences:fencegate", {
  595. description = "Wooden Fancegate",
  596. tiles = {"default_wood.png"},
  597. inventory_image = "fences_fencegate.png",
  598. wield_image = "fences_fencegate.png",
  599. paramtype = "light",
  600. paramtype2 = "facedir",
  601. sunlight_propagates = true,
  602. walkable = true,
  603. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fences=1},
  604. drop = 'fences:fencegate',
  605. drawtype = "nodebox",
  606. node_box = {
  607. type = "fixed",
  608. fixed = {
  609. {-1/2, -1/2+5/16, -1/16, -1/2+2/16, 1/2, 1/16}, --links abschluss
  610. {1/2-2/16, -1/2+5/16, -1/16, 1/2, 1/2, 1/16}, --rechts abschluss
  611. {-2/16, -1/2+6/16, -1/16, 0, 1/2-1/16, 1/16}, --mitte links
  612. {0, -1/2+6/16, -1/16, 2/16, 1/2-1/16, 1/16}, --mitte rechts
  613. {-2/16, 1/2-4/16, 1/16, -1/2, 1/2-1/16, -1/16}, --oben(quer) -z
  614. {-2/16, -1/2+6/16, 1/16, -1/2, -1/2+9/16, -1/16}, --unten(quer) -z
  615. {2/16, 1/2-4/16, -1/16, 1/2, 1/2-1/16, 1/16}, --oben(quer) z
  616. {2/16, -1/2+6/16, -1/16, 1/2, -1/2+9/16, 1/16}, --unten(quer) z
  617. p1,p2,p3,p4,p5,
  618. bx1,bx11,bx2,bx21,
  619. }
  620. },
  621. selection_box = {
  622. type = "fixed",
  623. fixed = {
  624. {-1/2, -1/2+5/16, -1/16, 1/2, 1/2, 1/16}, --gate
  625. }
  626. },
  627. on_construct = function(pos)
  628. me2 = minetest.env:get_node(pos)
  629. meta2 = minetest.env:get_meta(pos)
  630. meta2:set_int("state", 0)
  631. state2 = 0
  632. find_dock(pos, -1)
  633. end,
  634. on_rightclick = function(pos, node, clicker)
  635. punch_gate(pos, node)
  636. end,
  637. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  638. find_dock(pos, -1)
  639. end
  640. })
  641. if override_original == true then
  642. minetest.register_abm({
  643. nodenames = {"default:fence_wood"},
  644. interval = 1.0,
  645. chance = 1,
  646. action = function(pos, node, active_object_count, active_object_count_wider)
  647. local tmp_node3 = {name="fences:fence_wood"}
  648. minetest.env:set_node(pos, tmp_node3)
  649. minetest.env:punch_node(pos)
  650. end
  651. })
  652. end