init.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. -- Minetest 0.4 mod: vessels
  2. -- See README.txt for licensing and other information.
  3. if not minetest.global_exists("vessels") then vessels = {} end
  4. vessels.modpath = minetest.get_modpath("vessels")
  5. vessels.get_formspec = function()
  6. local formspec =
  7. "size[8,7;]" ..
  8. default.formspec.get_form_colors() ..
  9. default.formspec.get_form_image() ..
  10. default.formspec.get_slot_colors() ..
  11. "list[context;vessels;0,0.3;8,2;]" ..
  12. "list[current_player;main;0,2.85;8,1;]" ..
  13. "list[current_player;main;0,4.08;8,3;8]" ..
  14. "listring[context;vessels]" ..
  15. "listring[current_player;main]" ..
  16. default.get_hotbar_bg(0, 2.85)
  17. -- Inventory slots overlay
  18. local vx, vy = 0, 0.3
  19. for i = 1,16 do
  20. if i == 9 then
  21. vx = 0
  22. vy = vy + 1
  23. end
  24. formspec = formspec .. "image["..vx..","..vy..";1,1;vessels_glass_bottle_slot.png]"
  25. vx = vx + 1
  26. end
  27. return formspec
  28. end
  29. vessels.on_construct = function(pos)
  30. local meta = minetest.get_meta(pos)
  31. meta:set_string("formspec", vessels.get_formspec())
  32. local inv = meta:get_inventory()
  33. inv:set_size("vessels", 8 * 2)
  34. end
  35. vessels.can_dig = function(pos,player)
  36. local inv = minetest.get_meta(pos):get_inventory()
  37. return inv:is_empty("vessels")
  38. end
  39. vessels.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  40. if minetest.get_item_group(stack:get_name(), "vessel") ~= 0 then
  41. return stack:get_count()
  42. end
  43. return 0
  44. end
  45. vessels.on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  46. minetest.log("action", player:get_player_name() .. " moves stuff in vessels shelf at ".. minetest.pos_to_string(pos))
  47. end
  48. vessels.on_metadata_inventory_put = function(pos, listname, index, stack, player)
  49. minetest.log("action", player:get_player_name() .. " moves stuff to vessels shelf at ".. minetest.pos_to_string(pos))
  50. end
  51. vessels.on_metadata_inventory_take = function(pos, listname, index, stack, player)
  52. minetest.log("action", player:get_player_name() .. " takes stuff from vessels shelf at ".. minetest.pos_to_string(pos))
  53. end
  54. vessels.on_blast = function(pos)
  55. local drops = {}
  56. default.get_inventory_drops(pos, "vessels", drops)
  57. drops[#drops + 1] = "vessels:shelf"
  58. minetest.remove_node(pos)
  59. return drops
  60. end
  61. vessels.on_steel_bottle_dig = function(pos, node, digger)
  62. if not digger or not digger:is_player() then
  63. return minetest.node_dig(pos, node, digger)
  64. end
  65. if minetest.is_protected(pos, digger:get_player_name()) then
  66. return
  67. end
  68. local meta = minetest.get_meta(pos)
  69. local ntype = meta:get_string("nodetype_on_dig")
  70. if ntype ~= "" then
  71. -- The value of this metadata is the itemtype we should add to digger's inventory.
  72. local def = minetest.registered_items[ntype]
  73. if def then
  74. local inv = digger:get_inventory()
  75. local leftover = inv:add_item("main", ItemStack(ntype))
  76. minetest.item_drop(leftover, nil, pos)
  77. minetest.remove_node(pos)
  78. -- Hmmm, it seems client plays a sound already and we don't need to.
  79. --coresounds.play_sound_node_dug(pos, "vessels:steel_bottle")
  80. return
  81. end
  82. end
  83. -- In case of any failure, just dig normally.
  84. return minetest.node_dig(pos, node, digger)
  85. end
  86. if not vessels.run_once then
  87. local shelf_groups = utility.dig_groups("furniture", {flammable = 3})
  88. local shelf_sounds = default.node_sound_wood_defaults()
  89. minetest.register_node("vessels:shelf", {
  90. description = "Vessels Shelf",
  91. tiles = {
  92. "default_wood.png",
  93. "default_wood.png",
  94. "default_wood.png",
  95. "default_wood.png",
  96. "vessels_shelf.png",
  97. "vessels_shelf.png"
  98. },
  99. paramtype2 = "facedir",
  100. is_ground_content = false,
  101. groups = shelf_groups,
  102. sounds = shelf_sounds,
  103. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  104. on_construct = function(...)
  105. return vessels.on_construct(...) end,
  106. can_dig = function(...)
  107. return vessels.can_dig(...) end,
  108. allow_metadata_inventory_put = function(...)
  109. return vessels.allow_metadata_inventory_put(...) end,
  110. on_metadata_inventory_move = function(...)
  111. return vessels.on_metadata_inventory_move(...) end,
  112. on_metadata_inventory_put = function(...)
  113. return vessels.on_metadata_inventory_put(...) end,
  114. on_metadata_inventory_take = function(...)
  115. return vessels.on_metadata_inventory_take(...) end,
  116. on_blast = function(...)
  117. return vessels.on_blast(...) end,
  118. })
  119. minetest.register_node("vessels:shelf2", {
  120. description = "Vessels Shelf",
  121. tiles = {
  122. "default_wood.png",
  123. "default_wood.png",
  124. "default_wood.png",
  125. "default_wood.png",
  126. "vessels_shelf2.png",
  127. "vessels_shelf2.png"
  128. },
  129. paramtype2 = "facedir",
  130. is_ground_content = false,
  131. groups = shelf_groups,
  132. sounds = shelf_sounds,
  133. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  134. on_construct = function(...)
  135. return vessels.on_construct(...) end,
  136. can_dig = function(...)
  137. return vessels.can_dig(...) end,
  138. allow_metadata_inventory_put = function(...)
  139. return vessels.allow_metadata_inventory_put(...) end,
  140. on_metadata_inventory_move = function(...)
  141. return vessels.on_metadata_inventory_move(...) end,
  142. on_metadata_inventory_put = function(...)
  143. return vessels.on_metadata_inventory_put(...) end,
  144. on_metadata_inventory_take = function(...)
  145. return vessels.on_metadata_inventory_take(...) end,
  146. on_blast = function(...)
  147. return vessels.on_blast(...) end,
  148. })
  149. minetest.register_craft({
  150. output = "vessels:shelf",
  151. recipe = {
  152. {"group:wood", "group:wood", "group:wood"},
  153. {"group:vessel", "group:vessel", "group:vessel"},
  154. {"group:wood", "group:wood", "group:wood"},
  155. }
  156. })
  157. minetest.register_craft({
  158. output = "vessels:shelf2",
  159. recipe = {
  160. {"group:wood", "group:wood", "group:wood"},
  161. {"group:vessel", "", "group:vessel"},
  162. {"group:wood", "group:wood", "group:wood"},
  163. }
  164. })
  165. minetest.register_node("vessels:glass_bottle", {
  166. description = "Glass Bottle (Empty)",
  167. drawtype = "plantlike",
  168. tiles = {"vessels_glass_bottle.png"},
  169. inventory_image = "vessels_glass_bottle.png",
  170. wield_image = "vessels_glass_bottle.png",
  171. paramtype = "light",
  172. is_ground_content = false,
  173. walkable = false,
  174. selection_box = {
  175. type = "fixed",
  176. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  177. },
  178. groups = utility.dig_groups("item", {vessel = 1, attached_node = 1}),
  179. sounds = default.node_sound_glass_defaults(),
  180. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  181. })
  182. minetest.register_craft( {
  183. output = "vessels:glass_bottle 10",
  184. recipe = {
  185. {"default:glass", "", "default:glass" },
  186. {"default:glass", "", "default:glass" },
  187. {"", "default:glass", "" }
  188. }
  189. })
  190. minetest.register_node("vessels:drinking_glass", {
  191. description = "Drinking Glass (Empty)",
  192. drawtype = "plantlike",
  193. tiles = {"vessels_drinking_glass.png"},
  194. inventory_image = "vessels_drinking_glass_inv.png",
  195. wield_image = "vessels_drinking_glass.png",
  196. paramtype = "light",
  197. is_ground_content = false,
  198. walkable = false,
  199. selection_box = {
  200. type = "fixed",
  201. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  202. },
  203. groups = utility.dig_groups("item", {vessel = 1, attached_node = 1}),
  204. sounds = default.node_sound_glass_defaults(),
  205. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  206. })
  207. minetest.register_craft( {
  208. output = "vessels:drinking_glass 14",
  209. recipe = {
  210. {"default:glass", "", "default:glass"},
  211. {"default:glass", "", "default:glass"},
  212. {"default:glass", "default:glass", "default:glass"}
  213. }
  214. })
  215. minetest.register_node("vessels:vessels_drinking_mug", {
  216. description = "Drinking Mug (Empty)",
  217. drawtype = "plantlike",
  218. tiles = {"vessels_drinking_mug.png"},
  219. inventory_image = "vessels_drinking_mug_inv.png",
  220. wield_image = "vessels_drinking_mug.png",
  221. paramtype = "light",
  222. is_ground_content = false,
  223. walkable = false,
  224. selection_box = {
  225. type = "fixed",
  226. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  227. },
  228. groups = utility.dig_groups("item", {vessel = 1, attached_node = 1}),
  229. sounds = default.node_sound_glass_defaults(),
  230. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  231. })
  232. minetest.register_craft( {
  233. output = "vessels:vessels_drinking_mug 14",
  234. recipe = {
  235. {"default:glass", "", "default:glass"},
  236. {"default:glass", "", "default:glass"},
  237. {"default:glass", "default:clay_lump", "default:glass"}
  238. }
  239. })
  240. minetest.register_node("vessels:steel_bottle", {
  241. description = "Heavy Iron Bottle (Empty)",
  242. drawtype = "plantlike",
  243. tiles = {"vessels_steel_bottle.png"},
  244. inventory_image = "vessels_steel_bottle.png",
  245. wield_image = "vessels_steel_bottle.png",
  246. paramtype = "light",
  247. is_ground_content = false,
  248. walkable = false,
  249. selection_box = {
  250. type = "fixed",
  251. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  252. },
  253. groups = utility.dig_groups("item", {vessel = 1, attached_node = 1}),
  254. sounds = default.node_sound_defaults(),
  255. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  256. on_dig = function(...)
  257. return vessels.on_steel_bottle_dig(...)
  258. end,
  259. })
  260. minetest.register_craft( {
  261. output = "vessels:steel_bottle 5",
  262. recipe = {
  263. {"default:steel_ingot", "", "default:steel_ingot" },
  264. {"default:steel_ingot", "", "default:steel_ingot" },
  265. {"", "default:steel_ingot", "" }
  266. }
  267. })
  268. -- Glass and steel recycling
  269. minetest.register_craftitem("vessels:glass_fragments", {
  270. description = "Pile of Glass Fragments",
  271. inventory_image = "vessels_glass_fragments.png",
  272. })
  273. minetest.register_craft( {
  274. type = "shapeless",
  275. output = "vessels:glass_fragments",
  276. recipe = {
  277. "vessels:glass_bottle",
  278. "vessels:glass_bottle",
  279. },
  280. })
  281. minetest.register_craft( {
  282. type = "shapeless",
  283. output = "vessels:glass_fragments",
  284. recipe = {
  285. "vessels:drinking_glass",
  286. "vessels:drinking_glass",
  287. },
  288. })
  289. minetest.register_craft({
  290. type = "cooking",
  291. output = "default:glass",
  292. recipe = "vessels:glass_fragments",
  293. })
  294. minetest.register_craft( {
  295. type = "cooking",
  296. output = "default:steel_ingot",
  297. recipe = "vessels:steel_bottle",
  298. })
  299. -- Reloadable.
  300. local name = "vessels:core"
  301. local file = vessels.modpath .. "/init.lua"
  302. reload.register_file(name, file, false)
  303. vessels.run_once = true
  304. end