Advertisement
gyoce

first program farm lua

Aug 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.75 KB | None | 0 0
  1. farming = false
  2. pos = {0, 1, 0} -- x, y, z
  3. front = true
  4.  
  5. function selectSeed()
  6.     for i = 1, 16 do
  7.         local data = turtle.getItemDetail(i)
  8.         if data ~= nil then
  9.             if data.name == "immersiveengineering:seed" then
  10.                 turtle.select(i)
  11.                 break
  12.             end
  13.         end
  14.     end
  15. end
  16.  
  17. function moveAndDig()
  18.     if turtle.forward() == false then
  19.         turtle.dig()
  20.         turtle.forward()
  21.         turtle.digDown()
  22.         selectSeed()
  23.         turtle.placeDown()
  24.     end
  25. end
  26.  
  27. function dropAll()
  28.     for i = 1, 16 do
  29.         local data = turtle.getItemDetail(i)
  30.         if data ~= nil then
  31.             turtle.select(i)
  32.             if data.name == "immersiveengineering:seed" then
  33.                 turtle.turnLeft()
  34.                 if turtle.drop() == false then
  35.                     print("No more space in the seed chest")
  36.                     farming = false
  37.                 end
  38.                 turtle.turnRight()
  39.             elseif data.name == "immersiveengineering:material" then
  40.                 turtle.turnRight()
  41.                 if turtle.drop() == false then
  42.                     print("No more space in the result chest")
  43.                     farming = false
  44.                 end
  45.                 turtle.turnLeft()
  46.             else
  47.                 if turtle.dropUp() == false then
  48.                     print("No more space in the miscellaneous chest")
  49.                     farming = false
  50.                 end
  51.             end
  52.         end
  53.     end
  54. end
  55.  
  56. function needfuel()
  57.     if turtle.getFuelLevel() < 100 then
  58.         if pos[1] == 0 and pos[2] == 1 and pos[3] == 0 then
  59.             if turtle.suckDown(16) == false then
  60.                 print("No more fuel in the fuel chest")
  61.                 farming = false
  62.             elseif turtle.refuel() == false then
  63.                 print("Error while refueling")
  64.                 farming = false
  65.             end
  66.         end
  67.     end
  68. end
  69.  
  70. function farm()
  71.     -- Drop all items
  72.     dropAll()
  73.  
  74.     if farming == true then
  75.         -- Look if fuel is needed
  76.         needfuel()
  77.  
  78.         if farming == true then
  79.             -- Just the first block
  80.             moveAndDig()
  81.             pos[3] = pos[3] + 1
  82.  
  83.             -- For all the farm 9 * 9 the first time
  84.             for i = 1, 9 do
  85.                 for j = 1, 8 do
  86.                     moveAndDig()
  87.                     if front == true then
  88.                         pos[3] = pos[3] + 1
  89.                     else
  90.                         pos[3] = pos[3] - 1
  91.                     end            
  92.                 end
  93.  
  94.                 -- For the turn of the turtle
  95.                 if i < 9 then
  96.                     if front == true then
  97.                         turtle.turnRight()
  98.                         moveAndDig()
  99.                         turtle.turnRight()
  100.                         pos[1] = pos[1] + 1
  101.                         front = false
  102.                     else
  103.                         turtle.turnLeft()
  104.                         moveAndDig()
  105.                         turtle.turnLeft()
  106.                         pos[1] = pos[1] + 1
  107.                         front = true
  108.                     end
  109.                 end                
  110.             end
  111.  
  112.             -- Going at the start
  113.             turtle.turnLeft()
  114.             for i = 1, 8 do
  115.                 moveAndDig()
  116.                 pos[1] = pos[1] - 1
  117.             end
  118.  
  119.             turtle.turnLeft()
  120.             for i = 1, 9 do
  121.                 moveAndDig()
  122.                 pos[3] = pos[3] - 1
  123.             end
  124.  
  125.             turtle.turnLeft()
  126.             turtle.turnLeft()
  127.         end
  128.     end
  129.  
  130.     sleep(60)
  131. end
  132.  
  133. function main()
  134.     farming = true
  135.     while farming == true do
  136.         farm()
  137.     end
  138. end
  139.  
  140. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement