init.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  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. use_texture_alpha = 'clip',
  401. description = S("Wooden Door"),
  402. inventory_image = "doors_item_wood.png",
  403. groups = {node = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
  404. recipe = {
  405. {"group:wood", "group:wood"},
  406. {"group:wood", "group:wood"},
  407. {"group:wood", "group:wood"},
  408. }
  409. })
  410. doors.register("door_steel", {
  411. tiles = {{name = "doors_door_steel.png", backface_culling = true}},
  412. use_texture_alpha = 'clip',
  413. description = S("Steel Door"),
  414. inventory_image = "doors_item_steel.png",
  415. protected = true,
  416. groups = {node = 1, cracky = 1, level = 2},
  417. sounds = default.node_sound_metal_defaults(),
  418. sound_open = "doors_steel_door_open",
  419. sound_close = "doors_steel_door_close",
  420. recipe = {
  421. {"default:steel_ingot", "default:steel_ingot"},
  422. {"default:steel_ingot", "default:steel_ingot"},
  423. {"default:steel_ingot", "default:steel_ingot"},
  424. }
  425. })
  426. doors.register("door_glass", {
  427. tiles = {"doors_door_glass.png"},
  428. use_texture_alpha = 'clip',
  429. description = S("Glass Door"),
  430. inventory_image = "doors_item_glass.png",
  431. groups = {node = 1, cracky=3, oddly_breakable_by_hand=3},
  432. sounds = default.node_sound_glass_defaults(),
  433. sound_open = "doors_glass_door_open",
  434. sound_close = "doors_glass_door_close",
  435. recipe = {
  436. {"default:glass", "default:glass"},
  437. {"default:glass", "default:glass"},
  438. {"default:glass", "default:glass"},
  439. }
  440. })
  441. doors.register("door_obsidian_glass", {
  442. tiles = {"doors_door_obsidian_glass.png"},
  443. use_texture_alpha = 'clip',
  444. description = S("Obsidian Glass Door"),
  445. inventory_image = "doors_item_obsidian_glass.png",
  446. groups = {node = 1, cracky=3},
  447. sounds = default.node_sound_glass_defaults(),
  448. sound_open = "doors_glass_door_open",
  449. sound_close = "doors_glass_door_close",
  450. recipe = {
  451. {"default:obsidian_glass", "default:obsidian_glass"},
  452. {"default:obsidian_glass", "default:obsidian_glass"},
  453. {"default:obsidian_glass", "default:obsidian_glass"},
  454. },
  455. })
  456. -- Capture mods using the old API as best as possible.
  457. function doors.register_door(name, def)
  458. if def.only_placer_can_open then
  459. def.protected = true
  460. end
  461. def.only_placer_can_open = nil
  462. local i = name:find(":")
  463. local modname = name:sub(1, i - 1)
  464. if not def.tiles then
  465. if def.protected then
  466. def.tiles = {{name = "doors_door_steel.png", backface_culling = true}}
  467. else
  468. def.tiles = {{name = "doors_door_wood.png", backface_culling = true}}
  469. end
  470. minetest.log("warning", modname .. " registered door \"" .. name .. "\" " ..
  471. "using deprecated API method \"doors.register_door()\" but " ..
  472. "did not provide the \"tiles\" parameter. A fallback tiledef " ..
  473. "will be used instead.")
  474. end
  475. doors.register(name, def)
  476. end
  477. ----trapdoor----
  478. function doors.trapdoor_toggle(pos, node, clicker)
  479. node = node or minetest.get_node(pos)
  480. replace_old_owner_information(pos)
  481. if clicker and not default.can_interact_with_node(clicker, pos) then
  482. return false
  483. end
  484. local def = minetest.registered_nodes[node.name]
  485. if string.sub(node.name, -5) == "_open" then
  486. minetest.sound_play(def.sound_close,
  487. {pos = pos, gain = 0.3, max_hear_distance = 10}, true)
  488. minetest.swap_node(pos, {name = string.sub(node.name, 1,
  489. string.len(node.name) - 5), param1 = node.param1, param2 = node.param2})
  490. else
  491. minetest.sound_play(def.sound_open,
  492. {pos = pos, gain = 0.3, max_hear_distance = 10}, true)
  493. minetest.swap_node(pos, {name = node.name .. "_open",
  494. param1 = node.param1, param2 = node.param2})
  495. end
  496. end
  497. function doors.register_trapdoor(name, def)
  498. if not name:find(":") then
  499. name = "doors:" .. name
  500. end
  501. local name_closed = name
  502. local name_opened = name.."_open"
  503. def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  504. doors.trapdoor_toggle(pos, node, clicker)
  505. return itemstack
  506. end
  507. -- Common trapdoor configuration
  508. def.drawtype = "nodebox"
  509. def.paramtype = "light"
  510. def.paramtype2 = "facedir"
  511. def.is_ground_content = false
  512. if def.protected then
  513. def.can_dig = can_dig_door
  514. def.after_place_node = function(pos, placer, itemstack, pointed_thing)
  515. local pn = placer:get_player_name()
  516. local meta = minetest.get_meta(pos)
  517. meta:set_string("owner", pn)
  518. meta:set_string("infotext", def.description .. "\n" .. S("Owned by @1", pn))
  519. return (creative and creative.is_enabled_for and creative.is_enabled_for(pn))
  520. end
  521. def.on_blast = function() end
  522. def.on_key_use = function(pos, player)
  523. local door = doors.get(pos)
  524. door:toggle(player)
  525. end
  526. def.on_skeleton_key_use = function(pos, player, newsecret)
  527. replace_old_owner_information(pos)
  528. local meta = minetest.get_meta(pos)
  529. local owner = meta:get_string("owner")
  530. local pname = player:get_player_name()
  531. -- verify placer is owner of lockable door
  532. if owner ~= pname then
  533. minetest.record_protection_violation(pos, pname)
  534. minetest.chat_send_player(pname, S("You do not own this trapdoor."))
  535. return nil
  536. end
  537. local secret = meta:get_string("key_lock_secret")
  538. if secret == "" then
  539. secret = newsecret
  540. meta:set_string("key_lock_secret", secret)
  541. end
  542. return secret, S("a locked trapdoor"), owner
  543. end
  544. def.node_dig_prediction = ""
  545. else
  546. def.on_blast = function(pos, intensity)
  547. minetest.remove_node(pos)
  548. return {name}
  549. end
  550. end
  551. if not def.sounds then
  552. def.sounds = default.node_sound_wood_defaults()
  553. end
  554. if not def.sound_open then
  555. def.sound_open = "doors_door_open"
  556. end
  557. if not def.sound_close then
  558. def.sound_close = "doors_door_close"
  559. end
  560. local def_opened = table.copy(def)
  561. local def_closed = table.copy(def)
  562. def_closed.node_box = {
  563. type = "fixed",
  564. fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
  565. }
  566. def_closed.selection_box = {
  567. type = "fixed",
  568. fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
  569. }
  570. def_closed.tiles = {
  571. def.tile_front,
  572. def.tile_front .. '^[transformFY',
  573. def.tile_side,
  574. def.tile_side,
  575. def.tile_side,
  576. def.tile_side
  577. }
  578. def_opened.node_box = {
  579. type = "fixed",
  580. fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
  581. }
  582. def_opened.selection_box = {
  583. type = "fixed",
  584. fixed = {-0.5, -0.5, 6/16, 0.5, 0.5, 0.5}
  585. }
  586. def_opened.tiles = {
  587. def.tile_side,
  588. def.tile_side .. '^[transform2',
  589. def.tile_side .. '^[transform3',
  590. def.tile_side .. '^[transform1',
  591. def.tile_front .. '^[transform46',
  592. def.tile_front .. '^[transform6'
  593. }
  594. def_opened.drop = name_closed
  595. def_opened.groups.not_in_creative_inventory = 1
  596. minetest.register_node(name_opened, def_opened)
  597. minetest.register_node(name_closed, def_closed)
  598. doors.registered_trapdoors[name_opened] = true
  599. doors.registered_trapdoors[name_closed] = true
  600. end
  601. doors.register_trapdoor("doors:trapdoor", {
  602. description = S("Wooden Trapdoor"),
  603. inventory_image = "doors_trapdoor.png",
  604. wield_image = "doors_trapdoor.png",
  605. tile_front = "doors_trapdoor.png",
  606. tile_side = "doors_trapdoor_side.png",
  607. use_texture_alpha = 'clip',
  608. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, door = 1},
  609. })
  610. doors.register_trapdoor("doors:trapdoor_steel", {
  611. description = S("Steel Trapdoor"),
  612. inventory_image = "doors_trapdoor_steel.png",
  613. wield_image = "doors_trapdoor_steel.png",
  614. tile_front = "doors_trapdoor_steel.png",
  615. tile_side = "doors_trapdoor_steel_side.png",
  616. use_texture_alpha = 'clip',
  617. protected = true,
  618. sounds = default.node_sound_metal_defaults(),
  619. sound_open = "doors_steel_door_open",
  620. sound_close = "doors_steel_door_close",
  621. groups = {cracky = 1, level = 2, door = 1},
  622. })
  623. minetest.register_craft({
  624. output = "doors:trapdoor 2",
  625. recipe = {
  626. {"group:wood", "group:wood", "group:wood"},
  627. {"group:wood", "group:wood", "group:wood"},
  628. {"", "", ""},
  629. }
  630. })
  631. minetest.register_craft({
  632. output = "doors:trapdoor_steel",
  633. recipe = {
  634. {"default:steel_ingot", "default:steel_ingot"},
  635. {"default:steel_ingot", "default:steel_ingot"},
  636. }
  637. })
  638. ----fence gate----
  639. local fence_collision_extra = minetest.settings:get_bool("enable_fence_tall") and 3/8 or 0
  640. function doors.register_fencegate(name, def)
  641. local fence = {
  642. description = def.description,
  643. drawtype = "mesh",
  644. tiles = {},
  645. paramtype = "light",
  646. paramtype2 = "facedir",
  647. sunlight_propagates = true,
  648. is_ground_content = false,
  649. drop = name .. "_closed",
  650. connect_sides = {"left", "right"},
  651. groups = def.groups,
  652. sounds = def.sounds,
  653. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  654. local node_def = minetest.registered_nodes[node.name]
  655. minetest.swap_node(pos, {name = node_def._gate, param2 = node.param2})
  656. minetest.sound_play(node_def._gate_sound, {pos = pos, gain = 0.15,
  657. max_hear_distance = 8}, true)
  658. return itemstack
  659. end,
  660. selection_box = {
  661. type = "fixed",
  662. fixed = {-1/2, -1/2, -1/4, 1/2, 1/2, 1/4}
  663. },
  664. }
  665. if type(def.texture) == "string" then
  666. fence.tiles[1] = {name = def.texture, backface_culling = true}
  667. elseif def.texture.backface_culling == nil then
  668. fence.tiles[1] = table.copy(def.texture)
  669. fence.tiles[1].backface_culling = true
  670. else
  671. fence.tiles[1] = def.texture
  672. end
  673. if not fence.sounds then
  674. fence.sounds = default.node_sound_wood_defaults()
  675. end
  676. fence.groups.fence = 1
  677. local fence_closed = table.copy(fence)
  678. fence_closed.mesh = "doors_fencegate_closed.obj"
  679. fence_closed._gate = name .. "_open"
  680. fence_closed._gate_sound = "doors_fencegate_open"
  681. fence_closed.collision_box = {
  682. type = "fixed",
  683. fixed = {-1/2, -1/2, -1/8, 1/2, 1/2 + fence_collision_extra, 1/8}
  684. }
  685. local fence_open = table.copy(fence)
  686. fence_open.mesh = "doors_fencegate_open.obj"
  687. fence_open._gate = name .. "_closed"
  688. fence_open._gate_sound = "doors_fencegate_close"
  689. fence_open.groups.not_in_creative_inventory = 1
  690. fence_open.collision_box = {
  691. type = "fixed",
  692. fixed = {{-1/2, -1/2, -1/8, -3/8, 1/2 + fence_collision_extra, 1/8},
  693. {-1/2, -3/8, -1/2, -3/8, 3/8, 0 }}
  694. }
  695. minetest.register_node(":" .. name .. "_closed", fence_closed)
  696. minetest.register_node(":" .. name .. "_open", fence_open)
  697. minetest.register_craft({
  698. output = name .. "_closed",
  699. recipe = {
  700. {"group:stick", def.material, "group:stick"},
  701. {"group:stick", def.material, "group:stick"}
  702. }
  703. })
  704. end
  705. doors.register_fencegate("doors:gate_wood", {
  706. description = S("Apple Wood Fence Gate"),
  707. texture = "default_wood.png",
  708. material = "default:wood",
  709. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
  710. })
  711. doors.register_fencegate("doors:gate_acacia_wood", {
  712. description = S("Acacia Wood Fence Gate"),
  713. texture = "default_acacia_wood.png",
  714. material = "default:acacia_wood",
  715. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
  716. })
  717. doors.register_fencegate("doors:gate_junglewood", {
  718. description = S("Jungle Wood Fence Gate"),
  719. texture = "default_junglewood.png",
  720. material = "default:junglewood",
  721. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
  722. })
  723. doors.register_fencegate("doors:gate_pine_wood", {
  724. description = S("Pine Wood Fence Gate"),
  725. texture = "default_pine_wood.png",
  726. material = "default:pine_wood",
  727. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3}
  728. })
  729. doors.register_fencegate("doors:gate_aspen_wood", {
  730. description = S("Aspen Wood Fence Gate"),
  731. texture = "default_aspen_wood.png",
  732. material = "default:aspen_wood",
  733. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3}
  734. })
  735. ----fuels----
  736. minetest.register_craft({
  737. type = "fuel",
  738. recipe = "doors:trapdoor",
  739. burntime = 7,
  740. })
  741. minetest.register_craft({
  742. type = "fuel",
  743. recipe = "doors:door_wood",
  744. burntime = 14,
  745. })
  746. minetest.register_craft({
  747. type = "fuel",
  748. recipe = "doors:gate_wood_closed",
  749. burntime = 7,
  750. })
  751. minetest.register_craft({
  752. type = "fuel",
  753. recipe = "doors:gate_acacia_wood_closed",
  754. burntime = 8,
  755. })
  756. minetest.register_craft({
  757. type = "fuel",
  758. recipe = "doors:gate_junglewood_closed",
  759. burntime = 9,
  760. })
  761. minetest.register_craft({
  762. type = "fuel",
  763. recipe = "doors:gate_pine_wood_closed",
  764. burntime = 6,
  765. })
  766. minetest.register_craft({
  767. type = "fuel",
  768. recipe = "doors:gate_aspen_wood_closed",
  769. burntime = 5,
  770. })