init.lua 5.7 KB

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