init.lua 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. -- Minetest 0.4 mod: vessels
  2. -- See README.txt for licensing and other information.
  3. vessels = vessels or {}
  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. --minetest.chat_send_player("MustTest", "# Server: Node dig!")
  63. if not digger or not digger:is_player() then
  64. return minetest.node_dig(pos, node, digger)
  65. end
  66. if minetest.is_protected(pos, digger:get_player_name()) then
  67. return
  68. end
  69. local meta = minetest.get_meta(pos)
  70. local ntype = meta:get_string("nodetype_on_dig")
  71. if ntype ~= "" then
  72. -- The value of this metadata is the itemtype we should add to digger's inventory.
  73. local def = minetest.registered_items[ntype]
  74. if def then
  75. local inv = digger:get_inventory()
  76. local leftover = inv:add_item("main", ItemStack(ntype))
  77. minetest.item_drop(leftover, nil, pos)
  78. minetest.remove_node(pos)
  79. -- Hmmm, it seems client plays a sound already and we don't need to.
  80. --coresounds.play_sound_node_dug(pos, "vessels:steel_bottle")
  81. return
  82. end
  83. end
  84. -- In case of any failure, just dig normally.
  85. return minetest.node_dig(pos, node, digger)
  86. end
  87. if not vessels.run_once then
  88. local shelf_groups = utility.dig_groups("furniture", {flammable = 3})
  89. local shelf_sounds = default.node_sound_wood_defaults()
  90. minetest.register_node("vessels:shelf", {
  91. description = "Vessels Shelf",
  92. tiles = {
  93. "default_wood.png",
  94. "default_wood.png",
  95. "default_wood.png",
  96. "default_wood.png",
  97. "vessels_shelf.png",
  98. "vessels_shelf.png"
  99. },
  100. paramtype2 = "facedir",
  101. is_ground_content = false,
  102. groups = shelf_groups,
  103. sounds = shelf_sounds,
  104. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  105. on_construct = function(...)
  106. return vessels.on_construct(...) end,
  107. can_dig = function(...)
  108. return vessels.can_dig(...) end,
  109. allow_metadata_inventory_put = function(...)
  110. return vessels.allow_metadata_inventory_put(...) end,
  111. on_metadata_inventory_move = function(...)
  112. return vessels.on_metadata_inventory_move(...) end,
  113. on_metadata_inventory_put = function(...)
  114. return vessels.on_metadata_inventory_put(...) end,
  115. on_metadata_inventory_take = function(...)
  116. return vessels.on_metadata_inventory_take(...) end,
  117. on_blast = function(...)
  118. return vessels.on_blast(...) end,
  119. })
  120. minetest.register_node("vessels:shelf2", {
  121. description = "Vessels Shelf",
  122. tiles = {
  123. "default_wood.png",
  124. "default_wood.png",
  125. "default_wood.png",
  126. "default_wood.png",
  127. "vessels_shelf2.png",
  128. "vessels_shelf2.png"
  129. },
  130. paramtype2 = "facedir",
  131. is_ground_content = false,
  132. groups = shelf_groups,
  133. sounds = shelf_sounds,
  134. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  135. on_construct = function(...)
  136. return vessels.on_construct(...) end,
  137. can_dig = function(...)
  138. return vessels.can_dig(...) end,
  139. allow_metadata_inventory_put = function(...)
  140. return vessels.allow_metadata_inventory_put(...) end,
  141. on_metadata_inventory_move = function(...)
  142. return vessels.on_metadata_inventory_move(...) end,
  143. on_metadata_inventory_put = function(...)
  144. return vessels.on_metadata_inventory_put(...) end,
  145. on_metadata_inventory_take = function(...)
  146. return vessels.on_metadata_inventory_take(...) end,
  147. on_blast = function(...)
  148. return vessels.on_blast(...) end,
  149. })
  150. minetest.register_craft({
  151. output = "vessels:shelf",
  152. recipe = {
  153. {"group:wood", "group:wood", "group:wood"},
  154. {"group:vessel", "group:vessel", "group:vessel"},
  155. {"group:wood", "group:wood", "group:wood"},
  156. }
  157. })
  158. minetest.register_craft({
  159. output = "vessels:shelf2",
  160. recipe = {
  161. {"group:wood", "group:wood", "group:wood"},
  162. {"group:vessel", "", "group:vessel"},
  163. {"group:wood", "group:wood", "group:wood"},
  164. }
  165. })
  166. minetest.register_node("vessels:glass_bottle", {
  167. description = "Glass Bottle (Empty)",
  168. drawtype = "plantlike",
  169. tiles = {"vessels_glass_bottle.png"},
  170. inventory_image = "vessels_glass_bottle.png",
  171. wield_image = "vessels_glass_bottle.png",
  172. paramtype = "light",
  173. is_ground_content = false,
  174. walkable = false,
  175. selection_box = {
  176. type = "fixed",
  177. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  178. },
  179. groups = utility.dig_groups("item", {vessel = 1, attached_node = 1}),
  180. sounds = default.node_sound_glass_defaults(),
  181. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  182. })
  183. minetest.register_craft( {
  184. output = "vessels:glass_bottle 10",
  185. recipe = {
  186. {"default:glass", "", "default:glass" },
  187. {"default:glass", "", "default:glass" },
  188. {"", "default:glass", "" }
  189. }
  190. })
  191. minetest.register_node("vessels:drinking_glass", {
  192. description = "Drinking Glass (Empty)",
  193. drawtype = "plantlike",
  194. tiles = {"vessels_drinking_glass.png"},
  195. inventory_image = "vessels_drinking_glass_inv.png",
  196. wield_image = "vessels_drinking_glass.png",
  197. paramtype = "light",
  198. is_ground_content = false,
  199. walkable = false,
  200. selection_box = {
  201. type = "fixed",
  202. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  203. },
  204. groups = utility.dig_groups("item", {vessel = 1, attached_node = 1}),
  205. sounds = default.node_sound_glass_defaults(),
  206. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  207. })
  208. minetest.register_craft( {
  209. output = "vessels:drinking_glass 14",
  210. recipe = {
  211. {"default:glass", "", "default:glass"},
  212. {"default:glass", "", "default:glass"},
  213. {"default:glass", "default:glass", "default:glass"}
  214. }
  215. })
  216. minetest.register_node("vessels:steel_bottle", {
  217. description = "Heavy Iron Bottle (Empty)",
  218. drawtype = "plantlike",
  219. tiles = {"vessels_steel_bottle.png"},
  220. inventory_image = "vessels_steel_bottle.png",
  221. wield_image = "vessels_steel_bottle.png",
  222. paramtype = "light",
  223. is_ground_content = false,
  224. walkable = false,
  225. selection_box = {
  226. type = "fixed",
  227. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  228. },
  229. groups = utility.dig_groups("item", {vessel = 1, attached_node = 1}),
  230. sounds = default.node_sound_defaults(),
  231. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  232. on_dig = function(...)
  233. return vessels.on_steel_bottle_dig(...)
  234. end,
  235. })
  236. minetest.register_craft( {
  237. output = "vessels:steel_bottle 5",
  238. recipe = {
  239. {"default:steel_ingot", "", "default:steel_ingot" },
  240. {"default:steel_ingot", "", "default:steel_ingot" },
  241. {"", "default:steel_ingot", "" }
  242. }
  243. })
  244. -- Glass and steel recycling
  245. minetest.register_craftitem("vessels:glass_fragments", {
  246. description = "Pile Of Glass Fragments",
  247. inventory_image = "vessels_glass_fragments.png",
  248. })
  249. minetest.register_craft( {
  250. type = "shapeless",
  251. output = "vessels:glass_fragments",
  252. recipe = {
  253. "vessels:glass_bottle",
  254. "vessels:glass_bottle",
  255. },
  256. })
  257. minetest.register_craft( {
  258. type = "shapeless",
  259. output = "vessels:glass_fragments",
  260. recipe = {
  261. "vessels:drinking_glass",
  262. "vessels:drinking_glass",
  263. },
  264. })
  265. minetest.register_craft({
  266. type = "cooking",
  267. output = "default:glass",
  268. recipe = "vessels:glass_fragments",
  269. })
  270. minetest.register_craft( {
  271. type = "cooking",
  272. output = "default:steel_ingot",
  273. recipe = "vessels:steel_bottle",
  274. })
  275. -- Reloadable.
  276. local name = "vessels:core"
  277. local file = vessels.modpath .. "/init.lua"
  278. reload.register_file(name, file, false)
  279. vessels.run_once = true
  280. end