Advertisement
Renzott

Turtle Minecraft Farmer

Jan 31st, 2021 (edited)
1,295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. x = 0
  2. z = 0
  3.  
  4. a = 8
  5. b = 8
  6.  
  7. isRunning = true
  8. isLeft = true
  9. isFinishCycle = false
  10.  
  11. cycle = 0;
  12.  
  13. function statsTurtle()
  14.     term.setCursorPos(1,12)
  15.     print("Ciclos: ", math.floor(cycle / 2))
  16.  
  17.     term.setCursorPos(1,13)
  18.     actualFuel = turtle.getFuelLevel()
  19.     totalFuel = turtle.getFuelLimit()
  20.     print("Energia: ",actualFuel,"/",totalFuel)
  21. end
  22.  
  23. function turnRight()
  24.     turtle.turnRight()
  25.     turtle.forward()
  26.     turtle.turnRight()
  27. end
  28.  
  29. function turnLeft()
  30.     turtle.turnLeft()
  31.     turtle.forward()
  32.     turtle.turnLeft()
  33. end
  34.  
  35. function transferItemsToChest()
  36.     for i = 2,16 do
  37.         turtle.select(i)
  38.         turtle.dropDown()
  39.     end
  40.     turtle.select(1)
  41. end
  42.  
  43. function harvestCrop(crop)
  44.     if crop.state.age == 7 then
  45.         turtle.digDown()
  46.         turtle.placeDown()
  47.     end
  48. end
  49.  
  50. function placeCrop()
  51.     turtle.placeDown()
  52. end
  53.  
  54. function checkBlockDown()
  55.     isBlock,block = turtle.inspectDown();
  56.    
  57.     chest = nil
  58.     crop = nil
  59.  
  60.     if isBlock then
  61.         if type(block) == "table" then
  62.             chest = string.find(block.name,"chest")
  63.             crop = string.find(block.name,"crop")  
  64.         end
  65.     else
  66.         placeCrop()
  67.     end
  68.  
  69.     if chest ~= nil then
  70.         term.clear()
  71.         term.setCursorPos(1,6)
  72.         print("Limpiando inventario...")
  73.         statsTurtle()
  74.         transferItemsToChest()
  75.     else
  76.         if crop ~= nil then
  77.             term.clear()
  78.             term.setCursorPos(1,6)
  79.             print("Crop Actual: ",block.state.age)
  80.             statsTurtle()
  81.             harvestCrop(block)
  82.         end
  83.     end
  84. end
  85.  
  86. function checkCropHarvested()
  87.     turtle.forward()
  88.     turtle.down()
  89.     turtle.turnLeft()
  90.     turtle.turnLeft()
  91.     while true do
  92.         isBlock,block = turtle.inspect()
  93.  
  94.         if isBlock then
  95.             sleep(1)
  96.             term.clear()
  97.             term.setCursorPos(1,6)
  98.             print("Nivel del Crop: ", block.state.age)
  99.             statsTurtle()
  100.             if block.state.age == 7 then
  101.                 turtle.up()
  102.                 turtle.forward()
  103.                 break
  104.             end
  105.         else
  106.             turtle.up()
  107.             turtle.forward()
  108.             break
  109.         end
  110.     end
  111. end
  112.  
  113. while isRunning do
  114.  
  115.     checkBlockDown()
  116.  
  117.     if x == a and z == b then
  118.         isFinishCycle = true
  119.     end
  120.  
  121.     if x == a then
  122.         if isFinishCycle then
  123.             isFinishCycle = false
  124.             isLeft = not isLeft
  125.             z = 0
  126.             checkCropHarvested()
  127.             cycle = cycle + 1;
  128.         else
  129.             if isLeft then
  130.                 turnRight()
  131.             else
  132.                 turnLeft()
  133.             end
  134.             z = z + 1
  135.         end
  136.  
  137.         isLeft = not isLeft
  138.         x = 0
  139.        
  140.     else
  141.         turtle.dig()
  142.         turtle.forward()
  143.  
  144.         x = x + 1
  145.     end
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement