nodes_barrel.lua 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. ---------------------------------------------------------------------
  2. -- a barrel and a tub - plus a function that makes 'round' objects
  3. ---------------------------------------------------------------------
  4. -- IMPORTANT NOTE: The barrel requires a lot of nodeboxes. That may be
  5. -- too much for weak hardware!
  6. ---------------------------------------------------------------------
  7. -- Functionality: right-click to open/close a barrel;
  8. -- punch a barrel to change between vertical/horizontal
  9. ---------------------------------------------------------------------
  10. -- Changelog:
  11. -- 24.03.13 Can no longer be opended/closed on rightclick because that is now used for a formspec;
  12. -- instead, it can be filled with liquids.
  13. -- Filled barrels will always be closed, while empty barrels will always be open.
  14. -- pipes: table with the following entries for each pipe-part:
  15. -- f: radius factor; if 1, it will have a radius of half a nodebox and fill the entire nodebox
  16. -- h1, h2: height at witch the nodebox shall start and end; usually -0.5 and 0.5 for a full nodebox
  17. -- b: make a horizontal part/shelf
  18. -- horizontal: if 1, then x and y coordinates will be swapped
  19. -- TODO: option so that it works without nodeboxes
  20. local S = cottages.S
  21. barrel = {};
  22. -- prepare formspec
  23. barrel.on_construct = function( pos )
  24. local meta = minetest.get_meta(pos);
  25. local percent = math.random( 1, 100 ); -- TODO: show real filling
  26. meta:set_string( 'formspec',
  27. "size[8,9]"..
  28. "image[2.6,2;2,3;default_sandstone.png^[lowpart:"..
  29. (100-percent)..":default_desert_stone.png]".. -- TODO: better images
  30. "label[2.2,0;"..S("Pour:").."]"..
  31. "list[current_name;input;3,0.5;1,1;]"..
  32. "label[5,3.3;"..S("Fill:").."]"..
  33. "list[current_name;output;5,3.8;1,1;]"..
  34. "list[current_player;main;0,5;8,4;]");
  35. meta:set_string( 'liquid_type', '' ); -- which liquid is in the barrel?
  36. meta:set_int( 'liquid_level', 0 ); -- how much of the liquid is in there?
  37. local inv = meta:get_inventory()
  38. inv:set_size("input", 1); -- to fill in new liquid
  39. inv:set_size("output", 1); -- to extract liquid
  40. end
  41. -- can only be digged if there are no more vessels/buckets in any of the slots
  42. -- TODO: allow digging of a filled barrel? this would disallow stacking of them
  43. barrel.can_dig = function( pos, player )
  44. local meta = minetest.get_meta(pos);
  45. local inv = meta:get_inventory()
  46. return ( inv:is_empty('input')
  47. and inv:is_empty('output'));
  48. end
  49. -- the barrel received input; either a new liquid that is to be poured in or a vessel that is to be filled
  50. barrel.on_metadata_inventory_put = function( pos, listname, index, stack, player )
  51. end
  52. -- right-click to open/close barrel; punch to switch between horizontal/vertical position
  53. minetest.register_node("cottages:barrel", {
  54. description = S("barrel (closed)"),
  55. paramtype = "light",
  56. drawtype = "mesh",
  57. mesh = "cottages_barrel_closed.obj",
  58. tiles = {"cottages_barrel.png" },
  59. groups = { tree = 1, snappy = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2
  60. },
  61. drop = "cottages:barrel",
  62. -- on_rightclick = function(pos, node, puncher)
  63. -- minetest.add_node(pos, {name = "cottages:barrel_open", param2 = node.param2})
  64. -- end,
  65. -- TODO: on_rightclick is no longer available - maybe open if empty and closed if full?
  66. on_punch = function(pos, node, puncher)
  67. minetest.add_node(pos, {name = "cottages:barrel_lying", param2 = node.param2})
  68. end,
  69. on_construct = function( pos )
  70. return barrel.on_construct( pos );
  71. end,
  72. can_dig = function(pos,player)
  73. return barrel.can_dig( pos, player );
  74. end,
  75. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  76. return barrel.on_metadata_inventory_put( pos, listname, index, stack, player );
  77. end,
  78. is_ground_content = false,
  79. })
  80. -- this barrel is opened at the top
  81. minetest.register_node("cottages:barrel_open", {
  82. description = S("barrel (open)"),
  83. paramtype = "light",
  84. drawtype = "mesh",
  85. mesh = "cottages_barrel.obj",
  86. tiles = {"cottages_barrel.png" },
  87. groups = { tree = 1, snappy = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory=1,
  88. },
  89. drop = "cottages:barrel",
  90. -- on_rightclick = function(pos, node, puncher)
  91. -- minetest.add_node(pos, {name = "cottages:barrel", param2 = node.param2})
  92. -- end,
  93. on_punch = function(pos, node, puncher)
  94. minetest.add_node(pos, {name = "cottages:barrel_lying_open", param2 = node.param2})
  95. end,
  96. is_ground_content = false,
  97. })
  98. -- horizontal barrel
  99. minetest.register_node("cottages:barrel_lying", {
  100. description = S("barrel (closed), lying somewhere"),
  101. paramtype = "light",
  102. paramtype2 = "facedir",
  103. drawtype = "mesh",
  104. mesh = "cottages_barrel_closed_lying.obj",
  105. tiles = {"cottages_barrel.png" },
  106. groups = { tree = 1, snappy = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory=1,
  107. },
  108. drop = "cottages:barrel",
  109. on_rightclick = function(pos, node, puncher)
  110. minetest.add_node(pos, {name = "cottages:barrel_lying_open", param2 = node.param2})
  111. end,
  112. on_punch = function(pos, node, puncher)
  113. if( node.param2 < 4 ) then
  114. minetest.add_node(pos, {name = "cottages:barrel_lying", param2 = (node.param2+1)})
  115. else
  116. minetest.add_node(pos, {name = "cottages:barrel", param2 = 0})
  117. end
  118. end,
  119. is_ground_content = false,
  120. })
  121. -- horizontal barrel, open
  122. minetest.register_node("cottages:barrel_lying_open", {
  123. description = S("barrel (opened), lying somewhere"),
  124. paramtype = "light",
  125. paramtype2 = "facedir",
  126. drawtype = "mesh",
  127. mesh = "cottages_barrel_lying.obj",
  128. tiles = {"cottages_barrel.png" },
  129. groups = { tree = 1, snappy = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory=1,
  130. },
  131. drop = "cottages:barrel",
  132. on_rightclick = function(pos, node, puncher)
  133. minetest.add_node(pos, {name = "cottages:barrel_lying", param2 = node.param2})
  134. end,
  135. on_punch = function(pos, node, puncher)
  136. if( node.param2 < 4 ) then
  137. minetest.add_node(pos, {name = "cottages:barrel_lying_open", param2 = (node.param2+1)})
  138. else
  139. minetest.add_node(pos, {name = "cottages:barrel_open", param2 = 0})
  140. end
  141. end,
  142. is_ground_content = false,
  143. })
  144. -- let's hope "tub" is the correct english word for "bottich"
  145. minetest.register_node("cottages:tub", {
  146. description = S("tub"),
  147. paramtype = "light",
  148. drawtype = "mesh",
  149. mesh = "cottages_tub.obj",
  150. tiles = {"cottages_barrel.png" },
  151. selection_box = {
  152. type = "fixed",
  153. fixed = {
  154. {-0.5, -0.5, -0.5, 0.5,-0.1, 0.5},
  155. }},
  156. collision_box = {
  157. type = "fixed",
  158. fixed = {
  159. {-0.5, -0.5, -0.5, 0.5,-0.1, 0.5},
  160. }},
  161. groups = { tree = 1, snappy = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2
  162. },
  163. is_ground_content = false,
  164. })
  165. minetest.register_craft({
  166. output = "cottages:barrel",
  167. recipe = {
  168. {cottages.craftitem_wood, "", cottages.craftitem_wood },
  169. {cottages.craftitem_steel, "", cottages.craftitem_steel},
  170. {cottages.craftitem_wood, cottages.craftitem_wood, cottages.craftitem_wood },
  171. },
  172. })
  173. minetest.register_craft({
  174. output = "cottages:tub 2",
  175. recipe = {
  176. {"cottages:barrel"},
  177. },
  178. })
  179. minetest.register_craft({
  180. output = "cottages:barrel",
  181. recipe = {
  182. {"cottages:tub"},
  183. {"cottages:tub"},
  184. },
  185. })