init.lua 23 KB

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