prozacgod

Gravelator

Jun 5th, 2014
1,189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. --[[
  2.  
  3. I wrote this to test items coming from a vacuum hopper, if they fuzzy match the naming criterion, then
  4. it assumes they are are broken ores, and then crafts as many as it can into a 2x2 grid, making gravel ore
  5.  
  6. It keeps up well on a simple system with four sieves and 4 activators per sieve, might be able to handle
  7. larger volumes.
  8.  
  9. In my build I had 4 sieves surrounding an Iron chest, a vacuum hopper was placed on top of this chest
  10. The crafty turtle was below it, and a chest was below the turtle, the top 10 lines or so should be all
  11. you'd need to change to make it cater to your build
  12.  
  13. ]]
  14. -- Broken Ores come from this chest
  15. local chest = peripheral.wrap("top")
  16. -- The turtle's direction in relation to chest.
  17. local turtleDir = "down"
  18.  
  19. function dropItems()
  20.   -- rewrite this to drop slot 1 wherever
  21.   turtle.select(1)
  22.   turtle.dropDown()
  23. end
  24.  
  25. --[[ Leave the rest alone, or break it.. or whatever.. ]]
  26.  
  27. function isBrokenOre(stack)
  28.   if stack == nil then
  29.     return false
  30.   end
  31.  
  32.   local bstart,bend = stack.name:find("Broken")
  33.   local ostart,oend = stack.name:find("Ore")
  34.  
  35.   if bstart == nil then
  36.     return false
  37.   end
  38.  
  39.   if ostart == nil then
  40.     return false
  41.   end
  42.  
  43.   return true
  44. end
  45.  
  46. function fetchSlot(slot, qty)
  47.   chest.pushItem(turtleDir, slot, qty)
  48. end
  49.  
  50. function makeGravel(slot, stack)
  51.   local c = math.floor(stack.qty/4)
  52.   local qty = c * 4
  53.  
  54.   fetchSlot(slot, qty)
  55.   turtle.transferTo(2, c)
  56.   turtle.transferTo(5, c)
  57.   turtle.transferTo(6, c)
  58.  
  59.   turtle.craft()
  60.   dropItems()
  61. end
  62.  
  63. function scanChest()
  64.   chest.condenseItems()
  65.   local stacks = chest.getAllStacks()
  66.  
  67.   for i,stack in ipairs(stacks) do
  68.     if isBrokenOre(stack) then
  69.       print("ORE: ", stack.name, "  ", stack.id)
  70.       if stack.qty >= 4 then
  71.         makeGravel(i, stack)
  72.       end
  73.     else
  74.       -- transfer through
  75.       chest.pushItem(turtleDir, i, stack.qty)
  76.       dropItems()
  77.       print("     ", stack.name, "  ", stack.id)
  78.     end
  79.   end
  80. end
  81.  
  82. while true do
  83.   scanChest()
  84. end
Advertisement
Add Comment
Please, Sign In to add comment