init.lua 23 KB

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