init.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. local vessels_shelf_def = {
  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_blast = function(pos)
  70. local drops = {}
  71. default.get_inventory_drops(pos, "vessels", drops)
  72. drops[#drops + 1] = "vessels:shelf"
  73. minetest.remove_node(pos)
  74. return drops
  75. end,
  76. on_metadata_inventory_put = function(pos)
  77. update_vessels_shelf(pos)
  78. end,
  79. on_metadata_inventory_take = function(pos)
  80. update_vessels_shelf(pos)
  81. end,
  82. on_metadata_inventory_move = function(pos)
  83. update_vessels_shelf(pos)
  84. end,
  85. }
  86. default.set_inventory_action_loggers(vessels_shelf_def, "vessels shelf")
  87. minetest.register_node("vessels:shelf", vessels_shelf_def)
  88. minetest.register_craft({
  89. output = "vessels:shelf",
  90. recipe = {
  91. {"group:wood", "group:wood", "group:wood"},
  92. {"group:vessel", "group:vessel", "group:vessel"},
  93. {"group:wood", "group:wood", "group:wood"},
  94. }
  95. })
  96. minetest.register_node("vessels:glass_bottle", {
  97. description = S("Empty Glass Bottle"),
  98. drawtype = "plantlike",
  99. tiles = {"vessels_glass_bottle.png"},
  100. inventory_image = "vessels_glass_bottle.png",
  101. wield_image = "vessels_glass_bottle.png",
  102. paramtype = "light",
  103. is_ground_content = false,
  104. walkable = false,
  105. selection_box = {
  106. type = "fixed",
  107. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  108. },
  109. groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
  110. sounds = default.node_sound_glass_defaults(),
  111. })
  112. minetest.register_craft( {
  113. output = "vessels:glass_bottle 10",
  114. recipe = {
  115. {"default:glass", "", "default:glass"},
  116. {"default:glass", "", "default:glass"},
  117. {"", "default:glass", ""}
  118. }
  119. })
  120. minetest.register_node("vessels:drinking_glass", {
  121. description = S("Empty Drinking Glass"),
  122. drawtype = "plantlike",
  123. tiles = {"vessels_drinking_glass.png"},
  124. inventory_image = "vessels_drinking_glass_inv.png",
  125. wield_image = "vessels_drinking_glass.png",
  126. paramtype = "light",
  127. is_ground_content = false,
  128. walkable = false,
  129. selection_box = {
  130. type = "fixed",
  131. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  132. },
  133. groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
  134. sounds = default.node_sound_glass_defaults(),
  135. })
  136. minetest.register_craft( {
  137. output = "vessels:drinking_glass 14",
  138. recipe = {
  139. {"default:glass", "", "default:glass"},
  140. {"default:glass", "", "default:glass"},
  141. {"default:glass", "default:glass", "default:glass"}
  142. }
  143. })
  144. minetest.register_node("vessels:steel_bottle", {
  145. description = S("Empty Heavy Steel Bottle"),
  146. drawtype = "plantlike",
  147. tiles = {"vessels_steel_bottle.png"},
  148. inventory_image = "vessels_steel_bottle.png",
  149. wield_image = "vessels_steel_bottle.png",
  150. paramtype = "light",
  151. is_ground_content = false,
  152. walkable = false,
  153. selection_box = {
  154. type = "fixed",
  155. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  156. },
  157. groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
  158. sounds = default.node_sound_defaults(),
  159. })
  160. minetest.register_craft( {
  161. output = "vessels:steel_bottle 5",
  162. recipe = {
  163. {"default:steel_ingot", "", "default:steel_ingot"},
  164. {"default:steel_ingot", "", "default:steel_ingot"},
  165. {"", "default:steel_ingot", ""}
  166. }
  167. })
  168. -- Glass and steel recycling
  169. minetest.register_craftitem("vessels:glass_fragments", {
  170. description = S("Glass Fragments"),
  171. inventory_image = "vessels_glass_fragments.png",
  172. })
  173. minetest.register_craft( {
  174. type = "shapeless",
  175. output = "vessels:glass_fragments",
  176. recipe = {
  177. "vessels:glass_bottle",
  178. "vessels:glass_bottle",
  179. },
  180. })
  181. minetest.register_craft( {
  182. type = "shapeless",
  183. output = "vessels:glass_fragments",
  184. recipe = {
  185. "vessels:drinking_glass",
  186. "vessels:drinking_glass",
  187. },
  188. })
  189. minetest.register_craft({
  190. type = "cooking",
  191. output = "default:glass",
  192. recipe = "vessels:glass_fragments",
  193. })
  194. minetest.register_craft( {
  195. type = "cooking",
  196. output = "default:steel_ingot",
  197. recipe = "vessels:steel_bottle",
  198. })
  199. minetest.register_craft({
  200. type = "fuel",
  201. recipe = "vessels:shelf",
  202. burntime = 30,
  203. })
  204. -- Register glass fragments as dungeon loot
  205. if minetest.global_exists("dungeon_loot") then
  206. dungeon_loot.register({
  207. name = "vessels:glass_fragments", chance = 0.35, count = {1, 4}
  208. })
  209. end