nodes_doorlike.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. -----------------------------------------------------------------------------------------------------------
  2. -- These nodes are all like doors in a way:
  3. -- * window shutters (they open on right-click and when it turns day; they close at night)
  4. -- * a half-door where the top part can be opened seperately from the bottom part
  5. -- * a gate that drops to the floor when opened
  6. --
  7. -----------------------------------------------------------------------------------------------------------
  8. -- IMPORTANT NOTICE: If you have a very slow computer, it might be wise to increase the rate at which the
  9. -- abm that opens/closes the window shutters is called. Anything less than 10 minutes
  10. -- (600 seconds) ought to be ok.
  11. -----------------------------------------------------------------------------------------------------------
  12. local S = cottages.S
  13. -----------------------------------------------------------------------------------------------------------
  14. -- small window shutters for single-node-windows; they open at day and close at night if the abm is working
  15. -----------------------------------------------------------------------------------------------------------
  16. -- propagate shutting/closing of window shutters to window shutters below/above this one
  17. cottages_window_sutter_operate = function( pos, old_node_state_name, new_node_state_name )
  18. local offsets = {-1,1,-2,2,-3,3};
  19. local stop_up = 0;
  20. local stop_down = 0;
  21. for i,v in ipairs(offsets) do
  22. local node = minetest.get_node_or_nil( {x=pos.x, y=(pos.y+v), z=pos.z } );
  23. if( node and node.name and node.name==old_node_state_name
  24. and ( (v > 0 and stop_up == 0 )
  25. or (v < 0 and stop_down == 0 ))) then
  26. minetest.swap_node({x=pos.x, y=(pos.y+v), z=pos.z }, {name = new_node_state_name, param2 = node.param2})
  27. -- found a diffrent node - no need to search further up
  28. elseif( v > 0 and stop_up == 0 ) then
  29. stop_up = 1;
  30. elseif( v < 0 and stop_down == 0 ) then
  31. stop_down = 1;
  32. end
  33. end
  34. end
  35. -- window shutters - they cover half a node to each side
  36. minetest.register_node("cottages:window_shutter_open", {
  37. description = S("opened window shutters"),
  38. drawtype = "nodebox",
  39. -- top, bottom, side1, side2, inner, outer
  40. tiles = {"cottages_minimal_wood.png"},
  41. paramtype = "light",
  42. paramtype2 = "facedir",
  43. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
  44. -- larger than one node but slightly smaller than a half node so that wallmounted torches pose no problem
  45. node_box = {
  46. type = "fixed",
  47. fixed = {
  48. {-0.90, -0.5, 0.4, -0.45, 0.5, 0.5},
  49. { 0.45, -0.5, 0.4, 0.9, 0.5, 0.5},
  50. },
  51. },
  52. selection_box = {
  53. type = "fixed",
  54. fixed = {
  55. {-0.9, -0.5, 0.4, 0.9, 0.5, 0.5},
  56. },
  57. },
  58. on_rightclick = function(pos, node, puncher)
  59. minetest.swap_node(pos, {name = "cottages:window_shutter_closed", param2 = node.param2})
  60. cottages_window_sutter_operate( pos, "cottages:window_shutter_open", "cottages:window_shutter_closed" );
  61. end,
  62. is_ground_content = false,
  63. })
  64. minetest.register_node("cottages:window_shutter_closed", {
  65. description = S("closed window shutters"),
  66. drawtype = "nodebox",
  67. -- top, bottom, side1, side2, inner, outer
  68. tiles = {"cottages_minimal_wood.png"},
  69. paramtype = "light",
  70. paramtype2 = "facedir",
  71. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
  72. node_box = {
  73. type = "fixed",
  74. fixed = {
  75. {-0.5, -0.5, 0.4, -0.05, 0.5, 0.5},
  76. { 0.05, -0.5, 0.4, 0.5, 0.5, 0.5},
  77. },
  78. },
  79. selection_box = {
  80. type = "fixed",
  81. fixed = {
  82. {-0.5, -0.5, 0.4, 0.5, 0.5, 0.5},
  83. },
  84. },
  85. on_rightclick = function(pos, node, puncher)
  86. minetest.swap_node(pos, {name = "cottages:window_shutter_open", param2 = node.param2})
  87. cottages_window_sutter_operate( pos, "cottages:window_shutter_closed", "cottages:window_shutter_open" );
  88. end,
  89. is_ground_content = false,
  90. drop = "cottages:window_shutter_open",
  91. })
  92. -- open shutters in the morning
  93. minetest.register_abm({
  94. nodenames = {"cottages:window_shutter_closed"},
  95. interval = 20, -- change this to 600 if your machine is too slow
  96. chance = 3, -- not all people wake up at the same time!
  97. action = function(pos)
  98. -- at this time, sleeping in a bed is not possible
  99. if( not(minetest.get_timeofday() < 0.2 or minetest.get_timeofday() > 0.805)) then
  100. local old_node = minetest.get_node( pos );
  101. minetest.swap_node(pos, {name = "cottages:window_shutter_open", param2 = old_node.param2})
  102. cottages_window_sutter_operate( pos, "cottages:window_shutter_closed", "cottages:window_shutter_open" );
  103. end
  104. end
  105. })
  106. -- close them at night
  107. minetest.register_abm({
  108. nodenames = {"cottages:window_shutter_open"},
  109. interval = 20, -- change this to 600 if your machine is too slow
  110. chance = 2,
  111. action = function(pos)
  112. -- same time at which sleeping is allowed in beds
  113. if( minetest.get_timeofday() < 0.2 or minetest.get_timeofday() > 0.805) then
  114. local old_node = minetest.get_node( pos );
  115. minetest.swap_node(pos, {name = "cottages:window_shutter_closed", param2 = old_node.param2})
  116. cottages_window_sutter_operate( pos, "cottages:window_shutter_open", "cottages:window_shutter_closed" );
  117. end
  118. end
  119. })
  120. ------------------------------------------------------------------------------------------------------------------------------
  121. -- a half door; can be combined to a full door where the upper part can be operated seperately; usually found in barns/stables
  122. ------------------------------------------------------------------------------------------------------------------------------
  123. minetest.register_node("cottages:half_door", {
  124. description = S("half door"),
  125. drawtype = "nodebox",
  126. -- top, bottom, side1, side2, inner, outer
  127. tiles = {"cottages_minimal_wood.png"},
  128. paramtype = "light",
  129. paramtype2 = "facedir",
  130. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
  131. node_box = {
  132. type = "fixed",
  133. fixed = {
  134. {-0.5, -0.5, 0.4, 0.48, 0.5, 0.5},
  135. },
  136. },
  137. selection_box = {
  138. type = "fixed",
  139. fixed = {
  140. {-0.5, -0.5, 0.4, 0.48, 0.5, 0.5},
  141. },
  142. },
  143. on_rightclick = function(pos, node, puncher)
  144. local node2 = minetest.get_node( {x=pos.x,y=(pos.y+1),z=pos.z});
  145. local param2 = node.param2;
  146. if( param2%4 == 1) then param2 = param2+1; --2;
  147. elseif( param2%4 == 2) then param2 = param2-1; --1;
  148. elseif( param2%4 == 3) then param2 = param2-3; --0;
  149. elseif( param2%4 == 0) then param2 = param2+3; --3;
  150. end;
  151. minetest.swap_node(pos, {name = "cottages:half_door", param2 = param2})
  152. -- if the node above consists of a door of the same type, open it as well
  153. -- Note: doors beneath this one are not opened! It is a special feature of these doors that they can be opend partly
  154. if( node2 ~= nil and node2.name == node.name and node2.param2==node.param2) then
  155. minetest.swap_node( {x=pos.x,y=(pos.y+1),z=pos.z}, {name = "cottages:half_door", param2 = param2})
  156. end
  157. end,
  158. is_ground_content = false,
  159. })
  160. minetest.register_node("cottages:half_door_inverted", {
  161. description = S("half door inverted"),
  162. drawtype = "nodebox",
  163. -- top, bottom, side1, side2, inner, outer
  164. tiles = {"cottages_minimal_wood.png"},
  165. paramtype = "light",
  166. paramtype2 = "facedir",
  167. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
  168. node_box = {
  169. type = "fixed",
  170. fixed = {
  171. {-0.5, -0.5, -0.5, 0.48, 0.5, -0.4},
  172. },
  173. },
  174. selection_box = {
  175. type = "fixed",
  176. fixed = {
  177. {-0.5, -0.5, -0.5, 0.48, 0.5, -0.4},
  178. },
  179. },
  180. on_rightclick = function(pos, node, puncher)
  181. local node2 = minetest.get_node( {x=pos.x,y=(pos.y+1),z=pos.z});
  182. local param2 = node.param2;
  183. if( param2%4 == 1) then param2 = param2-1; --0;
  184. elseif( param2%4 == 0) then param2 = param2+1; --1;
  185. elseif( param2%4 == 2) then param2 = param2+1; --3;
  186. elseif( param2%4 == 3) then param2 = param2-1; --2;
  187. end;
  188. minetest.swap_node(pos, {name = "cottages:half_door_inverted", param2 = param2})
  189. -- open upper parts of this door (if there are any)
  190. if( node2 ~= nil and node2.name == node.name and node2.param2==node.param2) then
  191. minetest.swap_node( {x=pos.x,y=(pos.y+1),z=pos.z}, {name = "cottages:half_door_inverted", param2 = param2})
  192. end
  193. end,
  194. is_ground_content = false,
  195. })
  196. ------------------------------------------------------------------------------------------------------------------------------
  197. -- this gate for fences solves the "where to store the opened gate" problem by dropping it to the floor in optened state
  198. ------------------------------------------------------------------------------------------------------------------------------
  199. minetest.register_node("cottages:gate_closed", {
  200. description = S("closed fence gate"),
  201. drawtype = "nodebox",
  202. -- top, bottom, side1, side2, inner, outer
  203. tiles = {cottages.texture_furniture},
  204. paramtype = "light",
  205. paramtype2 = "facedir",
  206. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
  207. node_box = {
  208. type = "fixed",
  209. fixed = {
  210. { -0.85, -0.25, -0.02, 0.85, -0.05, 0.02},
  211. { -0.85, 0.15, -0.02, 0.85, 0.35, 0.02},
  212. { -0.80, -0.05, -0.02, -0.60, 0.15, 0.02},
  213. { 0.60, -0.05, -0.02, 0.80, 0.15, 0.02},
  214. { -0.15, -0.05, -0.02, 0.15, 0.15, 0.02},
  215. },
  216. },
  217. selection_box = {
  218. type = "fixed",
  219. fixed = {
  220. { -0.85, -0.25, -0.1, 0.85, 0.35, 0.1},
  221. },
  222. },
  223. on_rightclick = function(pos, node, puncher)
  224. minetest.swap_node(pos, {name = "cottages:gate_open", param2 = node.param2})
  225. end,
  226. is_ground_content = false,
  227. })
  228. minetest.register_node("cottages:gate_open", {
  229. description = S("opened fence gate"),
  230. drawtype = "nodebox",
  231. -- top, bottom, side1, side2, inner, outer
  232. tiles = {cottages.texture_furniture},
  233. paramtype = "light",
  234. paramtype2 = "facedir",
  235. drop = "cottages:gate_closed",
  236. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
  237. node_box = {
  238. type = "fixed",
  239. fixed = {
  240. { -0.85, -0.5, -0.25, 0.85, -0.46, -0.05},
  241. { -0.85, -0.5, 0.15, 0.85, -0.46, 0.35},
  242. { -0.80, -0.5, -0.05, -0.60, -0.46, 0.15},
  243. { 0.60, -0.5, -0.05, 0.80, -0.46, 0.15},
  244. { -0.15, -0.5, -0.05, 0.15, -0.46, 0.15},
  245. },
  246. },
  247. selection_box = {
  248. type = "fixed",
  249. fixed = {
  250. { -0.85, -0.5, -0.25, 0.85, -0.3, 0.35},
  251. },
  252. },
  253. on_rightclick = function(pos, node, puncher)
  254. minetest.swap_node(pos, {name = "cottages:gate_closed", param2 = node.param2})
  255. end,
  256. is_ground_content = false,
  257. drop = "cottages:gate_closed",
  258. })
  259. -----------------------------------------------------------------------------------------------------------
  260. -- a hatch; nodebox definition taken from realtest
  261. -----------------------------------------------------------------------------------------------------------
  262. -- hatches rotate around their axis
  263. -- old facedir: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
  264. new_facedirs = { 10,19, 4,13, 2,18,22,14,20,16, 0,12,11, 3, 7,21, 9,23, 5, 1, 8,15, 6,17};
  265. cottages.register_hatch = function( nodename, description, texture, receipe_item )
  266. minetest.register_node( nodename, {
  267. description = S(description), -- not that there are any other...
  268. drawtype = "nodebox",
  269. -- top, bottom, side1, side2, inner, outer
  270. tiles = { texture },
  271. paramtype = "light",
  272. paramtype2 = "facedir",
  273. groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
  274. node_box = {
  275. type = "fixed",
  276. fixed = {
  277. {-0.49, -0.55, -0.49, -0.3, -0.45, 0.45},
  278. -- {-0.5, -0.55, 0.3, 0.3, -0.45, 0.5},
  279. {0.3, -0.55, -0.3, 0.49, -0.45, 0.45},
  280. {0.49, -0.55, -0.49, -0.3, -0.45, -0.3},
  281. {-0.075, -0.55, -0.3, 0.075, -0.45, 0.3},
  282. {-0.3, -0.55, -0.075, -0.075, -0.45, 0.075},
  283. {0.075, -0.55, -0.075, 0.3, -0.45, 0.075},
  284. {-0.3, -0.55, 0.3, 0.3, -0.45, 0.45},
  285. -- hinges
  286. {-0.45,-0.530, 0.45, -0.15,-0.470, 0.525},
  287. { 0.15,-0.530, 0.45, 0.45,-0.470, 0.525},
  288. -- handle
  289. {-0.05,-0.60,-0.35, 0.05,-0.40,-0.45},
  290. },
  291. },
  292. selection_box = {
  293. type = "fixed",
  294. fixed = {-0.5, -0.55, -0.5, 0.5, -0.45, 0.5},
  295. },
  296. on_rightclick = function(pos, node, puncher)
  297. minetest.swap_node(pos, {name = node.name, param2 = new_facedirs[ node.param2+1 ]})
  298. end,
  299. is_ground_content = false,
  300. on_place = minetest.rotate_node,
  301. })
  302. minetest.register_craft({
  303. output = nodename,
  304. recipe = {
  305. { '', '', receipe_item },
  306. { receipe_item, cottages.craftitem_stick, '' },
  307. { '', '', '' },
  308. }
  309. })
  310. end
  311. -- further alternate hatch materials: wood, tree, copper_block
  312. cottages.register_hatch( 'cottages:hatch_wood', 'wooden hatch', 'cottages_minimal_wood.png', cottages.craftitem_slab_wood );
  313. cottages.register_hatch( 'cottages:hatch_steel', 'metal hatch', 'cottages_steel_block.png', cottages.craftitem_steel );
  314. -----------------------------------------------------------------------------------------------------------
  315. -- and now the crafting receipes:
  316. -----------------------------------------------------------------------------------------------------------
  317. -- transform opend and closed shutters into each other for convenience
  318. minetest.register_craft({
  319. output = "cottages:window_shutter_open",
  320. recipe = {
  321. {"cottages:window_shutter_closed" },
  322. }
  323. })
  324. minetest.register_craft({
  325. output = "cottages:window_shutter_closed",
  326. recipe = {
  327. {"cottages:window_shutter_open" },
  328. }
  329. })
  330. minetest.register_craft({
  331. output = "cottages:window_shutter_open",
  332. recipe = {
  333. {cottages.craftitem_wood, "", cottages.craftitem_wood },
  334. }
  335. })
  336. -- transform one half door into another
  337. minetest.register_craft({
  338. output = "cottages:half_door",
  339. recipe = {
  340. {"cottages:half_door_inverted" },
  341. }
  342. })
  343. minetest.register_craft({
  344. output = "cottages:half_door_inverted",
  345. recipe = {
  346. {"cottages:half_door" },
  347. }
  348. })
  349. minetest.register_craft({
  350. output = "cottages:half_door 2",
  351. recipe = {
  352. {"", cottages.craftitem_wood, "" },
  353. {"", cottages.craftitem_door, "" },
  354. }
  355. })
  356. -- transform open and closed versions into into another for convenience
  357. minetest.register_craft({
  358. output = "cottages:gate_closed",
  359. recipe = {
  360. {"cottages:gate_open" },
  361. }
  362. })
  363. minetest.register_craft({
  364. output = "cottages:gate_open",
  365. recipe = {
  366. {"cottages:gate_closed"},
  367. }
  368. })
  369. minetest.register_craft({
  370. output = "cottages:gate_closed",
  371. recipe = {
  372. {cottages.craftitem_stick, cottages.craftitem_stick, cottages.craftitem_wood },
  373. }
  374. })