akihex

cleric

Jan 14th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. -- just dump one item each from the first (four)six slots, wait for signal change from one to two and than throw down a piece of living rock from slot 16
  2.  
  3. local signalSide = "back"
  4. local function checkSignal()
  5.   return rs.getAnalogInput(signalSide)
  6. end
  7.  
  8. local pistonSide = "right"
  9. local function piston(onOff)
  10.   rs.setOutput(pistonSide,onOff)
  11. end
  12.  
  13. local itemPattern = {1,2,3,4}
  14. local extPattern = {5,6}
  15. local finalReagent = {16}
  16.  
  17. local function checkInv(pattern)
  18.   for _,k in pairs(pattern) do
  19.     if turtle.getItemCount(k) == 0 then
  20.       return false
  21.     end
  22.   end
  23.   return true
  24. end
  25.  
  26. local function checkInventory()
  27.   return checkInv(itemPattern)
  28. end
  29.  
  30. local function checkExtInv()
  31.   return checkInv(extPattern)
  32. end
  33.  
  34. local function checkReagent()
  35.   return checkInv(finalReagent)
  36. end
  37.  
  38. local function checkNWait(pattern)
  39.   if not checkInv(pattern) then
  40.     print("Waiting for items: ingredients in slots 1-6 and living rock in slot 16")
  41.     local event = os.pullEvent("turtle_inventory")
  42.     while not checkInv(pattern) do sleep(1) end
  43.   end
  44.   return checkInv(pattern)
  45. end
  46.  
  47. local function dropItems(pattern)
  48.   for _,k in pairs(pattern) do
  49.     turtle.select(k)
  50.     turtle.drop(1)
  51.     sleep(0.5)
  52.   end
  53. end
  54.  
  55. local function wait2sOrSignal1()
  56.   sleep(1)
  57.   if checkSignal() == 1 then return true end
  58.   sleep(1)
  59.   if checkSignal() == 1 then return true else return false end
  60. end
  61.  
  62. local function finishRecipe()
  63.   checkNWait(finalReagent)
  64.   print("Finishing Runic Altar Creation")
  65.   sleep(1)
  66.   dropItems(finalReagent)
  67.   sleep(1.5)
  68.   piston(true)
  69.   sleep(3.5)
  70.   piston(false)
  71. end
  72.  
  73. piston(false)
  74.  
  75. while true do
  76.   if checkSignal() == 0 then
  77.     checkNWait(itemPattern)
  78.     dropItems(itemPattern)
  79.     if checkSignal() == 0 then
  80.       if not wait2sOrSignal1() then
  81.         checkNWait(extPattern)
  82.         dropItems(extPattern)
  83.         wait2sOrSignal1()
  84.       end
  85.     end
  86.   end
  87.   if checkSignal() == 1 then
  88.     local event = os.pullEvent("redstone")
  89.     if checkSignal() == 2 then
  90.       finishRecipe()
  91.     end
  92.   elseif checkSignal() == 2 then
  93.     finishRecipe()
  94.   elseif checkSignal() > 2 then
  95.     print("Weird Signal Alert: ", checkSignal())
  96.   end
  97.   sleep(2)
  98.   print("Starting next item creation")
  99. end
Advertisement
Add Comment
Please, Sign In to add comment