Advertisement
Harlaquin

potato

Jun 27th, 2024
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1. --  Potato Farm Code
  2. --  
  3.  
  4. southwest = {187, 66, 267}
  5. sourtheast = {195, 66, 267}
  6. northwest = {187, 66, 259}
  7. northeast = {195, 66, 259}
  8.  
  9. fuelChest = {194, 66, 268}
  10. storageChest = {188, 66, 268}
  11. slotCount = 16
  12.  
  13. --  Returns for 'itemName' slot in inventory
  14. function getItemIndex(itemName)
  15.     for slot = 1, 16, 1 do
  16.         item = turtle.getItemDetail(slot)
  17.         if(item ~= nil) then
  18.             if(item["name"] == itemName) then
  19.                 return slot
  20.             end
  21.         end
  22.     end
  23. end
  24.  
  25.  
  26. function checkFuel()
  27.     turtle.select(1)
  28.  
  29.     if(turtle.getFuelLevel() < 50) then
  30.         print("Attempting Refuel...")
  31.         for slot = 1, slotCount, 1 do
  32.             turtle.select(slot)
  33.             if(turtle.refuel(1)) then
  34.                 return true
  35.             end
  36.         end
  37.  
  38.         return false
  39.     else
  40.         return true
  41.     end
  42. end
  43.  
  44.  
  45. function getFuel()
  46.    
  47. end
  48.  
  49.  
  50. -- returns turtle distance compared to target location and counts fuel cost
  51. function getDistance(currX, currY, currZ)
  52.     cordX, cordY, cordZ = gps.locate()
  53.     fuelCost = turtle.getFuelLevel()
  54.     --effeicency variable -checks if travel is possible !!change later after troubleshooting
  55.     efficiency = true
  56.  
  57.     compX = currX -
  58.  
  59.     compared_set = {}
  60.  
  61.     return distance, efficency
  62. end
  63.  
  64.  
  65.  
  66. --  actual command to move to a given destination
  67. function moveTo(x, y, z)
  68.     destination = {x, y, z}
  69.  
  70.     if destination~=gps.locate()
  71.     then
  72.         --  moveing to location based on
  73.     end
  74. end
  75.  
  76.  
  77. --  main fuction to have a never ending farm
  78. --  !!northeast is a place holder for the last block in the calculated inputs
  79. --  !! make sure code can move side to side in a 8x8 grid repeating the dig/plant action
  80. --  !! has to stay inside placed location
  81. while(1) do
  82.  
  83.     -- checks turtle for fuel
  84.     if checkFuel()then
  85.  
  86.         startCord = gps.locate()
  87.         fuelstat = turtle.getFuelLevel()
  88.         distan, efficiency_value = getDistance()
  89.  
  90.         --checks if given inputs are possible
  91.         if(efficiency_value) then
  92.  
  93.             isBlock, data = turtle.inspectDown()
  94.             if(isBlock) then
  95.                 if (data['state']['age'] <= 7)
  96.                 then
  97.                     turtle.digDown()
  98.                     potatoIndex = getItemIndex("minecraft:potato")
  99.                     turtle.select(potatoIndex)
  100.                     turtle.placeDown()
  101.                 end
  102.                 else
  103.                     potatoIndex = getItemIndex("minecraft:potato")
  104.                     turtle.placeDown()
  105.                 end    
  106.            
  107.         end
  108.  
  109.     --  If turtle doesnt have fuel then it moves to chest, refuels, returns, then starts program from the top
  110.     else
  111.  
  112.         startCord = gps.locate()
  113.         moveTo(fuelChest)
  114.         turtle.refuel()
  115.         if turtle.checkFuel() then
  116.             moveTo(startCord)
  117.         end
  118.     end
  119. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement