ropeboxes.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. -- internationalization boilerplate
  2. local MP = minetest.get_modpath(minetest.get_current_modname())
  3. local S, NS = dofile(MP.."/intllib.lua")
  4. local function rope_box_tiles(count, tint)
  5. return {
  6. string.format("ropes_ropebox_front_%i.png^[colorize:%s^ropes_ropebox_front_%i.png^ropes_%i.png", count, tint, count, count),
  7. string.format("ropes_ropebox_front_%i.png^[colorize:%s^ropes_ropebox_front_%i.png^ropes_%i.png", count, tint, count, count),
  8. string.format("ropes_ropebox_side.png^[colorize:%s^ropes_ropebox_side.png", tint),
  9. string.format("ropes_ropebox_side.png^[colorize:%s^ropes_ropebox_side.png", tint),
  10. string.format("ropes_ropebox_front_%i.png^[colorize:%s^ropes_ropebox_front_%i.png^ropes_%i.png", count, tint, count, count),
  11. string.format("ropes_ropebox_front_%i.png^[colorize:%s^ropes_ropebox_front_%i.png^ropes_%i.png", count, tint, count, count),
  12. }
  13. end
  14. local rope_box_data = {
  15. {
  16. node={
  17. {-0.125, -0.125, -0.25, 0.125, 0.125, 0.25}, -- pulley
  18. {-0.125, -0.25, -0.125, 0.125, 0.25, 0.125}, -- pulley
  19. {-0.125, -0.1875, -0.1875, 0.125, 0.1875, 0.1875}, -- pulley_core
  20. {-0.1875, -0.5, -0.125, -0.125, 0.125, 0.125}, -- support
  21. {0.125, -0.5, -0.125, 0.1875, 0.125, 0.125}, -- support
  22. },
  23. --selection = {-0.1875, -0.5, -0.25, 0.1875, 0.25, 0.25}, -- selection
  24. tiles = 1,
  25. },
  26. {
  27. node={
  28. {-0.1875, -0.125, -0.25, 0.1875, 0.125, 0.25}, -- pulley
  29. {-0.1875, -0.25, -0.125, 0.1875, 0.25, 0.125}, -- pulley
  30. {-0.1875, -0.1875, -0.1875, 0.1875, 0.1875, 0.1875}, -- pulley_core
  31. {-0.25, -0.5, -0.125, -0.1875, 0.125, 0.125}, -- support
  32. {0.1875, -0.5, -0.125, 0.25, 0.125, 0.125}, -- support
  33. },
  34. --selection = {-0.1875, -0.5, -0.25, 0.1875, 0.25, 0.25}, -- selection
  35. tiles = 2,
  36. },
  37. {
  38. node={
  39. {-0.25, -0.125, -0.25, 0.25, 0.125, 0.25}, -- pulley
  40. {-0.25, -0.25, -0.125, 0.25, 0.25, 0.125}, -- pulley
  41. {-0.25, -0.1875, -0.1875, 0.25, 0.1875, 0.1875}, -- pulley_core
  42. {-0.3125, -0.5, -0.125, -0.25, 0.125, 0.125}, -- support
  43. {0.25, -0.5, -0.125, 0.3125, 0.125, 0.125}, -- support
  44. },
  45. --selection = {-0.3125, -0.5, -0.25, 0.3125, 0.25, 0.25}, -- selection
  46. tiles = 3,
  47. },
  48. {
  49. node={
  50. {-0.3125, -0.125, -0.25, 0.3125, 0.125, 0.25}, -- pulley
  51. {-0.3125, -0.25, -0.125, 0.3125, 0.25, 0.125}, -- pulley
  52. {-0.3125, -0.1875, -0.1875, 0.3125, 0.1875, 0.1875}, -- pulley_core
  53. {-0.375, -0.5, -0.125, -0.3125, 0.125, 0.125}, -- support
  54. {0.3125, -0.5, -0.125, 0.375, 0.125, 0.125}, -- support
  55. },
  56. --selection = {-0.375, -0.5, -0.25, 0.375, 0.25, 0.25}, -- selection
  57. tiles = 4,
  58. },
  59. {
  60. node={
  61. {-0.375, -0.125, -0.25, 0.375, 0.125, 0.25}, -- pulley
  62. {-0.375, -0.25, -0.125, 0.375, 0.25, 0.125}, -- pulley
  63. {-0.375, -0.1875, -0.1875, 0.375, 0.1875, 0.1875}, -- pulley_core
  64. {-0.4375, -0.5, -0.125, -0.375, 0.125, 0.125}, -- support
  65. {0.375, -0.5, -0.125, 0.4375, 0.125, 0.125}, -- support
  66. },
  67. --selection = {-0.4375, -0.5, -0.25, 0.4375, 0.25, 0.25}, -- selection
  68. tiles = 5,
  69. },
  70. {
  71. node={
  72. {-0.1875, -0.1875, -0.3125, 0.1875, 0.1875, 0.3125}, -- pulley
  73. {-0.1875, -0.3125, -0.1875, 0.1875, 0.3125, 0.1875}, -- pulley
  74. {-0.1875, -0.25, -0.25, 0.1875, 0.25, 0.25}, -- pulley_core
  75. {-0.25, -0.5, -0.125, -0.1875, 0.125, 0.125}, -- support
  76. {0.1875, -0.5, -0.125, 0.25, 0.125, 0.125}, -- support
  77. },
  78. --selection = {-0.1875, -0.5, -0.3125, 0.1875, 0.3125, 0.3125}, -- selection
  79. tiles = 2,
  80. },
  81. {
  82. node={
  83. {-0.25, -0.1875, -0.3125, 0.25, 0.1875, 0.3125}, -- pulley
  84. {-0.25, -0.3125, -0.1875, 0.25, 0.3125, 0.1875}, -- pulley
  85. {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25}, -- pulley_core
  86. {-0.3125, -0.5, -0.125, -0.25, 0.125, 0.125}, -- support
  87. {0.25, -0.5, -0.125, 0.3125, 0.125, 0.125}, -- support
  88. },
  89. --selection = {-0.3125, -0.5, -0.3125, 0.3125, 0.3125, 0.3125}, -- selection
  90. tiles = 3,
  91. },
  92. {
  93. node={
  94. {-0.3125, -0.1875, -0.3125, 0.3125, 0.1875, 0.3125}, -- pulley
  95. {-0.3125, -0.3125, -0.1875, 0.3125, 0.3125, 0.1875}, -- pulley
  96. {-0.3125, -0.25, -0.25, 0.3125, 0.25, 0.25}, -- pulley_core
  97. {-0.375, -0.5, -0.125, -0.3125, 0.125, 0.125}, -- support
  98. {0.3125, -0.5, -0.125, 0.375, 0.125, 0.125}, -- support
  99. },
  100. --selection = {-0.375, -0.5, -0.3125, 0.375, 0.3125, 0.3125}, -- selection
  101. tiles = 4,
  102. },
  103. {
  104. node={
  105. {-0.375, -0.1875, -0.3125, 0.375, 0.1875, 0.3125}, -- pulley
  106. {-0.375, -0.3125, -0.1875, 0.375, 0.3125, 0.1875}, -- pulley
  107. {-0.375, -0.25, -0.25, 0.375, 0.25, 0.25}, -- pulley_core
  108. {-0.4375, -0.5, -0.125, -0.375, 0.125, 0.125}, -- support
  109. {0.375, -0.5, -0.125, 0.4375, 0.125, 0.125}, -- support
  110. },
  111. --selection_bottom = {-0.4375, -0.5, -0.3125, 0.4375, 0.3125, 0.3125}, -- selection
  112. tiles = 5,
  113. }
  114. }
  115. local function register_rope_block(multiple, max_multiple, name_prefix, node_prefix, tint, flammable)
  116. local node_name = string.format("ropes:%s%irope_block", node_prefix, multiple)
  117. local rope_block_def = {
  118. description = S("@1 Ropebox @2m", name_prefix, ropes.ropeLength*multiple),
  119. _doc_items_create_entry = false,
  120. drawtype="nodebox",
  121. sunlight_propagates = true,
  122. paramtype = "light",
  123. paramtype2 = "wallmounted",
  124. walkable = false,
  125. climbable = true,
  126. tiles = rope_box_tiles(rope_box_data[multiple].tiles, tint),
  127. use_texture_alpha = "clip",
  128. node_box = {
  129. type = "fixed",
  130. fixed = rope_box_data[multiple].node
  131. },
  132. selection_box = {type="regular"},
  133. collision_box = {type="regular"},
  134. groups = {choppy=2, oddly_breakable_by_hand=1, rope_block = 1},
  135. on_place = function(itemstack, placer, pointed_thing)
  136. if pointed_thing.type == "node" then
  137. local target_node = minetest.get_node(pointed_thing.under)
  138. local target_def = minetest.registered_nodes[target_node.name]
  139. if target_def.walkable == false then
  140. return itemstack
  141. end
  142. end
  143. return minetest.item_place(itemstack, placer, pointed_thing)
  144. end,
  145. after_place_node = function(pos, placer)
  146. local pos_below = {x=pos.x, y=pos.y-1, z=pos.z}
  147. local placer_name = placer:get_player_name()
  148. if minetest.is_protected(pos_below, placer_name) and not minetest.check_player_privs(placer, "protection_bypass") then
  149. return
  150. end
  151. local node_below = minetest.get_node(pos_below)
  152. if ropes.can_place_rope_in_node(node_below.name) then
  153. minetest.add_node(pos_below, {name="ropes:rope_bottom"})
  154. local meta = minetest.get_meta(pos_below)
  155. meta:set_int("length_remaining", ropes.ropeLength*multiple)
  156. meta:set_string("placer", placer:get_player_name())
  157. end
  158. end,
  159. after_destruct = function(pos)
  160. local pos_below = {x=pos.x, y=pos.y-1, z=pos.z}
  161. ropes.destroy_rope(pos_below, {'ropes:rope', 'ropes:rope_bottom'})
  162. end
  163. }
  164. -- If this number is higher than permitted, we still want to register the block (in case
  165. -- some were already placed in-world) but we want to hide it from creative inventory
  166. -- and if someone digs it we want to disintegrate it into its component parts to prevent
  167. -- reuse.
  168. if multiple > max_multiple then
  169. rope_block_def.groups.not_in_creative_inventory = 1
  170. rope_block_def.drop = string.format("ropes:%s1rope_block %i", node_prefix, multiple)
  171. end
  172. if flammable then
  173. rope_block_def.groups.flammable = flammable
  174. minetest.register_craft({
  175. type = "fuel",
  176. recipe = node_name,
  177. burntime = ropes.rope_burn_time * multiple + ropes.wood_burn_time,
  178. })
  179. end
  180. minetest.register_node(node_name, rope_block_def)
  181. if (multiple ~= 1) then
  182. -- Only register a recipe to craft this if it's within the permitted multiple range
  183. if multiple <= max_multiple then
  184. for i = 1, multiple-1 do
  185. local rec = {string.format("ropes:%s%irope_block", node_prefix, i)}
  186. for n = 1, multiple-i do
  187. table.insert(rec, "ropes:ropesegment")
  188. end
  189. minetest.register_craft({
  190. output = node_name,
  191. type = "shapeless",
  192. recipe = rec
  193. })
  194. end
  195. end
  196. -- Always allow players to disintegrate this into component parts, in case
  197. -- there were some in inventory and the setting was changed.
  198. minetest.register_craft({
  199. output = "ropes:ropesegment",
  200. type = "shapeless",
  201. recipe = {
  202. node_name
  203. },
  204. replacements = {
  205. {node_name, string.format('ropes:%s%irope_block', node_prefix, multiple-1)},
  206. },
  207. })
  208. end
  209. if minetest.get_modpath("doc") then
  210. doc.add_entry_alias("nodes", "ropes:rope", "nodes", node_name)
  211. end
  212. end
  213. local rope_def = {
  214. description = S("Rope"),
  215. _doc_items_longdesc = ropes.doc.ropebox_longdesc,
  216. _doc_items_usagehelp = ropes.doc.ropebox_usage,
  217. walkable = false,
  218. climbable = true,
  219. sunlight_propagates = true,
  220. paramtype = "light",
  221. drop = "",
  222. tiles = { "ropes_3.png", "ropes_3.png", "ropes_3.png", "ropes_3.png", "ropes_5.png", "ropes_5.png" },
  223. use_texture_alpha = "clip",
  224. groups = {choppy=2, flammable=2, not_in_creative_inventory=1},
  225. sounds = {
  226. footstep = {name = "ropes_creak", gain = 0.8, max_hear_distance = 6},
  227. dig = "__group",
  228. dug = "__group",
  229. },
  230. drawtype = "nodebox",
  231. node_box = {
  232. type = "connected",
  233. fixed = {-1/16, -1/2, -1/16, 1/16, 1/2, 1/16},
  234. connect_top = {-1/16, 1/2, -1/16, 1/16, 3/4, 1/16}
  235. },
  236. connects_to = {"group:rope_block"},
  237. connect_sides = {"top"},
  238. selection_box = {
  239. type = "fixed",
  240. fixed = {-1/8, -1/2, -1/8, 1/8, 1/2, 1/8},
  241. },
  242. after_destruct = function(pos)
  243. ropes.hanging_after_destruct(pos, "ropes:rope_top", "ropes:rope", "ropes:rope_bottom")
  244. end,
  245. }
  246. local rope_extension_timer = ropes.make_rope_on_timer("ropes:rope")
  247. local rope_bottom_def = {
  248. description = S("Rope"),
  249. _doc_items_create_entry = false,
  250. walkable = false,
  251. climbable = true,
  252. sunlight_propagates = true,
  253. paramtype = "light",
  254. drop = "",
  255. tiles = { "ropes_3.png", "ropes_3.png", "ropes_3.png", "ropes_3.png", "ropes_5.png", "ropes_5.png" },
  256. use_texture_alpha = "clip",
  257. drawtype = "nodebox",
  258. groups = {choppy=2, flammable=2, not_in_creative_inventory=1},
  259. sounds = {
  260. footstep = {name = "ropes_creak", gain = 0.8, max_hear_distance = 6},
  261. dig = "__group",
  262. dug = "__group",
  263. },
  264. node_box = {
  265. type = "connected",
  266. fixed = {
  267. {-1/16, -3/8, -1/16, 1/16, 1/2, 1/16},
  268. {-2/16, -5/16, -2/16, 2/16, -1/16, 2/16},
  269. },
  270. connect_top = {-1/16, 1/2, -1/16, 1/16, 3/4, 1/16}
  271. },
  272. connects_to = {"group:rope_block"},
  273. connect_sides = {"top"},
  274. selection_box = {
  275. type = "fixed",
  276. fixed = {-1/8, -1/2, -1/8, 1/8, 1/2, 1/8},
  277. },
  278. on_construct = function( pos )
  279. local timer = minetest.get_node_timer( pos )
  280. timer:start( 1 )
  281. end,
  282. on_timer = rope_extension_timer,
  283. after_destruct = function(pos)
  284. ropes.hanging_after_destruct(pos, "ropes:rope_top", "ropes:rope", "ropes:rope_bottom")
  285. end,
  286. }
  287. minetest.register_node("ropes:rope", rope_def)
  288. minetest.register_node("ropes:rope_bottom", rope_bottom_def)
  289. if ropes.woodRopeBoxMaxMultiple > 0 or ropes.create_all_definitions then
  290. if ropes.woodRopeBoxMaxMultiple > 0 then
  291. minetest.register_craft({
  292. output = "ropes:wood1rope_block",
  293. recipe = {
  294. {'group:wood'},
  295. {'group:vines'}
  296. }
  297. })
  298. end
  299. for i = 1,9 do
  300. if ropes.woodRopeBoxMaxMultiple >= i or ropes.create_all_definitions then
  301. register_rope_block(i, ropes.woodRopeBoxMaxMultiple, S("Wood"), "wood", "#86683a", 2)
  302. end
  303. end
  304. end
  305. if ropes.copperRopeBoxMaxMultiple > 0 or ropes.create_all_definitions then
  306. if ropes.copperRopeBoxMaxMultiple > 0 then
  307. minetest.register_craft({
  308. output = "ropes:copper1rope_block",
  309. recipe = {
  310. {'default:copper_ingot'},
  311. {'group:vines'}
  312. }
  313. })
  314. end
  315. for i = 1,9 do
  316. if ropes.copperRopeBoxMaxMultiple >= i or ropes.create_all_definitions then
  317. register_rope_block(i, ropes.copperRopeBoxMaxMultiple, S("Copper"), "copper", "#c88648")
  318. end
  319. end
  320. end
  321. if ropes.steelRopeBoxMaxMultiple > 0 or ropes.create_all_definitions then
  322. if ropes.steelRopeBoxMaxMultiple > 0 then
  323. minetest.register_craft({
  324. output = "ropes:steel1rope_block",
  325. recipe = {
  326. {'default:steel_ingot'},
  327. {'group:vines'}
  328. }
  329. })
  330. end
  331. for i = 1,9 do
  332. if ropes.steelRopeBoxMaxMultiple >= i or ropes.create_all_definitions then
  333. register_rope_block(i, ropes.steelRopeBoxMaxMultiple, S("Steel"), "steel", "#ffffff")
  334. end
  335. end
  336. end