machine.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. minetest.register_craft({
  2. output = 'tombs:machine',
  3. recipe = {
  4. {'default:stone', 'default:stone', 'default:stone'},
  5. {'default:steel_ingot', 'default:diamond', 'default:steel_ingot'},
  6. {'default:stone', 'default:stone', 'default:stone'}
  7. }
  8. })
  9. minetest.register_node('tombs:machine', {
  10. description = 'Gravestone Engraver',
  11. tiles = {
  12. 'tombs_machine_side.png',
  13. 'tombs_machine_side.png',
  14. 'tombs_machine_side.png',
  15. 'tombs_machine_side.png',
  16. 'tombs_machine_side.png',
  17. 'tombs_machine_front.png',
  18. },
  19. groups = {oddly_breakable_by_hand=3},
  20. paramtype2 = 'facedir',
  21. on_construct = function(pos)
  22. local meta = minetest.get_meta(pos)
  23. meta:set_string('infotext', 'Gravestone Creator')
  24. meta:set_string('formspec', machine_formspec_centered)
  25. meta:set_string('var', 0)
  26. local inv = meta:get_inventory()
  27. inv:set_size('tool', 1)
  28. inv:set_size('input', 1)
  29. inv:set_size('output', 15)
  30. end,
  31. on_receive_fields = function(pos, formname, fields, sender)
  32. local meta = minetest.get_meta(pos)
  33. local inv = meta:get_inventory()
  34. local input_stack = inv:get_stack('input', 1)
  35. local input = input_stack:get_name()
  36. if fields ['offset'] then
  37. meta:set_string('formspec', machine_formspec_offset)
  38. meta:set_string('var', 1)
  39. tombs.populate_output(pos)
  40. elseif fields ['centered'] then
  41. meta:set_string('formspec', machine_formspec_centered)
  42. meta:set_string('var', 0)
  43. tombs.populate_output(pos)
  44. end
  45. end,
  46. can_dig = function(pos)
  47. local meta = minetest.get_meta(pos)
  48. local inv = meta:get_inventory()
  49. if inv:is_empty('tool') and
  50. inv:is_empty('input') and
  51. inv:is_empty('output') then
  52. return true
  53. else
  54. return false
  55. end
  56. end,
  57. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  58. if listname == 'input' then
  59. local input = stack:get_name()
  60. if not tombs.nodes[input] then
  61. return 0
  62. else
  63. return 99
  64. end
  65. end
  66. if listname == 'tool' then
  67. if stack:get_name() == 'bones:bones' then
  68. return 99
  69. elseif stack:get_name() == 'tombs:chisel' then
  70. return 1
  71. elseif stack:get_name() == 'mychisel:chisel' then
  72. return 1
  73. else
  74. return 0
  75. end
  76. end
  77. if listname == 'output' then
  78. return 0
  79. end
  80. end,
  81. on_metadata_inventory_put = function(pos)
  82. tombs.populate_output(pos)
  83. end,
  84. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  85. local meta = minetest.get_meta(pos)
  86. local inv = meta:get_inventory()
  87. local input_stack = inv:get_stack('input', 1)
  88. local tool_stack = inv:get_stack('tool', 1)
  89. local input = input_stack:get_name()
  90. local var = meta:get_string('var')
  91. if listname == 'input' then
  92. inv:set_list('output', {})
  93. elseif listname == 'tool' then
  94. inv:set_list('output', {})
  95. elseif listname == 'output' then
  96. input_stack:take_item(1)
  97. if tool_stack:get_name() == 'bones:bones' then
  98. tool_stack:take_item(1)
  99. elseif tool_stack:get_name() == 'tombs:chisel' then
  100. tool_stack:add_wear(65535 / 48)
  101. elseif tool_stack:get_name() == 'mychisel:chisel' then
  102. tool_stack:add_wear(65535 / 48)
  103. end
  104. inv:set_stack('tool',1,tool_stack)
  105. inv:set_stack('input',1,input_stack)
  106. local stone_stack = inv:get_stack(listname, index)
  107. if not stone_stack:is_empty() and stone_stack:get_name()~=stack:get_name() then
  108. local player_inv = player:get_inventory()
  109. if player_inv:room_for_item('main', stone_stack) then
  110. player_inv:add_item('main', stone_stack)
  111. end
  112. end
  113. if inv:is_empty('input') then
  114. inv:set_list('output', {})
  115. elseif inv:is_empty('tool') then
  116. inv:set_list('output', {})
  117. else
  118. tombs.populate_output(pos)
  119. end
  120. end
  121. end,
  122. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  123. local meta = minetest.get_meta(pos)
  124. local inv = meta:get_inventory()
  125. local input_stack = inv:get_stack(listname, index)
  126. local player_inv = player:get_inventory()
  127. if not player_inv:room_for_item('main', input_stack) then
  128. return 0
  129. else return stack:get_count()
  130. end
  131. end
  132. })
  133. function tombs.populate_output(pos)
  134. local meta = minetest.get_meta(pos)
  135. local inv = meta:get_inventory()
  136. local input_stack = inv:get_stack('input', 1)
  137. local tool_stack = inv:get_stack('tool', 1)
  138. local input = input_stack:get_name()
  139. local var = meta:get_string('var')
  140. if tombs.nodes[input] then
  141. if tool_stack:get_name() == 'bones:bones' or tool_stack:get_name() == 'tombs:chisel'
  142. or tool_stack:get_name() == 'mychisel:chisel' then
  143. inv:set_list('output', {})
  144. inv:set_list('output', tombs.crafting(input, var))
  145. end
  146. else
  147. inv:set_list('output', {})
  148. end
  149. end