init.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. -- vessels/init.lua
  2. -- Minetest 0.4 mod: vessels
  3. -- See README.txt for licensing and other information.
  4. -- Load support for MT game translation.
  5. local S = minetest.get_translator("vessels")
  6. local vessels_shelf_formspec =
  7. "size[8,7;]" ..
  8. "list[context;vessels;0,0.3;8,2;]" ..
  9. "list[current_player;main;0,2.85;8,1;]" ..
  10. "list[current_player;main;0,4.08;8,3;8]" ..
  11. "listring[context;vessels]" ..
  12. "listring[current_player;main]" ..
  13. default.get_hotbar_bg(0, 2.85)
  14. local function update_vessels_shelf(pos)
  15. local meta = minetest.get_meta(pos)
  16. local inv = meta:get_inventory()
  17. local invlist = inv:get_list("vessels")
  18. local formspec = vessels_shelf_formspec
  19. -- Inventory slots overlay
  20. local vx, vy = 0, 0.3
  21. local n_items = 0
  22. for i = 1, 16 do
  23. if i == 9 then
  24. vx = 0
  25. vy = vy + 1
  26. end
  27. if not invlist or invlist[i]:is_empty() then
  28. formspec = formspec ..
  29. "image[" .. vx .. "," .. vy .. ";1,1;vessels_shelf_slot.png]"
  30. else
  31. local stack = invlist[i]
  32. if not stack:is_empty() then
  33. n_items = n_items + stack:get_count()
  34. end
  35. end
  36. vx = vx + 1
  37. end
  38. meta:set_string("formspec", formspec)
  39. if n_items == 0 then
  40. meta:set_string("infotext", S("Empty Vessels Shelf"))
  41. else
  42. meta:set_string("infotext", S("Vessels Shelf (@1 items)", n_items))
  43. end
  44. end
  45. minetest.register_node("vessels:shelf", {
  46. description = S("Vessels Shelf"),
  47. tiles = {"default_wood.png", "default_wood.png", "default_wood.png",
  48. "default_wood.png", "vessels_shelf.png", "vessels_shelf.png"},
  49. paramtype2 = "facedir",
  50. is_ground_content = false,
  51. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
  52. sounds = default.node_sound_wood_defaults(),
  53. on_construct = function(pos)
  54. local meta = minetest.get_meta(pos)
  55. update_vessels_shelf(pos)
  56. local inv = meta:get_inventory()
  57. inv:set_size("vessels", 8 * 2)
  58. end,
  59. can_dig = function(pos,player)
  60. local inv = minetest.get_meta(pos):get_inventory()
  61. return inv:is_empty("vessels")
  62. end,
  63. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  64. if minetest.get_item_group(stack:get_name(), "vessel") ~= 0 then
  65. return stack:get_count()
  66. end
  67. return 0
  68. end,
  69. on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  70. minetest.log("action", player:get_player_name() ..
  71. " moves stuff in vessels shelf at ".. minetest.pos_to_string(pos))
  72. update_vessels_shelf(pos)
  73. end,
  74. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  75. minetest.log("action", player:get_player_name() ..
  76. " moves stuff to vessels shelf at ".. minetest.pos_to_string(pos))
  77. update_vessels_shelf(pos)
  78. end,
  79. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  80. minetest.log("action", player:get_player_name() ..
  81. " takes stuff from vessels shelf at ".. minetest.pos_to_string(pos))
  82. update_vessels_shelf(pos)
  83. end,
  84. on_blast = function(pos)
  85. local drops = {}
  86. default.get_inventory_drops(pos, "vessels", drops)
  87. drops[#drops + 1] = "vessels:shelf"
  88. minetest.remove_node(pos)
  89. return drops
  90. end,
  91. })
  92. minetest.register_craft({
  93. output = "vessels:shelf",
  94. recipe = {
  95. {"group:wood", "group:wood", "group:wood"},
  96. {"group:vessel", "group:vessel", "group:vessel"},
  97. {"group:wood", "group:wood", "group:wood"},
  98. }
  99. })
  100. minetest.register_node("vessels:glass_bottle", {
  101. description = S("Empty Glass Bottle"),
  102. drawtype = "plantlike",
  103. tiles = {"vessels_glass_bottle.png"},
  104. inventory_image = "vessels_glass_bottle.png",
  105. wield_image = "vessels_glass_bottle.png",
  106. paramtype = "light",
  107. is_ground_content = false,
  108. walkable = false,
  109. selection_box = {
  110. type = "fixed",
  111. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  112. },
  113. groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
  114. sounds = default.node_sound_glass_defaults(),
  115. })
  116. minetest.register_craft( {
  117. output = "vessels:glass_bottle 10",
  118. recipe = {
  119. {"default:glass", "", "default:glass"},
  120. {"default:glass", "", "default:glass"},
  121. {"", "default:glass", ""}
  122. }
  123. })
  124. minetest.register_node("vessels:drinking_glass", {
  125. description = S("Empty Drinking Glass"),
  126. drawtype = "plantlike",
  127. tiles = {"vessels_drinking_glass.png"},
  128. inventory_image = "vessels_drinking_glass_inv.png",
  129. wield_image = "vessels_drinking_glass.png",
  130. paramtype = "light",
  131. is_ground_content = false,
  132. walkable = false,
  133. selection_box = {
  134. type = "fixed",
  135. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  136. },
  137. groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
  138. sounds = default.node_sound_glass_defaults(),
  139. })
  140. minetest.register_craft( {
  141. output = "vessels:drinking_glass 14",
  142. recipe = {
  143. {"default:glass", "", "default:glass"},
  144. {"default:glass", "", "default:glass"},
  145. {"default:glass", "default:glass", "default:glass"}
  146. }
  147. })
  148. minetest.register_node("vessels:glass_jar", {
  149. description = S("Empty Glass Jar"),
  150. drawtype = "plantlike",
  151. tiles = {"vessels_glass_jar.png"},
  152. inventory_image = "vessels_glass_jar.png",
  153. wield_image = "vessels_glass_jar.png",
  154. paramtype = "light",
  155. is_ground_content = false,
  156. walkable = false,
  157. selection_box = {
  158. type = "fixed",
  159. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  160. },
  161. groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
  162. sounds = default.node_sound_glass_defaults(),
  163. })
  164. minetest.register_craft( {
  165. output = "vessels:glass_jar 10",
  166. recipe = {
  167. {"default:glass", "default:tin_ingot", "default:glass"},
  168. {"default:glass", "", "default:glass"},
  169. {"", "default:glass", ""}
  170. }
  171. })
  172. minetest.register_node("vessels:steel_bottle", {
  173. description = S("Empty Heavy Steel Bottle"),
  174. drawtype = "plantlike",
  175. tiles = {"vessels_steel_bottle.png"},
  176. inventory_image = "vessels_steel_bottle.png",
  177. wield_image = "vessels_steel_bottle.png",
  178. paramtype = "light",
  179. is_ground_content = false,
  180. walkable = false,
  181. selection_box = {
  182. type = "fixed",
  183. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  184. },
  185. groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
  186. sounds = default.node_sound_defaults(),
  187. })
  188. minetest.register_craft( {
  189. output = "vessels:steel_bottle 5",
  190. recipe = {
  191. {"default:steel_ingot", "", "default:steel_ingot"},
  192. {"default:steel_ingot", "", "default:steel_ingot"},
  193. {"", "default:steel_ingot", ""}
  194. }
  195. })
  196. -- Glass and steel recycling
  197. minetest.register_craftitem("vessels:glass_fragments", {
  198. description = S("Glass Fragments"),
  199. inventory_image = "vessels_glass_fragments.png",
  200. })
  201. minetest.register_craft( {
  202. type = "shapeless",
  203. output = "vessels:glass_fragments",
  204. recipe = {
  205. "vessels:glass_bottle",
  206. "vessels:glass_bottle",
  207. },
  208. })
  209. minetest.register_craft( {
  210. type = "shapeless",
  211. output = "vessels:glass_fragments",
  212. recipe = {
  213. "vessels:drinking_glass",
  214. "vessels:drinking_glass",
  215. },
  216. })
  217. minetest.register_craft( {
  218. type = "shapeless",
  219. output = "vessels:glass_fragments",
  220. recipe = { "vessels:glass_jar", "vessels:glass_jar" },
  221. })
  222. minetest.register_craft({
  223. type = "cooking",
  224. output = "default:glass",
  225. recipe = "vessels:glass_fragments",
  226. })
  227. minetest.register_craft( {
  228. type = "cooking",
  229. output = "default:steel_ingot",
  230. recipe = "vessels:steel_bottle",
  231. })
  232. minetest.register_craft({
  233. type = "fuel",
  234. recipe = "vessels:shelf",
  235. burntime = 30,
  236. })
  237. -- Register glass fragments as dungeon loot
  238. if minetest.global_exists("dungeon_loot") then
  239. dungeon_loot.register({
  240. name = "vessels:glass_fragments", chance = 0.35, count = {1, 4}
  241. })
  242. end