Pixxel124

CC farming

Mar 11th, 2023 (edited)
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.45 KB | None | 0 0
  1. fuelForCoal = 80
  2. storageName = "storagedrawers:basicdrawers"
  3. maxCoalLevel = 20
  4. maxFuelLevel = 300
  5. pickupSlot = 1
  6. seedSlots = { 3, 4, 5 }
  7. harvestSlots = { 6, 7, 8, 9, 10, 11, 12 }
  8. coalSlot = 16
  9. startingFuel = 0;
  10.  
  11. turnLeft = turtle.turnLeft
  12. turnRight = turtle.turnRight
  13. getFuel = turtle.getFuelLevel
  14. digDown = turtle.digDown
  15. inspect = turtle.inspect
  16. inspectDown = turtle.inspectDown
  17. count = turtle.getItemCount
  18. move = turtle.forward
  19.  
  20. function select(x)
  21.     turtle.select(x)
  22. end
  23.  
  24. function transfer(x)
  25.     turtle.transferTo(x)
  26. end
  27.  
  28. function getCoal()
  29.     select(coalSlot)
  30.     local neededCoal = turtle.getItemSpace()
  31.     turtle.suck(neededCoal)
  32. end
  33.  
  34. function refuel()
  35.     getCoal()
  36.     local fuelLevel = getFuel()
  37.  
  38.     if fuelLevel >= maxFuelLevel then
  39.         print("fuel is full")
  40.         return true
  41.     end
  42.  
  43.     local success, data = inspect();
  44.  
  45.     if not success then
  46.         print("inspect not successful")
  47.         return false
  48.     end
  49.  
  50.     if data.name ~= storageName then
  51.         print("not a drawer")
  52.         return false
  53.     end
  54.  
  55.     select(coalSlot)
  56.     while fuelLevel < maxFuelLevel do
  57.         turtle.refuel(1)
  58.         fuelLevel = getFuel()
  59.     end
  60.  
  61.     startingFuel = fuelLevel
  62.  
  63.     return true
  64. end
  65.  
  66. function transferSeeds()
  67.     select(1)
  68.     local seedSlot = seedSlots[1]
  69.  
  70.     for i, v in ipairs(seedSlots) do
  71.         select(v)
  72.         local seedCount = count()
  73.         if seedCount < 64 then
  74.             seedSlot = v
  75.             break
  76.         end
  77.     end
  78.  
  79.     select(1)
  80.     transfer(seedSlot)
  81.     select(seedSlot)
  82. end
  83.  
  84. function transferHarvest()
  85.     select(2)
  86.     local harvestSlot = harvestSlots[1]
  87.  
  88.     for i, v in ipairs(harvestSlots) do
  89.         select(v)
  90.         local harvestCount = count()
  91.         if harvestCount < 64 then
  92.             harvestSlot = v
  93.             break
  94.         end
  95.     end
  96.  
  97.     select(2)
  98.     transfer(harvestSlot)
  99. end
  100.  
  101. function plantSeed()
  102.     for i, v in ipairs(seedSlots) do
  103.         select(v)
  104.         if count() > 0 then
  105.             turtle.placeDown()
  106.             return
  107.         end
  108.     end
  109. end
  110.  
  111. function harvestCrop()
  112.     local success, data = inspectDown();
  113.     if not success then
  114.         return
  115.     end
  116.  
  117.     local age = data.state.age
  118.     if age ~= 7 then
  119.         return
  120.     end
  121.  
  122.     select(1)
  123.     digDown()
  124.  
  125.     transferSeeds()
  126.     plantSeed()
  127.     transferHarvest()
  128. end
  129.  
  130. function dropOff(slots)
  131.     for i, v in ipairs(slots) do
  132.         select(v)
  133.         if count() > 0 then
  134.             turtle.drop()
  135.         end
  136.     end
  137. end
  138.  
  139. function harvestField()
  140.     refuel()
  141.     turnLeft()
  142.  
  143.     for i = 1, 4 do
  144.         for i = 1, 8 do
  145.             harvestCrop()
  146.             move()
  147.         end
  148.  
  149.         turnLeft()
  150.         harvestCrop()
  151.         move()
  152.         turnLeft()
  153.  
  154.         for i = 1, 8 do
  155.             harvestCrop()
  156.             move()
  157.         end
  158.  
  159.         turnRight()
  160.         harvestCrop()
  161.         move()
  162.         turnRight()
  163.     end
  164.  
  165.     for i = 1, 8 do
  166.         harvestCrop()
  167.         move()
  168.     end
  169.     harvestCrop()
  170.  
  171.     turnRight()
  172.  
  173.     for i = 1, 8 do
  174.         move()
  175.     end
  176.  
  177.     turnRight()
  178.  
  179.     for i = 1, 6 do
  180.         move()
  181.     end
  182.  
  183.     turnLeft()
  184.     dropOff(seedSlots)
  185.  
  186.     turnRight()
  187.     move()
  188.     turnLeft()
  189.     dropOff(harvestSlots)
  190.  
  191.     turnRight()
  192.     move()
  193.     turnLeft()
  194.  
  195.     local fuelUsed = startingFuel - turtle.getFuelLevel()
  196.     print("fuel used: " .. fuelUsed)
  197. end
  198.  
  199. harvestField()
Add Comment
Please, Sign In to add comment