Advertisement
Banane9

jarswitcher

Feb 27th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. local mapSideToTurtleFunction = function(side, turtleFunction)
  2.     if string.lower(side) == "top" then
  3.         return turtle[turtleFunction.."Up"]
  4.     elseif string.lower(side) == "bottom" then
  5.         return turtle[turtleFunction.."Down"]
  6.     elseif string.lower(side) == "front" then
  7.         return turtle[turtleFunction]
  8.     end
  9. end
  10.  
  11. local isAboveLevel = function(jar, switchAmount)
  12.     local aspects = jar.getAspects()
  13.     if not aspects then return false end
  14.     return aspects[1].quantity > switchAmount
  15. end
  16.  
  17. local isBelowLevel = function(jar, switchAmount)
  18.     local aspects = jar.getAspects()
  19.     if not aspects then return true end
  20.     return aspects[1].quantity < switchAmount
  21. end
  22.  
  23. local Args = {...} -- jarToReplace newJars oldJars (<|>)switchAmount
  24.  
  25. local pickUpJar = mapSideToTurtleFunction(Args[1], "dig")
  26. local placeJar = mapSideToTurtleFunction(Args[1], "place")
  27. local jar = peripheral.wrap(Args[1])
  28. local dropJar = mapSideToTurtleFunction(Args[2], "drop")
  29. local suckJar = mapSideToTurtleFunction(Args[3], "suck")
  30. local checkLevel = 1
  31.  
  32. if string.sub(Args[4], 1, 1) == "<" then
  33.     checkLevel = isBelowLevel
  34. elseif string.sub(Args[4], 1, 1) == ">" then
  35.     checkLevel = isAboveLevel
  36. end
  37.  
  38. local switchAmount = tonumber(string.sub(Args[4], 2))
  39.  
  40. while true do
  41.     if checkLevel(jar, switchAmount) then
  42.         while not pickUpJar() do sleep(2) end
  43.         sleep(1)
  44.         while not dropJar() do sleep(2) end
  45.         sleep(1)
  46.         while not suckJar() do sleep(2) end
  47.         sleep(1)
  48.         while not placeJar() do sleep(2) end
  49.     end
  50.     sleep(5)
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement