IMarvinTPA

XP Farmer

Jan 28th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.28 KB | None | 0 0
  1. --pastebin get C2ZjmfV1 ninja
  2.  
  3. --shell.run("ninja rup")
  4.  
  5. local tArgs = { ... }
  6. local sOutput = tArgs[1]
  7. local filename = shell.getRunningProgram()
  8.  
  9. local function fixSide(aSide)
  10.     if aSide == nil then
  11.         aSide = ""
  12.     end
  13.     aSide = string.lower(aSide)
  14.     if aSide == "top" or aSide == "t" or aSide == "up" or aSide == "u"then
  15.         aSide = "t"
  16.     elseif aSide == "front" or aSide == "f" then
  17.         aSide = "f"
  18.     elseif aSide == "bottom" or aSide == "b" or aSide == "down" or aSide == "d" then
  19.         aSide = "b"
  20.     elseif aSide == "none" or aSide == "n" then
  21.         aSide = "n"
  22.     elseif aSide == "rtop" or aSide == "rt" or aSide == "rup" or aSide == "ru"then
  23.         aSide = "rt"
  24.     elseif aSide == "rfront" or aSide == "rf" then
  25.         aSide = "rf"
  26.     elseif aSide == "rbottom" or aSide == "rb" or aSide == "rdown" or aSide == "rd" then
  27.         aSide = "rd"
  28.     elseif aSide == "rright" or aSide == "rr" then
  29.         aSide = "rr"
  30.     elseif aSide == "rleft" or aSide == "rl" then
  31.         aSide = "rl"
  32.     elseif aSide == "rback" or aSide == "rbk" then
  33.         aSide = "rb"
  34.     else
  35.         aSide = nil
  36.     end
  37.     return aSide
  38. end
  39. sOutput = fixSide(sOutput)
  40.  
  41. if sOutput == nil then
  42.     print( "Usage: " .. filename .. " <output side> " )
  43.     print( "Side values are Top, Bottom, Front, and None" )
  44.     print( "The turtle will attack the front and push into the output side." )
  45.     print( "None can be specified if the turtle is expected to deal with items moving on their own." )
  46.     return
  47. end
  48.  
  49. local function isEmpty()
  50.     local bFull = true
  51.     local nTotalItems = 0
  52.     for n=1,16 do
  53.         local nCount = turtle.getItemCount(n)
  54.         if nCount == 0 then
  55.                 bFull = false
  56.         end
  57.         nTotalItems = nTotalItems + nCount
  58.     end
  59.          
  60.     if nCount == 0 then
  61.         print( "No more Items to drop." )
  62.         return true
  63.     end
  64.     return false
  65. end
  66.  
  67. local function flashSide(aSide)
  68.     --print("Flash " .. aSide .. " On ")
  69.     redstone.setOutput(aSide, true)
  70.     sleep(0.2)
  71.     --print("Flash " .. aSide .. " Off ")
  72.     redstone.setOutput(aSide, false)
  73.     sleep(0.2)
  74. end
  75.  
  76. local function unload()
  77.     if sOutput == "n" then
  78.         return
  79.     end
  80.     print( "Unloading items..." )
  81.  
  82.     for n=1,16 do
  83.         --unloaded = unloaded + turtle.getItemCount(n)
  84.         if (turtle.getItemCount(n) > 0) then
  85.             turtle.select(n)   
  86.             if sOutput == "t" then
  87.                 turtle.dropUp()
  88.             elseif sOutput == "f" then
  89.                 turtle.drop()
  90.             elseif sOutput == "b" then
  91.                 turtle.dropDown()
  92.             elseif sOutput == "rt" then
  93.                 flashSide("top")
  94.             elseif sOutput == "rd" then
  95.                 flashSide("bottom")
  96.             elseif sOutput == "rf" then
  97.                 flashSide("front")
  98.             elseif sOutput == "rb" then
  99.                 flashSide("back")
  100.             elseif sOutput == "rl" then
  101.                 flashSide("left")
  102.             elseif sOutput == "rf" then
  103.                 flashSide("right")
  104.             end
  105.            
  106.         end
  107.     end    
  108.     turtle.select(1)
  109. end
  110.  
  111. local function load()
  112.  
  113.     print( "Loading items..." )
  114.  
  115.     for n=1,16 do
  116.         --unloaded = unloaded + turtle.getItemCount(n)
  117.         if (turtle.getItemCount(n) == 0) then
  118.             turtle.select(n)
  119.             res = turtle.suck()
  120.             if res == false then
  121.                 print( "No more Items to get." )
  122.                 return false
  123.             end
  124.             sleep(60)
  125.         end
  126.     end
  127.     return true
  128. end
  129. local function displaySide(aSide)
  130.     if aSide == nil then
  131.         aSide = ""
  132.     end
  133.     aSide = string.lower(aSide)
  134.     if aSide == "t" then
  135.         aSide = "top"
  136.     elseif aSide == "f" then
  137.         aSide = "front"
  138.     elseif aSide == "b" then
  139.         aSide = "bottom"
  140.     elseif aSide == "n" then
  141.         aSide = "none"
  142.     elseif aSide == "rt" then
  143.         aSide = "redstone pulse top"
  144.     elseif aSide == "rf" then
  145.         aSide = "redstone pulse front"
  146.     elseif aSide == "rd" then
  147.         aSide = "redstone pulse down"
  148.     elseif aSide == "rr" then
  149.         aSide = "redstone pulse right"
  150.     elseif aSide == "rl" then
  151.         aSide = "redstone pulse left"
  152.     elseif aSide == "rb" then
  153.         aSide = "redstone pulse back"
  154.     else
  155.         aSide = "unknown (" .. aSide .. ")"
  156.     end
  157.     return aSide
  158. end
  159. print( "Attacking from " .. displaySide("f") .. " sending loot to " .. displaySide(sOutput) .. " with a delay of " .. 0.1 .. " seconds." )
  160.  
  161. --print("Left: " .. peripheral.getType("left"))
  162. --print("Right: " .. peripheral.getType("right"))
  163. local xp
  164. if peripheral.getType("left") == "xp" then
  165.     xp = peripheral.wrap("left")
  166. elseif peripheral.getType("right") == "xp" then
  167.     xp = peripheral.wrap("right")
  168. end
  169.  
  170.  
  171. if xp ~= nil then
  172.     xp.setAutoCollect(true)
  173. end
  174.  
  175. while true do
  176.     turtle.attack()
  177.     turtle.suck()
  178.     --xp.collect()
  179.     unload()
  180.     sleep(0.1)
  181. end
Advertisement
Add Comment
Please, Sign In to add comment