init.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. -- Minetest 0.4 mod: vessels
  2. -- See README.txt for licensing and other information.
  3. local vessels_shelf_formspec =
  4. "size[8,7;]" ..
  5. default.gui_bg ..
  6. default.gui_bg_img ..
  7. default.gui_slots ..
  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 get_vessels_shelf_formspec(inv)
  15. local formspec = vessels_shelf_formspec
  16. local invlist = inv and inv:get_list("vessels")
  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. if not invlist or invlist[i]:is_empty() then
  25. formspec = formspec ..
  26. "image[" .. vx .. "," .. vy .. ";1,1;vessels_shelf_slot.png]"
  27. end
  28. vx = vx + 1
  29. end
  30. return formspec
  31. end
  32. minetest.register_node("vessels:shelf", {
  33. description = "Vessels Shelf",
  34. tiles = {"default_wood.png", "default_wood.png", "default_wood.png",
  35. "default_wood.png", "vessels_shelf.png", "vessels_shelf.png"},
  36. paramtype2 = "facedir",
  37. is_ground_content = false,
  38. groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
  39. sounds = default.node_sound_wood_defaults(),
  40. on_construct = function(pos)
  41. local meta = minetest.get_meta(pos)
  42. meta:set_string("formspec", get_vessels_shelf_formspec(nil))
  43. local inv = meta:get_inventory()
  44. inv:set_size("vessels", 8 * 2)
  45. end,
  46. can_dig = function(pos,player)
  47. local inv = minetest.get_meta(pos):get_inventory()
  48. return inv:is_empty("vessels")
  49. end,
  50. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  51. if minetest.get_item_group(stack:get_name(), "vessel") ~= 0 then
  52. return stack:get_count()
  53. end
  54. return 0
  55. end,
  56. on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  57. minetest.log("action", player:get_player_name() ..
  58. " moves stuff in vessels shelf at ".. minetest.pos_to_string(pos))
  59. local meta = minetest.get_meta(pos)
  60. meta:set_string("formspec", get_vessels_shelf_formspec(meta:get_inventory()))
  61. end,
  62. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  63. minetest.log("action", player:get_player_name() ..
  64. " moves stuff to vessels shelf at ".. minetest.pos_to_string(pos))
  65. local meta = minetest.get_meta(pos)
  66. meta:set_string("formspec", get_vessels_shelf_formspec(meta:get_inventory()))
  67. end,
  68. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  69. minetest.log("action", player:get_player_name() ..
  70. " takes stuff from vessels shelf at ".. minetest.pos_to_string(pos))
  71. local meta = minetest.get_meta(pos)
  72. meta:set_string("formspec", get_vessels_shelf_formspec(meta:get_inventory()))
  73. end,
  74. on_blast = function(pos)
  75. local drops = {}
  76. default.get_inventory_drops(pos, "vessels", drops)
  77. drops[#drops + 1] = "vessels:shelf"
  78. minetest.remove_node(pos)
  79. return drops
  80. end,
  81. })
  82. minetest.register_craft({
  83. output = "vessels:shelf",
  84. recipe = {
  85. {"group:wood", "group:wood", "group:wood"},
  86. {"group:vessel", "group:vessel", "group:vessel"},
  87. {"group:wood", "group:wood", "group:wood"},
  88. }
  89. })
  90. minetest.register_node("vessels:glass_bottle", {
  91. description = "Glass Bottle (empty)",
  92. drawtype = "plantlike",
  93. tiles = {"vessels_glass_bottle.png"},
  94. inventory_image = "vessels_glass_bottle.png",
  95. wield_image = "vessels_glass_bottle.png",
  96. paramtype = "light",
  97. is_ground_content = false,
  98. walkable = false,
  99. selection_box = {
  100. type = "fixed",
  101. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  102. },
  103. groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
  104. sounds = default.node_sound_glass_defaults(),
  105. })
  106. minetest.register_craft( {
  107. output = "vessels:glass_bottle 10",
  108. recipe = {
  109. {"default:glass", "", "default:glass"},
  110. {"default:glass", "", "default:glass"},
  111. {"", "default:glass", ""}
  112. }
  113. })
  114. minetest.register_node("vessels:drinking_glass", {
  115. description = "Drinking Glass (empty)",
  116. drawtype = "plantlike",
  117. tiles = {"vessels_drinking_glass.png"},
  118. inventory_image = "vessels_drinking_glass_inv.png",
  119. wield_image = "vessels_drinking_glass.png",
  120. paramtype = "light",
  121. is_ground_content = false,
  122. walkable = false,
  123. selection_box = {
  124. type = "fixed",
  125. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  126. },
  127. groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
  128. sounds = default.node_sound_glass_defaults(),
  129. })
  130. minetest.register_craft( {
  131. output = "vessels:drinking_glass 14",
  132. recipe = {
  133. {"default:glass", "", "default:glass"},
  134. {"default:glass", "", "default:glass"},
  135. {"default:glass", "default:glass", "default:glass"}
  136. }
  137. })
  138. minetest.register_node("vessels:steel_bottle", {
  139. description = "Heavy Steel Bottle (empty)",
  140. drawtype = "plantlike",
  141. tiles = {"vessels_steel_bottle.png"},
  142. inventory_image = "vessels_steel_bottle.png",
  143. wield_image = "vessels_steel_bottle.png",
  144. paramtype = "light",
  145. is_ground_content = false,
  146. walkable = false,
  147. selection_box = {
  148. type = "fixed",
  149. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  150. },
  151. groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
  152. sounds = default.node_sound_defaults(),
  153. })
  154. minetest.register_craft( {
  155. output = "vessels:steel_bottle 5",
  156. recipe = {
  157. {"default:steel_ingot", "", "default:steel_ingot"},
  158. {"default:steel_ingot", "", "default:steel_ingot"},
  159. {"", "default:steel_ingot", ""}
  160. }
  161. })
  162. -- Glass and steel recycling
  163. minetest.register_craftitem("vessels:glass_fragments", {
  164. description = "Pile of Glass Fragments",
  165. inventory_image = "vessels_glass_fragments.png",
  166. })
  167. minetest.register_craft( {
  168. type = "shapeless",
  169. output = "vessels:glass_fragments",
  170. recipe = {
  171. "vessels:glass_bottle",
  172. "vessels:glass_bottle",
  173. },
  174. })
  175. minetest.register_craft( {
  176. type = "shapeless",
  177. output = "vessels:glass_fragments",
  178. recipe = {
  179. "vessels:drinking_glass",
  180. "vessels:drinking_glass",
  181. },
  182. })
  183. minetest.register_craft({
  184. type = "cooking",
  185. output = "default:glass",
  186. recipe = "vessels:glass_fragments",
  187. })
  188. minetest.register_craft( {
  189. type = "cooking",
  190. output = "default:steel_ingot",
  191. recipe = "vessels:steel_bottle",
  192. })
  193. minetest.register_craft({
  194. type = "fuel",
  195. recipe = "vessels:shelf",
  196. burntime = 30,
  197. })