TheKojent

Turbo Tree Sorter

Dec 26th, 2014
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.30 KB | None | 0 0
  1. rednet.open("left")
  2.  
  3. local mainID = 15
  4. local touchID = 16
  5. local charcoal = false
  6.  
  7. local function turnAround()
  8.     turtle.turnLeft()
  9.     turtle.turnLeft()
  10. end
  11.  
  12. local function goUp(count)
  13.     for k = 1,count do
  14.         turtle.up()
  15.     end
  16. end
  17.  
  18. local function goDown(count)
  19.     for k = 1,count do
  20.         turtle.down()
  21.     end
  22. end
  23.  
  24. while true do    --Main Loop
  25.     while turtle.getItemCount() == 0 do    --Get items
  26.         if not turtle.suck() then
  27.             goDown(2)
  28.             turtle.suckDown()
  29.             goUp(2)
  30.         end
  31.         if turtle.getItemCount() == 0 then
  32.             rednet.send(mainID, "home")
  33.             sleep(.5)
  34.             rednet.send(mainID, "2")
  35.             sleep(60)
  36.             rednet.send(mainID, "1")
  37.             sleep(60)
  38.         end
  39.     end
  40.    
  41.     rednet.send(mainID, "0")
  42.     sleep(.5)
  43.     rednet.send(mainID, "away")
  44.    
  45.     if turtle.getItemCount() ~= 0 then
  46.         local data = turtle.getItemDetail()
  47.         if data.name == "minecraft:log" then         --Sort logs
  48.             --[[
  49.             rednet.send(touchID, "charcoal")
  50.             while true do
  51.                 id, message = rednet.receive()
  52.                 if id == touchID then
  53.                     charcoal = message
  54.                     break
  55.                 end
  56.             end
  57.             ]]
  58.             if charcoal then
  59.                 turtle.turnLeft()
  60.                 if not turtle.drop() then
  61.                     goUp(4)
  62.                     turtle.turnLeft()
  63.                     turtle.drop()
  64.                     turtle.turnRight()
  65.                     goDown(4)
  66.                 end
  67.                 turtle.turnRight()
  68.             else
  69.                 goUp(4)
  70.                 turnAround()
  71.                 turtle.drop()
  72.                 turnAround()
  73.                 goDown(4)
  74.             end
  75.         elseif data.name == "minecraft:sapling" then --Sort saplings
  76.             goUp(1)
  77.             if not turtle.drop() then
  78.                 goUp(3)
  79.                 turnAround()
  80.                 turtle.drop()
  81.                 turnAround()
  82.                 goDown(3)
  83.             end
  84.             goDown(1)
  85.         elseif data.name == "minecraft:apple" then   --Sort apples
  86.             turnAround()
  87.             goUp(1)
  88.             turtle.drop()
  89.             goDown(1)
  90.             turnAround()
  91.         elseif data.name == "minecraft:coal" then    --Sort Charcoal and refuel (if needed)
  92.             if turtle.getFuelLevel() < (turtle.getFuelLimit() - 5120) then
  93.                 turtle.refuel()
  94.             else
  95.                 goDown(2)
  96.                 turtle.turnLeft()
  97.                 if not turtle.drop() then
  98.                     goUp(6)
  99.                     turnRight()
  100.                     if not turtle.drop() then
  101.                         turnAround()
  102.                         turtle.drop()
  103.                         turnAround()
  104.                     end
  105.                     goDown(4)
  106.                 else
  107.                     goUp(2)
  108.                     turtle.turnRight()
  109.                 end
  110.             end
  111.         else                        --Sort everything else
  112.             goDown(1)
  113.             turtle.turnRight()
  114.             turtle.drop()
  115.             turtle.turnLeft()
  116.             goUp(1)
  117.         end
  118.     end
  119. end
  120.  
  121. rednet.close("left")
Advertisement
Add Comment
Please, Sign In to add comment