init.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  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 = 0.3, max_hear_distance = 10}, true)
  158. else
  159. minetest.sound_play(def.door.sounds[2],
  160. {pos = pos, gain = 0.3, 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 not pointed_thing.type == "node" then
  238. return itemstack
  239. end
  240. local node = minetest.get_node(pointed_thing.under)
  241. local pdef = minetest.registered_nodes[node.name]
  242. if pdef and pdef.on_rightclick and
  243. not (placer and placer:is_player() and
  244. placer:get_player_control().sneak) then
  245. return pdef.on_rightclick(pointed_thing.under,
  246. node, placer, itemstack, pointed_thing)
  247. end
  248. if pdef and pdef.buildable_to then
  249. pos = pointed_thing.under
  250. else
  251. pos = pointed_thing.above
  252. node = minetest.get_node(pos)
  253. pdef = minetest.registered_nodes[node.name]
  254. if not pdef or not pdef.buildable_to then
  255. return itemstack
  256. end
  257. end
  258. local above = {x = pos.x, y = pos.y + 1, z = pos.z}
  259. local top_node = minetest.get_node_or_nil(above)
  260. local topdef = top_node and minetest.registered_nodes[top_node.name]
  261. if not topdef or not topdef.buildable_to then
  262. return itemstack
  263. end
  264. local pn = placer and placer:get_player_name() or ""
  265. if minetest.is_protected(pos, pn) or minetest.is_protected(above, pn) then
  266. return itemstack
  267. end
  268. local dir = placer and minetest.dir_to_facedir(placer:get_look_dir()) or 0
  269. local ref = {
  270. {x = -1, y = 0, z = 0},
  271. {x = 0, y = 0, z = 1},
  272. {x = 1, y = 0, z = 0},
  273. {x = 0, y = 0, z = -1},
  274. }
  275. local aside = {
  276. x = pos.x + ref[dir + 1].x,
  277. y = pos.y + ref[dir + 1].y,
  278. z = pos.z + ref[dir + 1].z,
  279. }
  280. local state = 0
  281. if minetest.get_item_group(minetest.get_node(aside).name, "door") == 1 then
  282. state = state + 2
  283. minetest.set_node(pos, {name = name .. "_b", param2 = dir})
  284. minetest.set_node(above, {name = "doors:hidden", param2 = (dir + 3) % 4})
  285. else
  286. minetest.set_node(pos, {name = name .. "_a", param2 = dir})
  287. minetest.set_node(above, {name = "doors:hidden", param2 = dir})
  288. end
  289. local meta = minetest.get_meta(pos)
  290. meta:set_int("state", state)
  291. if def.protected then
  292. meta:set_string("owner", pn)
  293. meta:set_string("infotext", def.description .. "\n" .. S("Owned by @1", pn))
  294. end
  295. if not minetest.is_creative_enabled(pn) then
  296. itemstack:take_item()
  297. end
  298. minetest.sound_play(def.sounds.place, {pos = pos}, true)
  299. on_place_node(pos, minetest.get_node(pos),
  300. placer, node, itemstack, pointed_thing)
  301. return itemstack
  302. end
  303. })
  304. def.inventory_image = nil
  305. if def.recipe then
  306. minetest.register_craft({
  307. output = name,
  308. recipe = def.recipe,
  309. })
  310. end
  311. def.recipe = nil
  312. if not def.sounds then
  313. def.sounds = default.node_sound_wood_defaults()
  314. end
  315. if not def.sound_open then
  316. def.sound_open = "doors_door_open"
  317. end
  318. if not def.sound_close then
  319. def.sound_close = "doors_door_close"
  320. end
  321. def.groups.not_in_creative_inventory = 1
  322. def.groups.door = 1
  323. def.drop = name
  324. def.door = {
  325. name = name,
  326. sounds = { def.sound_close, def.sound_open },
  327. }
  328. if not def.on_rightclick then
  329. def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  330. doors.door_toggle(pos, node, clicker)
  331. return itemstack
  332. end
  333. end
  334. def.after_dig_node = function(pos, node, meta, digger)
  335. minetest.remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
  336. minetest.check_for_falling({x = pos.x, y = pos.y + 1, z = pos.z})
  337. end
  338. def.on_rotate = function(pos, node, user, mode, new_param2)
  339. return false
  340. end
  341. if def.protected then
  342. def.can_dig = can_dig_door
  343. def.on_blast = function() end
  344. def.on_key_use = function(pos, player)
  345. local door = doors.get(pos)
  346. door:toggle(player)
  347. end
  348. def.on_skeleton_key_use = function(pos, player, newsecret)
  349. replace_old_owner_information(pos)
  350. local meta = minetest.get_meta(pos)
  351. local owner = meta:get_string("owner")
  352. local pname = player:get_player_name()
  353. -- verify placer is owner of lockable door
  354. if owner ~= pname then
  355. minetest.record_protection_violation(pos, pname)
  356. minetest.chat_send_player(pname, S("You do not own this locked door."))
  357. return nil
  358. end
  359. local secret = meta:get_string("key_lock_secret")
  360. if secret == "" then
  361. secret = newsecret
  362. meta:set_string("key_lock_secret", secret)
  363. end
  364. return secret, S("a locked door"), owner
  365. end
  366. def.node_dig_prediction = ""
  367. else
  368. def.on_blast = function(pos, intensity)
  369. minetest.remove_node(pos)
  370. -- hidden node doesn't get blasted away.
  371. minetest.remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
  372. return {name}
  373. end
  374. end
  375. def.on_destruct = function(pos)
  376. minetest.remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
  377. end
  378. def.drawtype = "mesh"
  379. def.paramtype = "light"
  380. def.paramtype2 = "facedir"
  381. def.sunlight_propagates = true
  382. def.walkable = true
  383. def.is_ground_content = false
  384. def.buildable_to = false
  385. def.selection_box = {type = "fixed", fixed = {-1/2,-1/2,-1/2,1/2,3/2,-6/16}}
  386. def.collision_box = {type = "fixed", fixed = {-1/2,-1/2,-1/2,1/2,3/2,-6/16}}
  387. def.use_texture_alpha = "clip"
  388. def.mesh = "door_a.obj"
  389. minetest.register_node(":" .. name .. "_a", def)
  390. def.mesh = "door_b.obj"
  391. minetest.register_node(":" .. name .. "_b", def)
  392. def.mesh = "door_a2.obj"
  393. minetest.register_node(":" .. name .. "_c", def)
  394. def.mesh = "door_b2.obj"
  395. minetest.register_node(":" .. name .. "_d", def)
  396. doors.registered_doors[name .. "_a"] = true
  397. doors.registered_doors[name .. "_b"] = true
  398. doors.registered_doors[name .. "_c"] = true
  399. doors.registered_doors[name .. "_d"] = true
  400. end
  401. doors.register("door_wood", {
  402. tiles = {{ name = "doors_door_wood.png", backface_culling = true }},
  403. description = S("Wooden Door"),
  404. inventory_image = "doors_item_wood.png",
  405. groups = {node = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
  406. recipe = {
  407. {"group:wood", "group:wood"},
  408. {"group:wood", "group:wood"},
  409. {"group:wood", "group:wood"},
  410. }
  411. })
  412. doors.register("door_steel", {
  413. tiles = {{name = "doors_door_steel.png", backface_culling = true}},
  414. description = S("Steel Door"),
  415. inventory_image = "doors_item_steel.png",
  416. protected = true,
  417. groups = {node = 1, cracky = 1, level = 2},
  418. sounds = default.node_sound_metal_defaults(),
  419. sound_open = "doors_steel_door_open",
  420. sound_close = "doors_steel_door_close",
  421. recipe = {
  422. {"default:steel_ingot", "default:steel_ingot"},
  423. {"default:steel_ingot", "default:steel_ingot"},
  424. {"default:steel_ingot", "default:steel_ingot"},
  425. }
  426. })
  427. doors.register("door_glass", {
  428. tiles = {"doors_door_glass.png"},
  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. description = S("Obsidian Glass Door"),
  444. inventory_image = "doors_item_obsidian_glass.png",
  445. groups = {node = 1, cracky=3},
  446. sounds = default.node_sound_glass_defaults(),
  447. sound_open = "doors_glass_door_open",
  448. sound_close = "doors_glass_door_close",
  449. recipe = {
  450. {"default:obsidian_glass", "default:obsidian_glass"},
  451. {"default:obsidian_glass", "default:obsidian_glass"},
  452. {"default:obsidian_glass", "default:obsidian_glass"},
  453. },
  454. })
  455. -- Capture mods using the old API as best as possible.
  456. function doors.register_door(name, def)
  457. if def.only_placer_can_open then
  458. def.protected = true
  459. end
  460. def.only_placer_can_open = nil
  461. local i = name:find(":")
  462. local modname = name:sub(1, i - 1)
  463. if not def.tiles then
  464. if def.protected then
  465. def.tiles = {{name = "doors_door_steel.png", backface_culling = true}}
  466. else
  467. def.tiles = {{name = "doors_door_wood.png", backface_culling = true}}
  468. end
  469. minetest.log("warning", modname .. " registered door \"" .. name .. "\" " ..
  470. "using deprecated API method \"doors.register_door()\" but " ..
  471. "did not provide the \"tiles\" parameter. A fallback tiledef " ..
  472. "will be used instead.")
  473. end
  474. doors.register(name, def)
  475. end
  476. ----trapdoor----
  477. function doors.trapdoor_toggle(pos, node, clicker)
  478. node = node or minetest.get_node(pos)
  479. replace_old_owner_information(pos)
  480. if clicker and not default.can_interact_with_node(clicker, pos) then
  481. return false
  482. end
  483. local def = minetest.registered_nodes[node.name]
  484. if string.sub(node.name, -5) == "_open" then
  485. minetest.sound_play(def.sound_close,
  486. {pos = pos, gain = 0.3, max_hear_distance = 10}, true)
  487. minetest.swap_node(pos, {name = string.sub(node.name, 1,
  488. string.len(node.name) - 5), param1 = node.param1, param2 = node.param2})
  489. else
  490. minetest.sound_play(def.sound_open,
  491. {pos = pos, gain = 0.3, max_hear_distance = 10}, true)
  492. minetest.swap_node(pos, {name = node.name .. "_open",
  493. param1 = node.param1, param2 = node.param2})
  494. end
  495. end
  496. function doors.register_trapdoor(name, def)
  497. if not name:find(":") then
  498. name = "doors:" .. name
  499. end
  500. local name_closed = name
  501. local name_opened = name.."_open"
  502. def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  503. doors.trapdoor_toggle(pos, node, clicker)
  504. return itemstack
  505. end
  506. -- Common trapdoor configuration
  507. def.drawtype = "nodebox"
  508. def.paramtype = "light"
  509. def.paramtype2 = "facedir"
  510. def.is_ground_content = false
  511. def.use_texture_alpha = "clip"
  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 minetest.is_creative_enabled(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. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, door = 1},
  608. })
  609. doors.register_trapdoor("doors:trapdoor_steel", {
  610. description = S("Steel Trapdoor"),
  611. inventory_image = "doors_trapdoor_steel.png",
  612. wield_image = "doors_trapdoor_steel.png",
  613. tile_front = "doors_trapdoor_steel.png",
  614. tile_side = "doors_trapdoor_steel_side.png",
  615. protected = true,
  616. sounds = default.node_sound_metal_defaults(),
  617. sound_open = "doors_steel_door_open",
  618. sound_close = "doors_steel_door_close",
  619. groups = {cracky = 1, level = 2, door = 1},
  620. })
  621. minetest.register_craft({
  622. output = "doors:trapdoor 2",
  623. recipe = {
  624. {"group:wood", "group:wood", "group:wood"},
  625. {"group:wood", "group:wood", "group:wood"},
  626. {"", "", ""},
  627. }
  628. })
  629. minetest.register_craft({
  630. output = "doors:trapdoor_steel",
  631. recipe = {
  632. {"default:steel_ingot", "default:steel_ingot"},
  633. {"default:steel_ingot", "default:steel_ingot"},
  634. }
  635. })
  636. ----fence gate----
  637. local fence_collision_extra = minetest.settings:get_bool("enable_fence_tall") and 3/8 or 0
  638. function doors.register_fencegate(name, def)
  639. local fence = {
  640. description = def.description,
  641. drawtype = "mesh",
  642. tiles = {},
  643. paramtype = "light",
  644. paramtype2 = "facedir",
  645. sunlight_propagates = true,
  646. is_ground_content = false,
  647. drop = name .. "_closed",
  648. connect_sides = {"left", "right"},
  649. groups = def.groups,
  650. sounds = def.sounds,
  651. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  652. local node_def = minetest.registered_nodes[node.name]
  653. minetest.swap_node(pos, {name = node_def.gate, param2 = node.param2})
  654. minetest.sound_play(node_def.sound, {pos = pos, gain = 0.3,
  655. max_hear_distance = 8}, true)
  656. return itemstack
  657. end,
  658. selection_box = {
  659. type = "fixed",
  660. fixed = {-1/2, -1/2, -1/4, 1/2, 1/2, 1/4}
  661. },
  662. }
  663. if type(def.texture) == "string" then
  664. fence.tiles[1] = {name = def.texture, backface_culling = true}
  665. elseif def.texture.backface_culling == nil then
  666. fence.tiles[1] = table.copy(def.texture)
  667. fence.tiles[1].backface_culling = true
  668. else
  669. fence.tiles[1] = def.texture
  670. end
  671. if not fence.sounds then
  672. fence.sounds = default.node_sound_wood_defaults()
  673. end
  674. fence.groups.fence = 1
  675. local fence_closed = table.copy(fence)
  676. fence_closed.mesh = "doors_fencegate_closed.obj"
  677. fence_closed.gate = name .. "_open"
  678. fence_closed.sound = "doors_fencegate_open"
  679. fence_closed.collision_box = {
  680. type = "fixed",
  681. fixed = {-1/2, -1/2, -1/8, 1/2, 1/2 + fence_collision_extra, 1/8}
  682. }
  683. local fence_open = table.copy(fence)
  684. fence_open.mesh = "doors_fencegate_open.obj"
  685. fence_open.gate = name .. "_closed"
  686. fence_open.sound = "doors_fencegate_close"
  687. fence_open.groups.not_in_creative_inventory = 1
  688. fence_open.collision_box = {
  689. type = "fixed",
  690. fixed = {{-1/2, -1/2, -1/8, -3/8, 1/2 + fence_collision_extra, 1/8},
  691. {-1/2, -3/8, -1/2, -3/8, 3/8, 0 }}
  692. }
  693. minetest.register_node(":" .. name .. "_closed", fence_closed)
  694. minetest.register_node(":" .. name .. "_open", fence_open)
  695. minetest.register_craft({
  696. output = name .. "_closed",
  697. recipe = {
  698. {"group:stick", def.material, "group:stick"},
  699. {"group:stick", def.material, "group:stick"}
  700. }
  701. })
  702. end
  703. doors.register_fencegate("doors:gate_wood", {
  704. description = S("Apple Wood Fence Gate"),
  705. texture = "default_wood.png",
  706. material = "default:wood",
  707. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
  708. })
  709. doors.register_fencegate("doors:gate_acacia_wood", {
  710. description = S("Acacia Wood Fence Gate"),
  711. texture = "default_acacia_wood.png",
  712. material = "default:acacia_wood",
  713. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
  714. })
  715. doors.register_fencegate("doors:gate_junglewood", {
  716. description = S("Jungle Wood Fence Gate"),
  717. texture = "default_junglewood.png",
  718. material = "default:junglewood",
  719. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}
  720. })
  721. doors.register_fencegate("doors:gate_pine_wood", {
  722. description = S("Pine Wood Fence Gate"),
  723. texture = "default_pine_wood.png",
  724. material = "default:pine_wood",
  725. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3}
  726. })
  727. doors.register_fencegate("doors:gate_aspen_wood", {
  728. description = S("Aspen Wood Fence Gate"),
  729. texture = "default_aspen_wood.png",
  730. material = "default:aspen_wood",
  731. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3}
  732. })
  733. ----fuels----
  734. minetest.register_craft({
  735. type = "fuel",
  736. recipe = "doors:trapdoor",
  737. burntime = 7,
  738. })
  739. minetest.register_craft({
  740. type = "fuel",
  741. recipe = "doors:door_wood",
  742. burntime = 14,
  743. })
  744. minetest.register_craft({
  745. type = "fuel",
  746. recipe = "doors:gate_wood_closed",
  747. burntime = 7,
  748. })
  749. minetest.register_craft({
  750. type = "fuel",
  751. recipe = "doors:gate_acacia_wood_closed",
  752. burntime = 8,
  753. })
  754. minetest.register_craft({
  755. type = "fuel",
  756. recipe = "doors:gate_junglewood_closed",
  757. burntime = 9,
  758. })
  759. minetest.register_craft({
  760. type = "fuel",
  761. recipe = "doors:gate_pine_wood_closed",
  762. burntime = 6,
  763. })
  764. minetest.register_craft({
  765. type = "fuel",
  766. recipe = "doors:gate_aspen_wood_closed",
  767. burntime = 5,
  768. })