akihex

frankenWither

May 14th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | None | 0 0
  1. local ae = peripheral.wrap("bottom")
  2. local bubble = peripheral.wrap("front")
  3. local dir = "up"
  4. local head = "left"
  5. local body = "right"
  6. local placer = {[body]=peripheral.wrap(body),[head]=peripheral.wrap(head)}
  7. local sandID = 88
  8. local skullID = 397
  9.  
  10. local function stockUp()
  11.   ae.pullItem(dir,1,64)
  12.   ae.pullItem(dir,2,64)
  13.   local item = ae.getStackInSlot(1)
  14.   if not item or item.id ~= sandID then
  15.     print("Error: Wrong item in interface")
  16.     return false
  17.   end
  18.   local nSand = ae.pushItemIntoSlot(dir,1,4,1)
  19.   while nSand < 4 do
  20.     nSand = nSand + ae.pushItemIntoSlot(dir,1,4-nSand,1)
  21.   end
  22.   local nSkull = ae.pushItemIntoSlot(dir,2,3,2)
  23.   while nSkull < 3 do
  24.     nSkull = nSkull + ae.pushItemIntoSlot(dir,2,3-nSkull,2)
  25.   end
  26.   if turtle.getItemCount(1) == 4 and turtle.getItemCount(2) == 3 then do return true end
  27.   else return false end
  28. end
  29.  
  30. local function pulse(dir)
  31.   rs.setOutput(dir,true)
  32.   sleep(0.1)
  33.   rs.setOutput(dir,false)
  34. end
  35.  
  36. local function bodyCount()
  37.   return turtle.getItemCount(1) > 0 or turtle.getItemCount(2) > 1
  38. end
  39.  
  40. local function headCount()
  41.   --return turtle.getItemCount(2) > 0
  42.   -- bug: the last wither skull gets placed but never leaves the turtles inventory
  43.   sleep(1.2)
  44.   return false
  45. end
  46.  
  47. local CountItem = {[body]=bodyCount, [head]=headCount}
  48.  
  49. local function place(dir)
  50. --  rs.setOutput(dir,true)
  51.   while not bubble.isActivate() do
  52.     bubble.setActivate(true)
  53.   end
  54.   placer[dir].setActivate(true)
  55.   sleep(0.1)
  56.   while CountItem[dir]() do
  57.     sleep(0.1)
  58.   end
  59. --  rs.setOutput(dir,false)
  60.   placer[dir].setActivate(false)
  61. end
  62.  
  63. local it = 0
  64. while true do
  65.   print("Iteration "..it)
  66.   if not stockUp() then break end
  67.   place(body)
  68.   place(head)
  69.   sleep(10)
  70.   it = it + 1
  71. end
Advertisement
Add Comment
Please, Sign In to add comment