Advertisement
bigibas123

FarmTurtle

Jul 13th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.78 KB | None | 0 0
  1. --[[
  2.     11 X 11 farm
  3. ]]--
  4.  
  5. os.loadAPI("tst")
  6.  
  7. stroke= true
  8. run = true
  9. local function getFreeSlot()
  10.     for slot=1,16 do
  11.         if turtle.getItemCount(slot) == 0 then
  12.             return slot
  13.         end
  14.     end
  15. end
  16.  
  17. local function seedsToOne()
  18.     for slot=1,16 do
  19.         data = turtle.getItemDetail(slot)
  20.         if data ~= nil then
  21.             if data["name"] == "minecraft:wheat_seeds" then
  22.                 turtle.select(slot)
  23.                 turtle.transferTo(1)
  24.             end
  25.         end
  26.     end
  27. end
  28.  
  29. local function moveIone()
  30.     turtle.select(1)
  31.     free=getFreeSlot()
  32.     turtle.transferTo(free)
  33. end
  34.  
  35.  
  36. function organize()
  37.     moveIone()
  38.     seedsToOne()
  39. end
  40. function doFarm(x,y)
  41.     if x == 6 and y == 6 then
  42.         return true
  43.     end
  44.     local success, data = turtle.inspectDown()
  45.    
  46.     if success then
  47.         if data.name == "minecraft:fence" then
  48.             os.shutdown()
  49.             else
  50.             if data.metadata == 7 then
  51.                 turtle.digDown()
  52.                 organize()
  53.                 turtle.select(1)
  54.                 turtle.placeDown()
  55.                 else
  56.                 return false
  57.             end
  58.         end
  59.         else
  60.         turtle.digDown()
  61.         turtle.select(1)
  62.         turtle.placeDown()
  63.         return false
  64.     end
  65. end
  66.  
  67. function goToStart()
  68.     tst.turnAround()
  69.     for i=1,10 do
  70.         tst.forward()
  71.     end
  72.     tst.turnRight()
  73.     for i=1,10 do
  74.         tst.forward()
  75.     end
  76.     tst.turnRight()
  77.     x,y,z = tst.getLocation()
  78.     print(x..";"..y..";"..z)
  79. end
  80.  
  81. function doLine(x)
  82.     for y=1,10 do
  83.         doFarm(x,y)
  84.         tst.forward()
  85.     end
  86. end
  87.  
  88. function emptyInf()
  89.     organize()
  90.     tst.turnAround()
  91.     for slot=2,16 do
  92.         turtle.select(slot)
  93.         data = turtle.getItemDetail()
  94.         if data ~= nil then
  95.             turtle.drop()
  96.         end
  97.     end
  98.     tst.turnRight()
  99.     tst.turnRight()
  100. end
  101.  
  102. function waitForEnd()
  103.     while true do
  104.         local event, key = os.pullEvent( "key" )
  105.         if key == keys.e then
  106.             return
  107.         end
  108.     end
  109. end
  110.  
  111. function main()
  112.     while run do
  113.         organize()
  114.         for x=1,10 do
  115.             doLine(x)
  116.             if stroke then
  117.                 doFarm(x,11)
  118.                 tst.turnRight()
  119.                 tst.forward()
  120.                 tst.turnRight()
  121.                 stroke = false
  122.                 else
  123.                 doFarm(x,0)
  124.                 tst.turnLeft()
  125.                 tst.forward()
  126.                 tst.turnLeft()
  127.                 stroke = true
  128.             end
  129.         end
  130.         doLine(11)
  131.         doFarm(11,11)
  132.         goToStart()
  133.         emptyInf()
  134.         sleep(120)
  135.     end  
  136.    
  137.     end
  138.    
  139. tst.manSetLocation(0,0,0)
  140. parallel.waitForAny(waitForEnd,main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement