2
0

init.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  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. return default.can_interact_with_node(digger, pos)
  191. end
  192. function doors.register(name, def)
  193. if not name:find(":") then
  194. name = "doors:" .. name
  195. end
  196. -- replace old doors of this type automatically
  197. minetest.register_lbm({
  198. name = ":doors:replace_" .. name:gsub(":", "_"),
  199. nodenames = {name.."_b_1", name.."_b_2"},
  200. action = function(pos, node)
  201. local l = tonumber(node.name:sub(-1))
  202. local meta = minetest.get_meta(pos)
  203. local h = meta:get_int("right") + 1
  204. local p2 = node.param2
  205. local replace = {
  206. {{type = "a", state = 0}, {type = "a", state = 3}},
  207. {{type = "b", state = 1}, {type = "b", state = 2}}
  208. }
  209. local new = replace[l][h]
  210. -- retain infotext and doors_owner fields
  211. minetest.swap_node(pos, {name = name .. "_" .. new.type, param2 = p2})
  212. meta:set_int("state", new.state)
  213. -- properly place doors:hidden at the right spot
  214. local p3 = p2
  215. if new.state >= 2 then
  216. p3 = (p3 + 3) % 4
  217. end
  218. if new.state % 2 == 1 then
  219. if new.state >= 2 then
  220. p3 = (p3 + 1) % 4
  221. else
  222. p3 = (p3 + 3) % 4
  223. end
  224. end
  225. -- wipe meta on top node as it's unused
  226. minetest.set_node({x = pos.x, y = pos.y + 1, z = pos.z},
  227. {name = "doors:hidden", param2 = p3})
  228. end
  229. })
  230. minetest.register_craftitem(":" .. name, {
  231. description = def.description,
  232. inventory_image = def.inventory_image,
  233. groups = table.copy(def.groups),
  234. on_place = function(itemstack, placer, pointed_thing)
  235. local pos
  236. if not pointed_thing.type == "node" then
  237. return itemstack
  238. end
  239. local node = minetest.get_node(pointed_thing.under)
  240. local pdef = minetest.registered_nodes[node.name]
  241. if pdef and pdef.on_rightclick and
  242. not (placer and placer:is_player() and
  243. placer:get_player_control().sneak) then
  244. return pdef.on_rightclick(pointed_thing.under,
  245. node, placer, itemstack, pointed_thing)
  246. end
  247. if pdef and pdef.buildable_to then
  248. pos = pointed_thing.under
  249. else
  250. pos = pointed_thing.above
  251. node = minetest.get_node(pos)
  252. pdef = minetest.registered_nodes[node.name]
  253. if not pdef or not pdef.buildable_to then
  254. return itemstack
  255. end
  256. end
  257. local above = {x = pos.x, y = pos.y + 1, z = pos.z}
  258. local top_node = minetest.get_node_or_nil(above)
  259. local topdef = top_node and minetest.registered_nodes[top_node.name]
  260. if not topdef or not topdef.buildable_to then
  261. return itemstack
  262. end
  263. local pn = placer and placer:get_player_name() or ""
  264. if minetest.is_protected(pos, pn) or minetest.is_protected(above, pn) then
  265. return itemstack
  266. end
  267. local dir = placer and minetest.dir_to_facedir(placer:get_look_dir()) or 0
  268. local ref = {
  269. {x = -1, y = 0, z = 0},
  270. {x = 0, y = 0, z = 1},
  271. {x = 1, y = 0, z = 0},
  272. {x = 0, y = 0, z = -1},
  273. }
  274. local aside = {
  275. x = pos.x + ref[dir + 1].x,
  276. y = pos.y + ref[dir + 1].y,
  277. z = pos.z + ref[dir + 1].z,
  278. }
  279. local state = 0
  280. if minetest.get_item_group(minetest.get_node(aside).name, "door") == 1 then
  281. state = state + 2
  282. minetest.set_node(pos, {name = name .. "_b", param2 = dir})
  283. minetest.set_node(above, {name = "doors:hidden", param2 = (dir + 3) % 4})
  284. else
  285. minetest.set_node(pos, {name = name .. "_a", param2 = dir})
  286. minetest.set_node(above, {name = "doors:hidden", param2 = dir})
  287. end
  288. local meta = minetest.get_meta(pos)
  289. meta:set_int("state", state)
  290. if def.protected then
  291. meta:set_string("owner", pn)
  292. meta:set_string("infotext", "Owned by " .. pn)
  293. end
  294. if not (creative and creative.is_enabled_for and creative.is_enabled_for(pn)) then
  295. itemstack:take_item()
  296. end
  297. minetest.sound_play(def.sounds.place, {pos = pos})
  298. on_place_node(pos, minetest.get_node(pos),
  299. placer, node, itemstack, pointed_thing)
  300. return itemstack
  301. end
  302. })
  303. def.inventory_image = nil
  304. if def.recipe then
  305. minetest.register_craft({
  306. output = name,
  307. recipe = def.recipe,
  308. })
  309. end
  310. def.recipe = nil
  311. if not def.sounds then
  312. def.sounds = default.node_sound_wood_defaults()
  313. end
  314. if not def.sound_open then
  315. def.sound_open = "doors_door_open"
  316. end
  317. if not def.sound_close then
  318. def.sound_close = "doors_door_close"
  319. end
  320. def.groups.not_in_creative_inventory = 1
  321. def.groups.door = 1
  322. def.drop = name
  323. def.door = {
  324. name = name,
  325. sounds = { def.sound_close, def.sound_open },
  326. }
  327. def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  328. _doors.door_toggle(pos, node, clicker)
  329. return itemstack
  330. end
  331. def.after_dig_node = function(pos, node, meta, digger)
  332. minetest.remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
  333. minetest.check_for_falling({x = pos.x, y = pos.y + 1, z = pos.z})
  334. end
  335. def.on_rotate = function(pos, node, user, mode, new_param2)
  336. return false
  337. end
  338. if def.protected then
  339. def.can_dig = can_dig_door
  340. def.on_blast = function() end
  341. def.on_key_use = function(pos, player)
  342. local door = doors.get(pos)
  343. door:toggle(player)
  344. end
  345. def.on_skeleton_key_use = function(pos, player, newsecret)
  346. replace_old_owner_information(pos)
  347. local meta = minetest.get_meta(pos)
  348. local owner = meta:get_string("owner")
  349. local pname = player:get_player_name()
  350. -- verify placer is owner of lockable door
  351. if owner ~= pname then
  352. minetest.record_protection_violation(pos, pname)
  353. minetest.chat_send_player(pname, "You do not own this locked door.")
  354. return nil
  355. end
  356. local secret = meta:get_string("key_lock_secret")
  357. if secret == "" then
  358. secret = newsecret
  359. meta:set_string("key_lock_secret", secret)
  360. end
  361. return secret, "a locked door", owner
  362. end
  363. def.node_dig_prediction = ""
  364. else
  365. def.on_blast = function(pos, intensity)
  366. minetest.remove_node(pos)
  367. -- hidden node doesn't get blasted away.
  368. minetest.remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
  369. return {name}
  370. end
  371. end
  372. def.on_destruct = function(pos)
  373. minetest.remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
  374. end
  375. def.drawtype = "mesh"
  376. def.paramtype = "light"
  377. def.paramtype2 = "facedir"
  378. def.sunlight_propagates = true
  379. def.walkable = true
  380. def.is_ground_content = false
  381. def.buildable_to = false
  382. def.selection_box = {type = "fixed", fixed = {-1/2,-1/2,-1/2,1/2,3/2,-6/16}}
  383. def.collision_box = {type = "fixed", fixed = {-1/2,-1/2,-1/2,1/2,3/2,-6/16}}
  384. def.mesh = "door_a.obj"
  385. minetest.register_node(":" .. name .. "_a", def)
  386. def.mesh = "door_b.obj"
  387. minetest.register_node(":" .. name .. "_b", def)
  388. _doors.registered_doors[name .. "_a"] = true
  389. _doors.registered_doors[name .. "_b"] = true
  390. end
  391. doors.register("door_wood", {
  392. tiles = {{ name = "doors_door_wood.png", backface_culling = true }},
  393. description = "Wooden Door",
  394. inventory_image = "doors_item_wood.png",
  395. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
  396. recipe = {
  397. {"group:wood", "group:wood"},
  398. {"group:wood", "group:wood"},
  399. {"group:wood", "group:wood"},
  400. }
  401. })
  402. doors.register("door_steel", {
  403. tiles = {{name = "doors_door_steel.png", backface_culling = true}},
  404. description = "Steel Door",
  405. inventory_image = "doors_item_steel.png",
  406. protected = true,
  407. groups = {cracky = 1, level = 2},
  408. sounds = default.node_sound_metal_defaults(),
  409. sound_open = "doors_steel_door_open",
  410. sound_close = "doors_steel_door_close",
  411. recipe = {
  412. {"default:steel_ingot", "default:steel_ingot"},
  413. {"default:steel_ingot", "default:steel_ingot"},
  414. {"default:steel_ingot", "default:steel_ingot"},
  415. }
  416. })
  417. doors.register("door_glass", {
  418. tiles = {"doors_door_glass.png"},
  419. description = "Glass Door",
  420. inventory_image = "doors_item_glass.png",
  421. groups = {cracky=3, oddly_breakable_by_hand=3},
  422. sounds = default.node_sound_glass_defaults(),
  423. sound_open = "doors_glass_door_open",
  424. sound_close = "doors_glass_door_close",
  425. recipe = {
  426. {"default:glass", "default:glass"},
  427. {"default:glass", "default:glass"},
  428. {"default:glass", "default:glass"},
  429. }
  430. })
  431. doors.register("door_obsidian_glass", {
  432. tiles = {"doors_door_obsidian_glass.png"},
  433. description = "Obsidian Glass Door",
  434. inventory_image = "doors_item_obsidian_glass.png",
  435. groups = {cracky=3},
  436. sounds = default.node_sound_glass_defaults(),
  437. sound_open = "doors_glass_door_open",
  438. sound_close = "doors_glass_door_close",
  439. recipe = {
  440. {"default:obsidian_glass", "default:obsidian_glass"},
  441. {"default:obsidian_glass", "default:obsidian_glass"},
  442. {"default:obsidian_glass", "default:obsidian_glass"},
  443. },
  444. })
  445. -- Capture mods using the old API as best as possible.
  446. function doors.register_door(name, def)
  447. if def.only_placer_can_open then
  448. def.protected = true
  449. end
  450. def.only_placer_can_open = nil
  451. local i = name:find(":")
  452. local modname = name:sub(1, i - 1)
  453. if not def.tiles then
  454. if def.protected then
  455. def.tiles = {{name = "doors_door_steel.png", backface_culling = true}}
  456. else
  457. def.tiles = {{name = "doors_door_wood.png", backface_culling = true}}
  458. end
  459. minetest.log("warning", modname .. " registered door \"" .. name .. "\" " ..
  460. "using deprecated API method \"doors.register_door()\" but " ..
  461. "did not provide the \"tiles\" parameter. A fallback tiledef " ..
  462. "will be used instead.")
  463. end
  464. doors.register(name, def)
  465. end
  466. ----trapdoor----
  467. function _doors.trapdoor_toggle(pos, node, clicker)
  468. node = node or minetest.get_node(pos)
  469. replace_old_owner_information(pos)
  470. if clicker and not default.can_interact_with_node(clicker, pos) then
  471. return false
  472. end
  473. local def = minetest.registered_nodes[node.name]
  474. if string.sub(node.name, -5) == "_open" then
  475. minetest.sound_play(def.sound_close,
  476. {pos = pos, gain = 0.3, max_hear_distance = 10})
  477. minetest.swap_node(pos, {name = string.sub(node.name, 1,
  478. string.len(node.name) - 5), param1 = node.param1, param2 = node.param2})
  479. else
  480. minetest.sound_play(def.sound_open,
  481. {pos = pos, gain = 0.3, max_hear_distance = 10})
  482. minetest.swap_node(pos, {name = node.name .. "_open",
  483. param1 = node.param1, param2 = node.param2})
  484. end
  485. end
  486. function doors.register_trapdoor(name, def)
  487. if not name:find(":") then
  488. name = "doors:" .. name
  489. end
  490. local name_closed = name
  491. local name_opened = name.."_open"
  492. def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  493. _doors.trapdoor_toggle(pos, node, clicker)
  494. return itemstack
  495. end
  496. -- Common trapdoor configuration
  497. def.drawtype = "nodebox"
  498. def.paramtype = "light"
  499. def.paramtype2 = "facedir"
  500. def.is_ground_content = false
  501. if def.protected then
  502. def.can_dig = can_dig_door
  503. def.after_place_node = function(pos, placer, itemstack, pointed_thing)
  504. local pn = placer:get_player_name()
  505. local meta = minetest.get_meta(pos)
  506. meta:set_string("owner", pn)
  507. meta:set_string("infotext", "Owned by "..pn)
  508. return (creative and creative.is_enabled_for and creative.is_enabled_for(pn))
  509. end
  510. def.on_blast = function() end
  511. def.on_key_use = function(pos, player)
  512. local door = doors.get(pos)
  513. door:toggle(player)
  514. end
  515. def.on_skeleton_key_use = function(pos, player, newsecret)
  516. replace_old_owner_information(pos)
  517. local meta = minetest.get_meta(pos)
  518. local owner = meta:get_string("owner")
  519. local pname = player:get_player_name()
  520. -- verify placer is owner of lockable door
  521. if owner ~= pname then
  522. minetest.record_protection_violation(pos, pname)
  523. minetest.chat_send_player(pname, "You do not own this trapdoor.")
  524. return nil
  525. end
  526. local secret = meta:get_string("key_lock_secret")
  527. if secret == "" then
  528. secret = newsecret
  529. meta:set_string("key_lock_secret", secret)
  530. end
  531. return secret, "a locked trapdoor", owner
  532. end
  533. def.node_dig_prediction = ""
  534. else
  535. def.on_blast = function(pos, intensity)
  536. minetest.remove_node(pos)
  537. return {name}
  538. end
  539. end
  540. if not def.sounds then
  541. def.sounds = default.node_sound_wood_defaults()
  542. end
  543. if not def.sound_open then
  544. def.sound_open = "doors_door_open"
  545. end
  546. if not def.sound_close then
  547. def.sound_close = "doors_door_close"
  548. end
  549. local def_opened = table.copy(def)
  550. local def_closed = table.copy(def)
  551. def_closed.node_box = {
  552. type = "fixed",
  553. fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
  554. }
  555. def_closed.selection_box = {
  556. type = "fixed",
  557. fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
  558. }
  559. def_closed.tiles = {def.tile_front,
  560. def.tile_front .. '^[transformFY',
  561. def.tile_side, def.tile_side,
  562. def.tile_side, def.tile_side}
  563. def_opened.node_box = {
  564. type = "fixed",
  565. fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
  566. }
  567. def_opened.selection_box = {
  568. type = "fixed",
  569. fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
  570. }
  571. def_opened.tiles = {def.tile_side, def.tile_side,
  572. def.tile_side .. '^[transform3',
  573. def.tile_side .. '^[transform1',
  574. def.tile_front .. '^[transform46',
  575. def.tile_front .. '^[transform6'}
  576. def_opened.drop = name_closed
  577. def_opened.groups.not_in_creative_inventory = 1
  578. minetest.register_node(name_opened, def_opened)
  579. minetest.register_node(name_closed, def_closed)
  580. _doors.registered_trapdoors[name_opened] = true
  581. _doors.registered_trapdoors[name_closed] = true
  582. end
  583. doors.register_trapdoor("doors:trapdoor", {
  584. description = "Wooden Trapdoor",
  585. inventory_image = "doors_trapdoor.png",
  586. wield_image = "doors_trapdoor.png",
  587. tile_front = "doors_trapdoor.png",
  588. tile_side = "doors_trapdoor_side.png",
  589. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, door = 1},
  590. })
  591. doors.register_trapdoor("doors:trapdoor_steel", {
  592. description = "Steel Trapdoor",
  593. inventory_image = "doors_trapdoor_steel.png",
  594. wield_image = "doors_trapdoor_steel.png",
  595. tile_front = "doors_trapdoor_steel.png",
  596. tile_side = "doors_trapdoor_steel_side.png",
  597. protected = true,
  598. sounds = default.node_sound_metal_defaults(),
  599. sound_open = "doors_steel_door_open",
  600. sound_close = "doors_steel_door_close",
  601. groups = {cracky = 1, level = 2, door = 1},
  602. })
  603. minetest.register_craft({
  604. output = 'doors:trapdoor 2',
  605. recipe = {
  606. {'group:wood', 'group:wood', 'group:wood'},
  607. {'group:wood', 'group:wood', 'group:wood'},
  608. {'', '', ''},
  609. }
  610. })
  611. minetest.register_craft({
  612. output = 'doors:trapdoor_steel',
  613. recipe = {
  614. {'default:steel_ingot', 'default:steel_ingot'},
  615. {'default:steel_ingot', 'default:steel_ingot'},
  616. }
  617. })
  618. ----fence gate----
  619. function doors.register_fencegate(name, def)
  620. local fence = {
  621. description = def.description,
  622. drawtype = "mesh",
  623. tiles = {},
  624. paramtype = "light",
  625. paramtype2 = "facedir",
  626. sunlight_propagates = true,
  627. is_ground_content = false,
  628. drop = name .. "_closed",
  629. connect_sides = {"left", "right"},
  630. groups = def.groups,
  631. sounds = def.sounds,
  632. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  633. local node_def = minetest.registered_nodes[node.name]
  634. minetest.swap_node(pos, {name = node_def.gate, param2 = node.param2})
  635. minetest.sound_play(node_def.sound, {pos = pos, gain = 0.3,
  636. max_hear_distance = 8})
  637. return itemstack
  638. end,
  639. selection_box = {
  640. type = "fixed",
  641. fixed = {-1/2, -1/2, -1/4, 1/2, 1/2, 1/4},
  642. },
  643. }
  644. if type(def.texture) == "string" then
  645. fence.tiles[1] = {name = def.texture, backface_culling = true}
  646. elseif def.texture.backface_culling == nil then
  647. fence.tiles[1] = table.copy(def.texture)
  648. fence.tiles[1].backface_culling = true
  649. else
  650. fence.tiles[1] = def.texture
  651. end
  652. if not fence.sounds then
  653. fence.sounds = default.node_sound_wood_defaults()
  654. end
  655. fence.groups.fence = 1
  656. local fence_closed = table.copy(fence)
  657. fence_closed.mesh = "doors_fencegate_closed.obj"
  658. fence_closed.gate = name .. "_open"
  659. fence_closed.sound = "doors_fencegate_open"
  660. fence_closed.collision_box = {
  661. type = "fixed",
  662. fixed = {-1/2, -1/2, -1/4, 1/2, 1/2, 1/4},
  663. }
  664. local fence_open = table.copy(fence)
  665. fence_open.mesh = "doors_fencegate_open.obj"
  666. fence_open.gate = name .. "_closed"
  667. fence_open.sound = "doors_fencegate_close"
  668. fence_open.groups.not_in_creative_inventory = 1
  669. fence_open.collision_box = {
  670. type = "fixed",
  671. fixed = {{-1/2, -1/2, -1/4, -3/8, 1/2, 1/4},
  672. {-1/2, -3/8, -1/2, -3/8, 3/8, 0}},
  673. }
  674. minetest.register_node(":" .. name .. "_closed", fence_closed)
  675. minetest.register_node(":" .. name .. "_open", fence_open)
  676. minetest.register_craft({
  677. output = name .. "_closed",
  678. recipe = {
  679. {"default:stick", def.material, "default:stick"},
  680. {"default:stick", def.material, "default:stick"}
  681. }
  682. })
  683. end
  684. doors.register_fencegate("doors:gate_wood", {
  685. description = "Apple Wood Fence Gate",
  686. texture = "default_wood.png",
  687. material = "default:wood",
  688. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
  689. })
  690. doors.register_fencegate("doors:gate_acacia_wood", {
  691. description = "Acacia Wood Fence Gate",
  692. texture = "default_acacia_wood.png",
  693. material = "default:acacia_wood",
  694. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
  695. })
  696. doors.register_fencegate("doors:gate_junglewood", {
  697. description = "Jungle Wood Fence Gate",
  698. texture = "default_junglewood.png",
  699. material = "default:junglewood",
  700. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
  701. })
  702. doors.register_fencegate("doors:gate_pine_wood", {
  703. description = "Pine Wood Fence Gate",
  704. texture = "default_pine_wood.png",
  705. material = "default:pine_wood",
  706. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3}
  707. })
  708. doors.register_fencegate("doors:gate_aspen_wood", {
  709. description = "Aspen Wood Fence Gate",
  710. texture = "default_aspen_wood.png",
  711. material = "default:aspen_wood",
  712. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3}
  713. })
  714. ----fuels----
  715. minetest.register_craft({
  716. type = "fuel",
  717. recipe = "doors:trapdoor",
  718. burntime = 7,
  719. })
  720. minetest.register_craft({
  721. type = "fuel",
  722. recipe = "doors:door_wood",
  723. burntime = 14,
  724. })
  725. minetest.register_craft({
  726. type = "fuel",
  727. recipe = "doors:gate_wood_closed",
  728. burntime = 7,
  729. })
  730. minetest.register_craft({
  731. type = "fuel",
  732. recipe = "doors:gate_acacia_wood_closed",
  733. burntime = 8,
  734. })
  735. minetest.register_craft({
  736. type = "fuel",
  737. recipe = "doors:gate_junglewood_closed",
  738. burntime = 9,
  739. })
  740. minetest.register_craft({
  741. type = "fuel",
  742. recipe = "doors:gate_pine_wood_closed",
  743. burntime = 6,
  744. })
  745. minetest.register_craft({
  746. type = "fuel",
  747. recipe = "doors:gate_aspen_wood_closed",
  748. burntime = 5,
  749. })