init.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. -- our API object
  2. doors = {}
  3. -- private data
  4. local _doors = {}
  5. _doors.registered_doors = {}
  6. _doors.registered_trapdoors = {}
  7. local function replace_old_owner_information(pos)
  8. local meta = minetest.get_meta(pos)
  9. local owner = meta:get_string("doors_owner")
  10. if owner and owner ~= "" then
  11. meta:set_string("owner", owner)
  12. meta:set_string("doors_owner", "")
  13. end
  14. end
  15. -- returns an object to a door object or nil
  16. function doors.get(pos)
  17. local node_name = minetest.get_node(pos).name
  18. if _doors.registered_doors[node_name] then
  19. -- A normal upright door
  20. return {
  21. pos = pos,
  22. open = function(self, player)
  23. if self:state() then
  24. return false
  25. end
  26. return _doors.door_toggle(self.pos, nil, player)
  27. end,
  28. close = function(self, player)
  29. if not self:state() then
  30. return false
  31. end
  32. return _doors.door_toggle(self.pos, nil, player)
  33. end,
  34. toggle = function(self, player)
  35. return _doors.door_toggle(self.pos, nil, player)
  36. end,
  37. state = function(self)
  38. local state = minetest.get_meta(self.pos):get_int("state")
  39. return state %2 == 1
  40. end
  41. }
  42. elseif _doors.registered_trapdoors[node_name] then
  43. -- A trapdoor
  44. return {
  45. pos = pos,
  46. open = function(self, player)
  47. if self:state() then
  48. return false
  49. end
  50. return _doors.trapdoor_toggle(self.pos, nil, player)
  51. end,
  52. close = function(self, player)
  53. if not self:state() then
  54. return false
  55. end
  56. return _doors.trapdoor_toggle(self.pos, nil, player)
  57. end,
  58. toggle = function(self, player)
  59. return _doors.trapdoor_toggle(self.pos, nil, player)
  60. end,
  61. state = function(self)
  62. return minetest.get_node(self.pos).name:sub(-5) == "_open"
  63. end
  64. }
  65. else
  66. return nil
  67. end
  68. end
  69. -- this hidden node is placed on top of the bottom, and prevents
  70. -- nodes from being placed in the top half of the door.
  71. minetest.register_node("doors:hidden", {
  72. description = "Hidden Door Segment",
  73. -- can't use airlike otherwise falling nodes will turn to entities
  74. -- and will be forever stuck until door is removed.
  75. drawtype = "nodebox",
  76. paramtype = "light",
  77. paramtype2 = "facedir",
  78. sunlight_propagates = true,
  79. -- has to be walkable for falling nodes to stop falling.
  80. walkable = true,
  81. pointable = false,
  82. diggable = false,
  83. buildable_to = false,
  84. floodable = false,
  85. drop = "",
  86. groups = {not_in_creative_inventory = 1},
  87. on_blast = function() end,
  88. tiles = {"doors_blank.png"},
  89. -- 1px transparent block inside door hinge near node top.
  90. node_box = {
  91. type = "fixed",
  92. fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32},
  93. },
  94. -- collision_box needed otherise selection box would be full node size
  95. collision_box = {
  96. type = "fixed",
  97. fixed = {-15/32, 13/32, -15/32, -13/32, 1/2, -13/32},
  98. },
  99. })
  100. -- table used to aid door opening/closing
  101. local transform = {
  102. {
  103. {v = "_a", param2 = 3},
  104. {v = "_a", param2 = 0},
  105. {v = "_a", param2 = 1},
  106. {v = "_a", param2 = 2},
  107. },
  108. {
  109. {v = "_b", param2 = 1},
  110. {v = "_b", param2 = 2},
  111. {v = "_b", param2 = 3},
  112. {v = "_b", param2 = 0},
  113. },
  114. {
  115. {v = "_b", param2 = 1},
  116. {v = "_b", param2 = 2},
  117. {v = "_b", param2 = 3},
  118. {v = "_b", param2 = 0},
  119. },
  120. {
  121. {v = "_a", param2 = 3},
  122. {v = "_a", param2 = 0},
  123. {v = "_a", param2 = 1},
  124. {v = "_a", param2 = 2},
  125. },
  126. }
  127. function _doors.door_toggle(pos, node, clicker)
  128. local meta = minetest.get_meta(pos)
  129. node = node or minetest.get_node(pos)
  130. local def = minetest.registered_nodes[node.name]
  131. local name = def.door.name
  132. local state = meta:get_string("state")
  133. if state == "" then
  134. -- fix up lvm-placed right-hinged doors, default closed
  135. if node.name:sub(-2) == "_b" then
  136. state = 2
  137. else
  138. state = 0
  139. end
  140. else
  141. state = tonumber(state)
  142. end
  143. replace_old_owner_information(pos)
  144. if clicker and not default.can_interact_with_node(clicker, pos) then
  145. return false
  146. end
  147. -- until Lua-5.2 we have no bitwise operators :(
  148. if state % 2 == 1 then
  149. state = state - 1
  150. else
  151. state = state + 1
  152. end
  153. local dir = node.param2
  154. if state % 2 == 0 then
  155. minetest.sound_play(def.door.sounds[1],
  156. {pos = pos, gain = 0.3, max_hear_distance = 10})
  157. else
  158. minetest.sound_play(def.door.sounds[2],
  159. {pos = pos, gain = 0.3, max_hear_distance = 10})
  160. end
  161. minetest.swap_node(pos, {
  162. name = name .. transform[state + 1][dir+1].v,
  163. param2 = transform[state + 1][dir+1].param2
  164. })
  165. meta:set_int("state", state)
  166. return true
  167. end
  168. local function on_place_node(place_to, newnode,
  169. placer, oldnode, itemstack, pointed_thing)
  170. -- Run script hook
  171. for _, callback in ipairs(minetest.registered_on_placenodes) do
  172. -- Deepcopy pos, node and pointed_thing because callback can modify them
  173. local place_to_copy = {x = place_to.x, y = place_to.y, z = place_to.z}
  174. local newnode_copy =
  175. {name = newnode.name, param1 = newnode.param1, param2 = newnode.param2}
  176. local oldnode_copy =
  177. {name = oldnode.name, param1 = oldnode.param1, param2 = oldnode.param2}
  178. local pointed_thing_copy = {
  179. type = pointed_thing.type,
  180. above = vector.new(pointed_thing.above),
  181. under = vector.new(pointed_thing.under),
  182. ref = pointed_thing.ref,
  183. }
  184. callback(place_to_copy, newnode_copy, placer,
  185. oldnode_copy, itemstack, pointed_thing_copy)
  186. end
  187. end
  188. local function can_dig_door(pos, digger)
  189. replace_old_owner_information(pos)
  190. if default.can_interact_with_node(digger, pos) then
  191. return true
  192. else
  193. minetest.record_protection_violation(pos, digger:get_player_name())
  194. return false
  195. end
  196. end
  197. function doors.register(name, def)
  198. if not name:find(":") then
  199. name = "doors:" .. name
  200. end
  201. -- replace old doors of this type automatically
  202. minetest.register_lbm({
  203. name = ":doors:replace_" .. name:gsub(":", "_"),
  204. nodenames = {name.."_b_1", name.."_b_2"},
  205. action = function(pos, node)
  206. local l = tonumber(node.name:sub(-1))
  207. local meta = minetest.get_meta(pos)
  208. local h = meta:get_int("right") + 1
  209. local p2 = node.param2
  210. local replace = {
  211. {{type = "a", state = 0}, {type = "a", state = 3}},
  212. {{type = "b", state = 1}, {type = "b", state = 2}}
  213. }
  214. local new = replace[l][h]
  215. -- retain infotext and doors_owner fields
  216. minetest.swap_node(pos, {name = name .. "_" .. new.type, param2 = p2})
  217. meta:set_int("state", new.state)
  218. -- properly place doors:hidden at the right spot
  219. local p3 = p2
  220. if new.state >= 2 then
  221. p3 = (p3 + 3) % 4
  222. end
  223. if new.state % 2 == 1 then
  224. if new.state >= 2 then
  225. p3 = (p3 + 1) % 4
  226. else
  227. p3 = (p3 + 3) % 4
  228. end
  229. end
  230. -- wipe meta on top node as it's unused
  231. minetest.set_node({x = pos.x, y = pos.y + 1, z = pos.z},
  232. {name = "doors:hidden", param2 = p3})
  233. end
  234. })
  235. minetest.register_craftitem(":" .. name, {
  236. description = def.description,
  237. inventory_image = def.inventory_image,
  238. groups = table.copy(def.groups),
  239. on_place = function(itemstack, placer, pointed_thing)
  240. local pos
  241. if not pointed_thing.type == "node" then
  242. return itemstack
  243. end
  244. local node = minetest.get_node(pointed_thing.under)
  245. local pdef = minetest.registered_nodes[node.name]
  246. if pdef and pdef.on_rightclick and
  247. not placer:get_player_control().sneak then
  248. return pdef.on_rightclick(pointed_thing.under,
  249. node, placer, itemstack, pointed_thing)
  250. end
  251. if pdef and pdef.buildable_to then
  252. pos = pointed_thing.under
  253. else
  254. pos = pointed_thing.above
  255. node = minetest.get_node(pos)
  256. pdef = minetest.registered_nodes[node.name]
  257. if not pdef or not pdef.buildable_to then
  258. return itemstack
  259. end
  260. end
  261. local above = {x = pos.x, y = pos.y + 1, z = pos.z}
  262. local top_node = minetest.get_node_or_nil(above)
  263. local topdef = top_node and minetest.registered_nodes[top_node.name]
  264. if not topdef or not topdef.buildable_to then
  265. return itemstack
  266. end
  267. local pn = placer:get_player_name()
  268. if minetest.is_protected(pos, pn) or minetest.is_protected(above, pn) then
  269. return itemstack
  270. end
  271. local dir = minetest.dir_to_facedir(placer:get_look_dir())
  272. local ref = {
  273. {x = -1, y = 0, z = 0},
  274. {x = 0, y = 0, z = 1},
  275. {x = 1, y = 0, z = 0},
  276. {x = 0, y = 0, z = -1},
  277. }
  278. local aside = {
  279. x = pos.x + ref[dir + 1].x,
  280. y = pos.y + ref[dir + 1].y,
  281. z = pos.z + ref[dir + 1].z,
  282. }
  283. local state = 0
  284. if minetest.get_item_group(minetest.get_node(aside).name, "door") == 1 then
  285. state = state + 2
  286. minetest.set_node(pos, {name = name .. "_b", param2 = dir})
  287. minetest.set_node(above, {name = "doors:hidden", param2 = (dir + 3) % 4})
  288. else
  289. minetest.set_node(pos, {name = name .. "_a", param2 = dir})
  290. minetest.set_node(above, {name = "doors:hidden", param2 = dir})
  291. end
  292. local meta = minetest.get_meta(pos)
  293. meta:set_int("state", state)
  294. if def.protected then
  295. meta:set_string("owner", pn)
  296. meta:set_string("infotext", "Owned by " .. pn)
  297. end
  298. if not (creative and creative.is_enabled_for and creative.is_enabled_for(pn)) then
  299. itemstack:take_item()
  300. end
  301. minetest.sound_play(def.sounds.place, {pos = pos})
  302. on_place_node(pos, minetest.get_node(pos),
  303. placer, node, itemstack, pointed_thing)
  304. return itemstack
  305. end
  306. })
  307. def.inventory_image = nil
  308. if def.recipe then
  309. minetest.register_craft({
  310. output = name,
  311. recipe = def.recipe,
  312. })
  313. end
  314. def.recipe = nil
  315. if not def.sounds then
  316. def.sounds = default.node_sound_wood_defaults()
  317. end
  318. if not def.sound_open then
  319. def.sound_open = "doors_door_open"
  320. end
  321. if not def.sound_close then
  322. def.sound_close = "doors_door_close"
  323. end
  324. def.groups.not_in_creative_inventory = 1
  325. def.groups.door = 1
  326. def.drop = name
  327. def.door = {
  328. name = name,
  329. sounds = { def.sound_close, def.sound_open },
  330. }
  331. def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  332. _doors.door_toggle(pos, node, clicker)
  333. return itemstack
  334. end
  335. def.after_dig_node = function(pos, node, meta, digger)
  336. minetest.remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
  337. minetest.check_for_falling({x = pos.x, y = pos.y + 1, z = pos.z})
  338. end
  339. def.on_rotate = function(pos, node, user, mode, new_param2)
  340. return false
  341. end
  342. if def.protected then
  343. def.can_dig = can_dig_door
  344. def.on_blast = function() end
  345. def.on_key_use = function(pos, player)
  346. local door = doors.get(pos)
  347. door:toggle(player)
  348. end
  349. def.on_skeleton_key_use = function(pos, player, newsecret)
  350. replace_old_owner_information(pos)
  351. local meta = minetest.get_meta(pos)
  352. local owner = meta:get_string("owner")
  353. local pname = player:get_player_name()
  354. -- verify placer is owner of lockable door
  355. if owner ~= pname then
  356. minetest.record_protection_violation(pos, pname)
  357. minetest.chat_send_player(pname, "You do not own this locked door.")
  358. return nil
  359. end
  360. local secret = meta:get_string("key_lock_secret")
  361. if secret == "" then
  362. secret = newsecret
  363. meta:set_string("key_lock_secret", secret)
  364. end
  365. return secret, "a locked door", owner
  366. end
  367. else
  368. def.on_blast = function(pos, intensity)
  369. minetest.remove_node(pos)
  370. -- hidden node doesn't get blasted away.
  371. minetest.remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
  372. return {name}
  373. end
  374. end
  375. def.on_destruct = function(pos)
  376. minetest.remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
  377. end
  378. def.drawtype = "mesh"
  379. def.paramtype = "light"
  380. def.paramtype2 = "facedir"
  381. def.sunlight_propagates = true
  382. def.walkable = true
  383. def.is_ground_content = false
  384. def.buildable_to = false
  385. def.selection_box = {type = "fixed", fixed = {-1/2,-1/2,-1/2,1/2,3/2,-6/16}}
  386. def.collision_box = {type = "fixed", fixed = {-1/2,-1/2,-1/2,1/2,3/2,-6/16}}
  387. def.mesh = "door_a.obj"
  388. minetest.register_node(":" .. name .. "_a", def)
  389. def.mesh = "door_b.obj"
  390. minetest.register_node(":" .. name .. "_b", def)
  391. _doors.registered_doors[name .. "_a"] = true
  392. _doors.registered_doors[name .. "_b"] = true
  393. end
  394. doors.register("door_wood", {
  395. tiles = {{ name = "doors_door_wood.png", backface_culling = true }},
  396. description = "Wooden Door",
  397. inventory_image = "doors_item_wood.png",
  398. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
  399. recipe = {
  400. {"group:wood", "group:wood"},
  401. {"group:wood", "group:wood"},
  402. {"group:wood", "group:wood"},
  403. }
  404. })
  405. doors.register("door_steel", {
  406. tiles = {{name = "doors_door_steel.png", backface_culling = true}},
  407. description = "Steel Door",
  408. inventory_image = "doors_item_steel.png",
  409. protected = true,
  410. groups = {cracky = 1, level = 2},
  411. sounds = default.node_sound_metal_defaults(),
  412. sound_open = "doors_steel_door_open",
  413. sound_close = "doors_steel_door_close",
  414. recipe = {
  415. {"default:steel_ingot", "default:steel_ingot"},
  416. {"default:steel_ingot", "default:steel_ingot"},
  417. {"default:steel_ingot", "default:steel_ingot"},
  418. }
  419. })
  420. doors.register("door_glass", {
  421. tiles = {"doors_door_glass.png"},
  422. description = "Glass Door",
  423. inventory_image = "doors_item_glass.png",
  424. groups = {cracky=3, oddly_breakable_by_hand=3},
  425. sounds = default.node_sound_glass_defaults(),
  426. sound_open = "doors_glass_door_open",
  427. sound_close = "doors_glass_door_close",
  428. recipe = {
  429. {"default:glass", "default:glass"},
  430. {"default:glass", "default:glass"},
  431. {"default:glass", "default:glass"},
  432. }
  433. })
  434. doors.register("door_obsidian_glass", {
  435. tiles = {"doors_door_obsidian_glass.png"},
  436. description = "Obsidian Glass Door",
  437. inventory_image = "doors_item_obsidian_glass.png",
  438. groups = {cracky=3},
  439. sounds = default.node_sound_glass_defaults(),
  440. sound_open = "doors_glass_door_open",
  441. sound_close = "doors_glass_door_close",
  442. recipe = {
  443. {"default:obsidian_glass", "default:obsidian_glass"},
  444. {"default:obsidian_glass", "default:obsidian_glass"},
  445. {"default:obsidian_glass", "default:obsidian_glass"},
  446. },
  447. })
  448. -- Capture mods using the old API as best as possible.
  449. function doors.register_door(name, def)
  450. if def.only_placer_can_open then
  451. def.protected = true
  452. end
  453. def.only_placer_can_open = nil
  454. local i = name:find(":")
  455. local modname = name:sub(1, i - 1)
  456. if not def.tiles then
  457. if def.protected then
  458. def.tiles = {{name = "doors_door_steel.png", backface_culling = true}}
  459. else
  460. def.tiles = {{name = "doors_door_wood.png", backface_culling = true}}
  461. end
  462. minetest.log("warning", modname .. " registered door \"" .. name .. "\" " ..
  463. "using deprecated API method \"doors.register_door()\" but " ..
  464. "did not provide the \"tiles\" parameter. A fallback tiledef " ..
  465. "will be used instead.")
  466. end
  467. doors.register(name, def)
  468. end
  469. ----trapdoor----
  470. function _doors.trapdoor_toggle(pos, node, clicker)
  471. node = node or minetest.get_node(pos)
  472. replace_old_owner_information(pos)
  473. if clicker and not default.can_interact_with_node(clicker, pos) then
  474. return false
  475. end
  476. local def = minetest.registered_nodes[node.name]
  477. if string.sub(node.name, -5) == "_open" then
  478. minetest.sound_play(def.sound_close,
  479. {pos = pos, gain = 0.3, max_hear_distance = 10})
  480. minetest.swap_node(pos, {name = string.sub(node.name, 1,
  481. string.len(node.name) - 5), param1 = node.param1, param2 = node.param2})
  482. else
  483. minetest.sound_play(def.sound_open,
  484. {pos = pos, gain = 0.3, max_hear_distance = 10})
  485. minetest.swap_node(pos, {name = node.name .. "_open",
  486. param1 = node.param1, param2 = node.param2})
  487. end
  488. end
  489. function doors.register_trapdoor(name, def)
  490. if not name:find(":") then
  491. name = "doors:" .. name
  492. end
  493. local name_closed = name
  494. local name_opened = name.."_open"
  495. def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  496. _doors.trapdoor_toggle(pos, node, clicker)
  497. return itemstack
  498. end
  499. -- Common trapdoor configuration
  500. def.drawtype = "nodebox"
  501. def.paramtype = "light"
  502. def.paramtype2 = "facedir"
  503. def.is_ground_content = false
  504. if def.protected then
  505. def.can_dig = can_dig_door
  506. def.after_place_node = function(pos, placer, itemstack, pointed_thing)
  507. local pn = placer:get_player_name()
  508. local meta = minetest.get_meta(pos)
  509. meta:set_string("owner", pn)
  510. meta:set_string("infotext", "Owned by "..pn)
  511. return (creative and creative.is_enabled_for and creative.is_enabled_for(pn))
  512. end
  513. def.on_blast = function() end
  514. def.on_key_use = function(pos, player)
  515. local door = doors.get(pos)
  516. door:toggle(player)
  517. end
  518. def.on_skeleton_key_use = function(pos, player, newsecret)
  519. replace_old_owner_information(pos)
  520. local meta = minetest.get_meta(pos)
  521. local owner = meta:get_string("owner")
  522. local pname = player:get_player_name()
  523. -- verify placer is owner of lockable door
  524. if owner ~= pname then
  525. minetest.record_protection_violation(pos, pname)
  526. minetest.chat_send_player(pname, "You do not own this trapdoor.")
  527. return nil
  528. end
  529. local secret = meta:get_string("key_lock_secret")
  530. if secret == "" then
  531. secret = newsecret
  532. meta:set_string("key_lock_secret", secret)
  533. end
  534. return secret, "a locked trapdoor", owner
  535. end
  536. else
  537. def.on_blast = function(pos, intensity)
  538. minetest.remove_node(pos)
  539. return {name}
  540. end
  541. end
  542. if not def.sounds then
  543. def.sounds = default.node_sound_wood_defaults()
  544. end
  545. if not def.sound_open then
  546. def.sound_open = "doors_door_open"
  547. end
  548. if not def.sound_close then
  549. def.sound_close = "doors_door_close"
  550. end
  551. local def_opened = table.copy(def)
  552. local def_closed = table.copy(def)
  553. def_closed.node_box = {
  554. type = "fixed",
  555. fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
  556. }
  557. def_closed.selection_box = {
  558. type = "fixed",
  559. fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
  560. }
  561. def_closed.tiles = {def.tile_front,
  562. def.tile_front .. '^[transformFY',
  563. def.tile_side, def.tile_side,
  564. def.tile_side, def.tile_side}
  565. def_opened.node_box = {
  566. type = "fixed",
  567. fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
  568. }
  569. def_opened.selection_box = {
  570. type = "fixed",
  571. fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
  572. }
  573. def_opened.tiles = {def.tile_side, def.tile_side,
  574. def.tile_side .. '^[transform3',
  575. def.tile_side .. '^[transform1',
  576. def.tile_front .. '^[transform46',
  577. def.tile_front .. '^[transform6'}
  578. def_opened.drop = name_closed
  579. def_opened.groups.not_in_creative_inventory = 1
  580. minetest.register_node(name_opened, def_opened)
  581. minetest.register_node(name_closed, def_closed)
  582. _doors.registered_trapdoors[name_opened] = true
  583. _doors.registered_trapdoors[name_closed] = true
  584. end
  585. doors.register_trapdoor("doors:trapdoor", {
  586. description = "Trapdoor",
  587. inventory_image = "doors_trapdoor.png",
  588. wield_image = "doors_trapdoor.png",
  589. tile_front = "doors_trapdoor.png",
  590. tile_side = "doors_trapdoor_side.png",
  591. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, door = 1},
  592. })
  593. doors.register_trapdoor("doors:trapdoor_steel", {
  594. description = "Steel Trapdoor",
  595. inventory_image = "doors_trapdoor_steel.png",
  596. wield_image = "doors_trapdoor_steel.png",
  597. tile_front = "doors_trapdoor_steel.png",
  598. tile_side = "doors_trapdoor_steel_side.png",
  599. protected = true,
  600. sounds = default.node_sound_metal_defaults(),
  601. sound_open = "doors_steel_door_open",
  602. sound_close = "doors_steel_door_close",
  603. groups = {cracky = 1, level = 2, door = 1},
  604. })
  605. minetest.register_craft({
  606. output = 'doors:trapdoor 2',
  607. recipe = {
  608. {'group:wood', 'group:wood', 'group:wood'},
  609. {'group:wood', 'group:wood', 'group:wood'},
  610. {'', '', ''},
  611. }
  612. })
  613. minetest.register_craft({
  614. output = 'doors:trapdoor_steel',
  615. recipe = {
  616. {'default:steel_ingot', 'default:steel_ingot'},
  617. {'default:steel_ingot', 'default:steel_ingot'},
  618. }
  619. })
  620. ----fence gate----
  621. function doors.register_fencegate(name, def)
  622. local fence = {
  623. description = def.description,
  624. drawtype = "mesh",
  625. tiles = {def.texture},
  626. paramtype = "light",
  627. paramtype2 = "facedir",
  628. sunlight_propagates = true,
  629. is_ground_content = false,
  630. drop = name .. "_closed",
  631. connect_sides = {"left", "right"},
  632. groups = def.groups,
  633. sounds = def.sounds,
  634. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  635. local node_def = minetest.registered_nodes[node.name]
  636. minetest.swap_node(pos, {name = node_def.gate, param2 = node.param2})
  637. minetest.sound_play(node_def.sound, {pos = pos, gain = 0.3,
  638. max_hear_distance = 8})
  639. return itemstack
  640. end,
  641. selection_box = {
  642. type = "fixed",
  643. fixed = {-1/2, -1/2, -1/4, 1/2, 1/2, 1/4},
  644. },
  645. }
  646. if not fence.sounds then
  647. fence.sounds = default.node_sound_wood_defaults()
  648. end
  649. fence.groups.fence = 1
  650. local fence_closed = table.copy(fence)
  651. fence_closed.mesh = "doors_fencegate_closed.obj"
  652. fence_closed.gate = name .. "_open"
  653. fence_closed.sound = "doors_fencegate_open"
  654. fence_closed.collision_box = {
  655. type = "fixed",
  656. fixed = {-1/2, -1/2, -1/4, 1/2, 1/2, 1/4},
  657. }
  658. local fence_open = table.copy(fence)
  659. fence_open.mesh = "doors_fencegate_open.obj"
  660. fence_open.gate = name .. "_closed"
  661. fence_open.sound = "doors_fencegate_close"
  662. fence_open.groups.not_in_creative_inventory = 1
  663. fence_open.collision_box = {
  664. type = "fixed",
  665. fixed = {{-1/2, -1/2, -1/4, -3/8, 1/2, 1/4},
  666. {-1/2, -3/8, -1/2, -3/8, 3/8, 0}},
  667. }
  668. minetest.register_node(":" .. name .. "_closed", fence_closed)
  669. minetest.register_node(":" .. name .. "_open", fence_open)
  670. minetest.register_craft({
  671. output = name .. "_closed",
  672. recipe = {
  673. {"default:stick", def.material, "default:stick"},
  674. {"default:stick", def.material, "default:stick"}
  675. }
  676. })
  677. end
  678. doors.register_fencegate("doors:gate_wood", {
  679. description = "Wooden Fence Gate",
  680. texture = "default_wood.png",
  681. material = "default:wood",
  682. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
  683. })
  684. doors.register_fencegate("doors:gate_acacia_wood", {
  685. description = "Acacia Fence Gate",
  686. texture = "default_acacia_wood.png",
  687. material = "default:acacia_wood",
  688. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
  689. })
  690. doors.register_fencegate("doors:gate_junglewood", {
  691. description = "Jungle Wood Fence Gate",
  692. texture = "default_junglewood.png",
  693. material = "default:junglewood",
  694. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
  695. })
  696. doors.register_fencegate("doors:gate_pine_wood", {
  697. description = "Pine Fence Gate",
  698. texture = "default_pine_wood.png",
  699. material = "default:pine_wood",
  700. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3}
  701. })
  702. doors.register_fencegate("doors:gate_aspen_wood", {
  703. description = "Aspen Fence Gate",
  704. texture = "default_aspen_wood.png",
  705. material = "default:aspen_wood",
  706. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3}
  707. })
  708. ----fuels----
  709. minetest.register_craft({
  710. type = "fuel",
  711. recipe = "doors:trapdoor",
  712. burntime = 7,
  713. })
  714. minetest.register_craft({
  715. type = "fuel",
  716. recipe = "doors:door_wood",
  717. burntime = 14,
  718. })
  719. minetest.register_craft({
  720. type = "fuel",
  721. recipe = "doors:gate_wood_closed",
  722. burntime = 7,
  723. })
  724. minetest.register_craft({
  725. type = "fuel",
  726. recipe = "doors:gate_acacia_wood_closed",
  727. burntime = 8,
  728. })
  729. minetest.register_craft({
  730. type = "fuel",
  731. recipe = "doors:gate_junglewood_closed",
  732. burntime = 9,
  733. })
  734. minetest.register_craft({
  735. type = "fuel",
  736. recipe = "doors:gate_pine_wood_closed",
  737. burntime = 6,
  738. })
  739. minetest.register_craft({
  740. type = "fuel",
  741. recipe = "doors:gate_aspen_wood_closed",
  742. burntime = 5,
  743. })