Advertisement
Andriesmenze

Rice_harvester

Nov 24th, 2020 (edited)
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.86 KB | None | 0 0
  1. errorLevelCount = 0
  2. function checkBlockDown()
  3.     succes, data = turtle.inspectDown()
  4.     if succes == true then
  5.         block = data.name
  6.         state = data.metadata
  7.         return block, state
  8.     else
  9.         return false
  10.     end
  11. end
  12. function checkBlock()
  13.     succes, data = turtle.inspect()
  14.     if succes == true then
  15.         block = data.name
  16.         return block
  17.     else
  18.         return false
  19.     end
  20. end
  21. function getItemIndex(itemName)
  22.     for slot = 1, 16, 1 do
  23.         item = turtle.getItemDetail(slot)
  24.         if item ~= nil then
  25.             if item.name == itemName then
  26.                 return slot
  27.             end
  28.         else
  29.             return false
  30.         end
  31.     end
  32. end
  33. function placeWater()
  34.     print("Placing Water")
  35.     turtle.select(getItemIndex("AWWayofTime:waterSigil"))
  36.     turtle.placeDown()
  37.     os.sleep(1)
  38.     turtle.down()
  39.     os.sleep(1)
  40.     turtle.up()
  41. end
  42. function harvestReady()
  43.     if state == 7 then
  44.         return true
  45.     else
  46.         return false
  47.     end
  48. end
  49. function fuel()
  50.     fuelLevel = turtle.getFuelLevel()
  51.     if fuelLevel < 100 then
  52.         print("Fuel Low")
  53.         print("Fuel Level : "..fuelLevel)
  54.         fuelSlot = getItemIndex("minecraft:coal")
  55.         if fuelSlot ~= false then
  56.             turtle.select(fuelSlot)
  57.             turtle.refuel()
  58.         else
  59.             print("Inventory out of Fuel")
  60.             print("Stopping in "..fuelLevel.." Moves")
  61.         end
  62.     end
  63. end
  64. function harvest()
  65.     print("Harvesting")
  66.     turtle.digDown()
  67. end
  68. function makePlantReady()
  69.     if checkBlockDown() == false then
  70.         turtle.down()
  71.         name, state = checkBlockDown()
  72.         if name == "minecraft:dirt" then
  73.             print("This block is not RiceFarm ready")
  74.             turtle.up()
  75.             return false
  76.         elseif name == "Growthcraft|Rice:grc.paddyField" and state ~= 7 then
  77.             turtle.up()
  78.             placeWater()
  79.             return true
  80.         else
  81.             turtle.up()
  82.             return true
  83.         end
  84.     end
  85. end
  86. function plant()
  87.     riceSlot = getItemIndex("Growthcraft|Rice:grc.rice")
  88.     if riceSlot ~= false then
  89.         print("Planting")
  90.         turtle.select(riceSlot)
  91.         turtle.placeDown()
  92.     else
  93.         print("Out of Rice")
  94.     end
  95. end
  96. function turnAround()
  97.     turtle.turnLeft()
  98.     os.sleep(1)
  99.     turtle.turnLeft()
  100. end
  101. function next()
  102.     frontBlock = checkBlock()
  103.     if frontBlock == "minecraft:fence" or frontBlock == "Growthcraft:grc.fenceRope" then
  104.         print("detected a fence turning around")
  105.         turnAround()
  106.         turtle.forward()
  107.     else
  108.         print("Moving forward")
  109.         if errorLevelCount >= 20 then
  110.             print("can't move forward")
  111.             return false
  112.         else
  113.             if turtle.forward() ~= true then
  114.                 print("can't move forward")
  115.                 errorLevelCount = errorLevelCount + 1
  116.             else
  117.                 errorLevelCount = 0
  118.             end
  119.         end
  120.     end
  121. end
  122. print("starting....")
  123. while true do
  124.     fuel()
  125.     if turtle.getFuelLevel() == 0 then
  126.         print("Stopping")
  127.         break
  128.     end
  129.     downBlockName, downBlockState = checkBlockDown()
  130.     if downBlockName ~= false then
  131.         if harvestReady() == false then
  132.             if next() == false then
  133.                 break
  134.             end
  135.         else
  136.             harvest()
  137.             os.sleep(1)
  138.             if makePlantReady() ~= false then
  139.                 os.sleep(1)
  140.                 plant()
  141.             end
  142.             os.sleep(1)
  143.             if next() == false then
  144.                 break
  145.             end
  146.         end
  147.     else
  148.         makePlantReady()
  149.         os.sleep(1)
  150.         plant()
  151.         os.sleep(1)
  152.         if next() == false then
  153.             print("Closing Program, can't move forward")
  154.             break
  155.         end
  156.     end
  157. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement