Guest User

doorControl

a guest
Mar 5th, 2014
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local t = turtle
  2. local error = 0
  3.  
  4. function rotateBlock()
  5.   rs.setOutput("left",true)
  6.   sleep(0.1)
  7.   rs.setOutput("left",false)
  8.   os.pullEvent("redstone")
  9.   if(not rs.getInput("left")) then
  10.     print("Warning: wrong redstone signal received")
  11.     local signal = false
  12.     while not signal do
  13.       os.pullEvent("redstone")
  14.       signal = rs.getInput("left")
  15.     end
  16.     print("Warning: correct redstone signal received after wrong signal")
  17.   end
  18. end
  19.  
  20. function openDoor()
  21.   t.select(2)
  22.   if(t.getItemCount(2) > 0) then
  23.     print("Error: ItemCount slot 2 > 0")
  24.     error = 11
  25.     return
  26.   end
  27.   rs.setOutput("top",true)
  28.   sleep(0.05)
  29.   rs.setOutput("top",false)
  30.   if(t.getItemCount(2) == 0) then
  31.     print("Error: ItemCount slot 2 == 0")
  32.     error = 12
  33.     return
  34.   end
  35.   if(not t.transferTo(3)) then
  36.     print("Error: transfer to slot 3 failed")
  37.     error = 13
  38.     return
  39.   end
  40.   if(not t.digUp()) then
  41.     print("Error: cannot break Block Breaker")
  42.     error = 21
  43.     return
  44.   end
  45.   t.select(1)
  46.   if(not t.placeUp()) then
  47.     print("Error: cannot place Auto Placer")
  48.     error = 22
  49.     return
  50.   end
  51.   if(t.getItemCount(1) < 1) then
  52.     print("Error: less than one Auto Placer remaining")
  53.     error = 14
  54.     return
  55.   end
  56.   rotateBlock()
  57.   t.select(3)
  58.   if(t.getItemCount(3) < 3) then
  59.     print("Error: less than three door blocks in slot 3")
  60.     error = 15
  61.     return
  62.   end
  63.   if(not t.dropUp(2)) then
  64.     print("Error: cannot drop two items into Auto Placer")
  65.     error = 31
  66.     return
  67.   end
  68. end
  69.  
  70. function closeDoor()
  71.   t.select(3)
  72.   if(t.getItemCount(3) < 1) then
  73.     print("Error: less than one door block(s) in slot 3")
  74.     error = 16
  75.     return
  76.   end
  77.   if(not t.dropUp()) then
  78.     print("Error: cannot drop items into Auto Placer")
  79.     error = 32
  80.     return
  81.   end
  82.   t.select(1)
  83.   local nPlacers = t.getItemCount(1)
  84.   if(not t.digUp()) then
  85.     print("Error: cannot break Auto Placer")
  86.     error = 23
  87.     return
  88.   end
  89.   if(t.getItemCount(1) ~= nPlacers + 1) then
  90.     print("Error: inventory mix up; nPlacers = "..nPlacers)
  91.     error = 17
  92.     return
  93.   end
  94.   t.select(2)
  95.   if(not t.placeUp()) then
  96.     print("Error: cannot place Block Breaker")
  97.     error = 24
  98.     return
  99.   end
  100.   rotateBlock()
  101. end
  102.  
  103. function consistencyCheck()
  104.  
  105. end
Advertisement
Add Comment
Please, Sign In to add comment