2
0

init.lua 24 KB

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