Advertisement
SpyMomiji

Untitled

Dec 14th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.97 KB | None | 0 0
  1. --north south east western
  2. Face = "north"
  3.  
  4. --front left right back
  5. Nuclear = "front"
  6. Material = "left"
  7. Void = "back"
  8.  
  9. --front left right back top bottom
  10. coolingSingel = "right"
  11. PauseSingel = "bottom"
  12.  
  13. --number
  14. ThickID = 30086
  15. FuelID = 30101
  16. ThickWarn = 9980
  17. FuelWarn = 9980
  18.  
  19. --maxtri
  20. ThickSlot = {2,3,10,13,19,22,29,30}
  21. FuelSlot = {11,12,20,21}
  22.  
  23. --=====codes=====
  24.  
  25. pos = {"north", "east", "south", "western"}
  26. dict = {"front", "right", "back", "left"}
  27.  
  28. function getPosition(drection,flip)
  29.     if (drection=="top") then
  30.         if flip then
  31.             return "down"
  32.         else
  33.             return "up"
  34.         end
  35.     elseif(drection=="bottom") then
  36.         if flip then
  37.             return "up"
  38.         else
  39.             return "down"
  40.         end
  41.     else
  42.         local ph = 1
  43.         local dh = 1
  44.         for s=1,#pos,1 do
  45.             if pos[s] == Face then
  46.                 ph = s
  47.                 if flip then ph = ph + 2 end
  48.                 break
  49.             end
  50.         end
  51.         for s=1,#dict,1 do
  52.             if dict[s] == drection then
  53.                 dh = s + ph -1
  54.                 break
  55.             end
  56.         end
  57.         while dh > 4 do
  58.             dh = dh - 4
  59.         end
  60.         return pos[dh]
  61.     end
  62. end
  63.  
  64. function getChest(direct,check)
  65.     if (check ~= peripheral.getType(direct)) then
  66.         return nil,false,peripheral.getType(direct)
  67.     end
  68.    
  69.     local gd = getPosition(direct,false)
  70.     local gdf = getPosition(direct,true)
  71.     local ch = peripheral.wrap(direct)
  72.     print ("get chest at "..direct..",with pos "..gd..","..peripheral.getType(direct))
  73.     local ct = {
  74.         size = ch.getInventorySize(),
  75.         info = function(index)
  76.             local ti = ch.getStackInSlot(index)
  77.             if ti == nil then
  78.                 return 0,0
  79.             else
  80.                 return ti.id,ti.dmg
  81.             end
  82.         end,
  83.         put = function(index,count,TurtleIndex)
  84.             local c = 0
  85.             if TurtleIndex ~= nil then
  86.                 c = ch.pullItemIntoSlot(gdf,TurtleIndex,count,index)
  87.             else
  88.                 c = ch.pullItem(gdf,index,count)
  89.             end
  90.             if c == 0 then
  91.                 return false,c
  92.             else
  93.                 return true,c
  94.             end
  95.         end,
  96.         take = function(index,count)
  97.             local ful = true
  98.             for si = 1,16,1 do
  99.                 if turtle.getItemCount(si) == 0 then
  100.                         ful = false
  101.                         break
  102.                 end
  103.             end
  104.             if ful then
  105.                 return false,0
  106.             else
  107.                 return true,ch.pushItem(gdf,index,count)
  108.             end
  109.         end
  110.     }
  111.     return ct,true,peripheral.getType(direct)
  112. end
  113.  
  114.  
  115.  
  116. nuc,suc = getChest(Nuclear,"nuclear_reactor")
  117.  
  118. if not suc then print ("fail") return end
  119.  
  120. mac,suc = getChest(Material,"ender_chest")
  121.  
  122. if not suc then print ("fail") return end
  123.  
  124. voc,suc = getChest(Void,"ender_chest")
  125.  
  126. if not suc then print ("fail") return end
  127. suc = nil
  128.  
  129.  
  130. prs = function(pa)
  131.     redstone.setOutput(coolingSingel,pa)
  132. end
  133.  
  134. sts = function(pa)
  135.     redstone.setOutput(PauseSingel,pa)
  136. end
  137.  
  138. prs(false)
  139. sts(false)
  140. local suc = true
  141.  
  142. --item control
  143. function clearTurtle()
  144.     for sei=1,16,1 do
  145.         local co = turtle.getItemCount(sei)
  146.         if co ~= 0 then
  147.             voc.put(sei,co)
  148.         end
  149.     end
  150. end
  151.  
  152. speedUp = false
  153. expection = false
  154.  
  155. function checkItem(itemID,maxdmg,slots)
  156.     for i=1,#slots,1 do
  157.         local d,g = nuc.info(slots[i])
  158.         if d ~= itemID then
  159.            
  160.             prs(true)
  161.             sts(false)
  162.             clearTurtle()
  163.            
  164.             local suc = false
  165.            
  166.             for i=1,8,1 do
  167.                 for j=1,mac.size,1 do
  168.                     if mac.info(j) == itemID then
  169.                         suc = mac.take(j,1)
  170.                         if suc then break end
  171.                     end
  172.                 end
  173.                 if suc then break else os.sleep(1) end
  174.             end
  175.             if not suc then print("<!>no item "..itemID) expection = true return end
  176.            
  177.             for ty=1,8,1 do
  178.                 suc = nuc.take(slots[i],1)
  179.                 if not suc then break end
  180.                 suc = nuc.put(slots[i],1,1)
  181.                 if suc then break end
  182.             end
  183.            
  184.             if not suc then print("<!>change item "..itemID.."failed,at slot "..slots[i]) expection = true return end
  185.            
  186.         elseif g >= maxdmg then
  187.             speedUp = true
  188.         end
  189.     end
  190. end
  191.  
  192. --main
  193. function start()
  194.     while true do
  195.        
  196.         speedUp = false
  197.        
  198.         checkItem(ThickID,ThickWarn,ThickSlot)
  199.         checkItem(FuelID,FuelWarn,FuelSlot)
  200.        
  201.         if expection then return end
  202.         prs(false)
  203.         sts(true)
  204.        
  205.         if speedUp then
  206.             os.sleep(0.25)
  207.         else
  208.             os.sleep(5)
  209.         end
  210.     end
  211. end
  212.  
  213. --go
  214. print ("start")
  215. start()
  216. prs(false)
  217. print ("stop with a expection")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement