Advertisement
Guest User

generate

a guest
Aug 22nd, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. sourceChest = "top" --top or bottom
  2. hasMiniumStone = true
  3. recipe = {2,5,6,9}
  4.  
  5. function emptyInventory(targetChest)
  6.  
  7.  local f = 1
  8.  if hasMiniumStone == true then
  9.   f = 2
  10.  end
  11.  while f <= 16 do
  12.   if turtle.getItemCount(f) > 0 then
  13.    turtle.select(f)
  14.    if targetChest == "front" then
  15.     turtle.drop()
  16.    elseif targetChest == "bottom" then
  17.     turtle.dropDown()
  18.    elseif targetChest == "top" then
  19.     turtle.dropUp()
  20.    end
  21.   end
  22.   f = f + 1
  23.  end
  24. end
  25.  
  26. function distribute(slots)
  27.  local tempSlot = 1
  28.  if hasMiniumStone == true then
  29.   tempSlot = 2
  30.  end
  31.  turtle.select(tempSlot)
  32.  --Get some items from the source chest
  33.  while turtle.getItemCount(tempSlot) < table.getn(slots) do
  34.   if sourceChest == "top" then
  35.    turtle.suckUp()
  36.   else
  37.    turtle.suckDown()
  38.   end
  39.  end
  40.  
  41.  --Get rid of what we don't need
  42.  if sourceChest == "top" then
  43.   turtle.dropUp(turtle.getItemCount(tempSlot)-table.getn(slots))
  44.  else
  45.   turtle.dropDown(turtle.getItemCount(tempSlot)-table.getn(slots))
  46.  end
  47.  
  48.  --Get rid of extra overflow
  49.  if turtle.getItemCount(tempSlot + 1) > 0 then
  50.   turtle.select(tempSlot + 1)
  51.   if sourceChest == "top" then
  52.    turtle.dropUp(turtle.getItemCount(tempSlot + 1))
  53.   else
  54.    turtle.dropDown(turtle.getItemCount(tempSlot + 1))
  55.   end
  56.  end
  57.  
  58.  --Distribute
  59.  for i,v in ipairs(slots) do
  60.   if v == tempSlot then
  61.    
  62.   else
  63.    turtle.select(tempSlot)
  64.    turtle.transferTo(v,1)
  65.   end
  66.  end
  67. end
  68.  
  69. function craft()
  70.  turtle.select(1)
  71.  turtle.craft(1)
  72. end
  73.  
  74. print("Emptying inventory in case of reboot")
  75. emptyInventory(sourceChest)
  76. while true do
  77.  print("Distributing...")
  78.  distribute(recipe)
  79.  print("Crafting...")
  80.  craft()
  81.  print("Passing new items...")
  82.  emptyInventory("front")
  83.  sleep(0.01)
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement