mixer.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. minetest.register_node('mylandscaping:mixer', {
  2. description = 'Concrete Mixer',
  3. drawtype = 'mesh',
  4. mesh = 'mylandscaping_crusher.obj',
  5. tiles = {
  6. {name='mylandscaping_tex1.png'},{name='mylandscaping_supports.png'},
  7. {name='mylandscaping_base.png'},{name='mylandscaping_hopper.png'},
  8. {name='mylandscaping_crusher.png'}},
  9. groups = {oddly_breakable_by_hand=2},
  10. paramtype = 'light',
  11. paramtype2 = 'facedir',
  12. selection_box = {
  13. type = 'fixed',
  14. fixed = {
  15. {-0.5, -0.5, -0.5, 1.5, 1.5, 0.5},
  16. }
  17. },
  18. collision_box = {
  19. type = 'fixed',
  20. fixed = {
  21. {-0.5, -0.5, -0.5, 1.5, 1.5, 0.5},
  22. }
  23. },
  24. can_dig = function(pos,player)
  25. local meta = minetest.get_meta(pos);
  26. local inv = meta:get_inventory()
  27. if player:get_player_name() == meta:get_string('owner') and
  28. inv:is_empty('cobble') and
  29. inv:is_empty('gravel') and
  30. inv:is_empty('concrete') and
  31. inv:is_empty('sand') then
  32. return true
  33. else
  34. return false
  35. end
  36. end,
  37. after_place_node = function(pos, placer, itemstack)
  38. if not epic.space_to_side(pos) then
  39. minetest.remove_node(pos)
  40. return itemstack
  41. else
  42. local meta = minetest.get_meta(pos)
  43. local timer = minetest.get_node_timer(pos)
  44. meta:set_string('owner',placer:get_player_name())
  45. meta:set_string('infotext','Cement Mixer (owned by '..placer:get_player_name()..')')
  46. timer:start(10)
  47. end
  48. end,
  49. after_dig_node = function(pos, oldnode)
  50. epic.remove_side_node(pos, oldnode)
  51. end,
  52. on_construct = function(pos)
  53. local meta = minetest.get_meta(pos)
  54. meta:set_string('formspec', 'size[9,10;]'..
  55. 'background[-0.15,-0.25;9.40,10.75;mylandscaping_madison_stone.png]'..
  56. --Gravel
  57. 'label[0.5,1;Crush-o-matic]'..
  58. 'label[2,2;Cobble or Gravel]'..
  59. 'list[context;cobble;2.5,1;1,1;]'..
  60. 'list[context;gravel;5.5,1;1,1;]'..
  61. 'label[6.5,1;Gravel]'..
  62. --Concrete
  63. 'label[5,0.5;Concrete Mixer]'..
  64. 'list[context;sand;5.5,2.5;1,1;]'..
  65. 'label[6.5,2.5;Sand]'..
  66. 'list[context;concrete;5.5,4.5;1,1;]'..
  67. 'label[6.5,4.5;Output]'..
  68. --Players Inven
  69. 'list[current_player;main;0.5,6;8,4;]')
  70. meta:set_string('infotext', 'Concrete Mixer')
  71. local inv = meta:get_inventory()
  72. inv:set_size('cobble', 1)
  73. inv:set_size('gravel', 1)
  74. inv:set_size('concrete', 1)
  75. inv:set_size('sand', 1)
  76. end,
  77. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  78. local input = stack:get_name()
  79. if listname == 'cobble' then
  80. if input == 'default:cobble' or minetest.get_item_group(input, 'ml') > 0 or 'default:gravel' then
  81. return 99
  82. else
  83. return 0
  84. end
  85. elseif listname == 'gravel' then
  86. if input ~= 'default:gravel' then
  87. return 0
  88. else
  89. return 99
  90. end
  91. elseif listname == 'sand' then
  92. if minetest.get_item_group(input, 'sand') > 0 then
  93. return 99
  94. else
  95. return 0
  96. end
  97. elseif listname == 'concrete' then
  98. return 0
  99. end
  100. end,
  101. on_timer = function(pos)
  102. local timer = minetest.get_node_timer(pos)
  103. local meta = minetest.get_meta(pos)
  104. local inv = meta:get_inventory()
  105. local cobble = inv:get_stack('cobble', 1)
  106. local gravel = inv:get_stack('gravel', 1)
  107. local sand = inv:get_stack('sand', 1)
  108. local cobble_inv = cobble:get_name()
  109. local sand_inv = sand:get_name()
  110. if cobble:get_name() == 'default:cobble' or minetest.get_item_group(cobble_inv, 'ml') > 0 then
  111. inv:add_item('gravel','default:gravel')
  112. cobble:take_item()
  113. inv:set_stack('cobble',1,cobble)
  114. elseif cobble:get_name() == 'default:gravel' then
  115. inv:add_item('sand', 'default:sand')
  116. cobble:take_item()
  117. inv:set_stack('cobble',1,cobble)
  118. elseif gravel:get_name() == 'default:gravel' and minetest.get_item_group(sand_inv, 'sand') > 0 then
  119. inv:add_item('concrete','mylandscaping:concrete_bag')
  120. gravel:take_item()
  121. inv:set_stack('gravel',1,gravel)
  122. sand:take_item()
  123. inv:set_stack('sand',1,sand)
  124. end
  125. timer:start(10)
  126. end,
  127. })