gridcaster

farmbot

Jun 2nd, 2021 (edited)
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.64 KB | None | 0 0
  1. -- [[ Defaults ]] --
  2. width=9
  3. length=9
  4. channel=-1
  5. plant="true"
  6. fuelId="minecraft:coal"
  7. sleepTime=120
  8. borderSlot=14
  9. seedSlot=15
  10. fuelSlot=16
  11. -- [[ END Defaults ]] --
  12.  
  13. -- [[ Variables ]] --
  14. offsetX=0
  15. offsetZ=1
  16. chest= "minecraft:chest"
  17. -- [[ END Variables ]] --
  18.  
  19. local function checkBlock(compareFrom, compareTo)
  20.     if (compareFrom == compareTo) then
  21.         return true
  22.     end
  23. end
  24.  
  25. --print(detectChest("up")) -- Test function
  26. function detectChest(direction)
  27.     local found=false
  28.     if (direction == "up") then
  29.         blockDetected,blockDetails = turtle.inspectUp()
  30.     elseif (direction == "front") then
  31.         blockDetected,blockDetails = turtle.inspect()
  32.     elseif (direction == "down") then
  33.         blockDetected,blockDetails = turtle.inspectDown()
  34.     end
  35.     if (blockDetected) then
  36.         name=blockDetails['name']
  37.         if (name == chest) then
  38.             return true
  39.         end
  40.     end
  41.     return false
  42. end
  43.  
  44.  
  45.  
  46. local function harvestCrop()
  47.     blockDetected,blockDetails = turtle.inspectDown()
  48.     --print(blockDetected)
  49.     if (blockDetected) then
  50.         blockName=blockDetails['name']
  51.         --print(blockName)
  52.         if(blockName=='minecraft:wheat' or blockName=='minecraft:carrot' or blockName=='minecraft:potato') then
  53.             blockAge=blockDetails['state']['age']
  54.             if( blockAge == 7) then
  55.                 turtle.digDown()
  56.             end
  57.         end
  58.     end        
  59. end
  60.  
  61.  
  62.  
  63.  
  64. local function loadFuel ()
  65.     if (detectFuelChest()) then
  66.         currentFuel=turtle.getFuelLevel()
  67.         maxFuel=turtle.getFuelLimit()
  68.         fuelPercent=(math.floor((currentFuel/maxFuel)*100))
  69.         if (int(fuelPercent) < 10 ) then
  70.             if(turtle.suckUp()) then
  71.             end    
  72.         end
  73.     end
  74. end
  75.  
  76. local function checkSide(direction)
  77. end
  78.  
  79. function saveTable(table,name)
  80.     local file = fs.open(name,"w")
  81.     file.write(textutils.serialize(table))
  82.     file.close()
  83. end
  84.  
  85. function countBorderSlot()
  86.  
  87. end
  88.  
  89. local function main()
  90.     while true do
  91.     -- Start
  92.     -- Check Setup
  93.         -- Check for Chest Above to Refuel
  94.         if(detectChest("up") ~= true) then
  95.             print("Fuel Chest Not Found.")
  96.             print("Please place a chest above the bot.")
  97.             break
  98.         end
  99.         -- Check for Chest In Front to Get Seed
  100.         if(detectChest("front") ~= true) then
  101.             print("Seed Chest Not Found.")
  102.             print("Please place a chest in front the bot (outside the farm area).")
  103.             break
  104.         end
  105.         -- Check for Chest Below for materials
  106.         if(detectChest("up") ~= true) then
  107.             print("Harvest Chest Not Found.")
  108.             print("Please place a chest below the bot.")
  109.             break
  110.         end
  111.         -- Check for Item in Border Slot
  112.         if (turtle.getItemCount(borderSlot) == 0) then
  113.             print("Please place 1 border item in slot " .. tostring(borderSlot))
  114.             break
  115.          elseif (turtle.getItemCount(borderSlot) > 1) then
  116.              print("Please only place 1 border item in slot " .. tostring(borderSlot))
  117.              break
  118.          end
  119.     -- Check fuel level and refuel
  120.     -- Check seed level and reload
  121.     -- Check slots 1 to 13
  122.         -- If not seed, put in chest below
  123.         -- if seed, put in front chest
  124.     -- Sleep for a sleepTime
  125.     print("Sleeping for " .. tostring(sleepTime) .. " seconds.")
  126.     sleep(sleepTime)
  127.     print("Starting...")
  128.     print("Finished...")
  129.     -- Turn right
  130.     -- Turn right
  131.     -- until border
  132.         -- go forward
  133.         -- increment x
  134.     -- then turn right, go forward, turn right
  135.     -- repeat until border
  136.     -- go home
  137.     end
  138. end
  139.  
  140. main()
Add Comment
Please, Sign In to add comment