Advertisement
hashtagPinoy

CC:T Plant Harvester

Sep 25th, 2021 (edited)
1,774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.15 KB | None | 0 0
  1. --Have wireless turtle display previous harvest amount on an external monitor?
  2. --Also have it display ALL amount harvested
  3.  
  4.  cropName = ""
  5.  seedName = ""
  6.  
  7.  
  8. --[[if (#arg == 1) then
  9.  
  10.     if arg[1] == "crop" or arg[1] == "help" then
  11.         --print hardcoded supported crops
  12.         print("Supported crops:")
  13.         print("Wheat")
  14.         print("Potato")
  15.         print("Carrot")
  16.     else
  17.         print("Please try again using the 'crop' or 'help' arguments")
  18.     end
  19.  
  20.     cropName = tostring(arg[1])
  21.  
  22.     --Optimize at a later date
  23.     if(cropName == "wheat") then
  24.         cropName = "minecraft:wheat"
  25.  
  26.     elseif(cropName == "potato")then
  27.         cropName = "minecraft:potato"
  28.         seedName = "minecraft:potato"
  29.     elseif (cropName == "carrot") then
  30.         cropName = "minecraft:carrot"
  31.         seedName = "minecraft:carrot"
  32.     else
  33.         cropName = "minecraft:wheat"
  34.         seedName = "mineacraft:wheat_seeds"
  35.         print("Sorry! That's not a supported crop!")
  36.     end
  37.  
  38. else
  39.     print("Type 'crops' or 'help' to get started!")
  40. end]]
  41.  
  42.  
  43. function getSeedIndex(seedName)
  44.     for slot = 1, 16, 1 do
  45.         local item = turtle.getItemDetail(slot)
  46.         if(item ~= nil) then
  47.             if(item["name"] == seedName) then
  48.                 return slot
  49.             end
  50.         end
  51.     end
  52. end
  53.  
  54. function getCropIndex(cropName)
  55.     for slot = 1, 16, 1 do
  56.         local item = turtle.getItemDetail(slot)
  57.         if(item ~= nil) then
  58.             if(item["name"] == cropName) then
  59.                 return slot
  60.             end
  61.         end
  62.     end
  63. end
  64.  
  65.  
  66. --ONLY CALL WHEN TURTLE IS AT FULL STOP AND WAITING TO GO
  67. function startSequence()
  68.     turtle.select(1)
  69.  
  70.     turtle.suckUp(2)
  71.     turtle.refuel()
  72.     turtle.refuel()
  73.  
  74.     --drop only crops
  75.     for i = 1, 16 do
  76.         turtle.select(i)
  77.         local item = turtle.getItemDetail(slot)
  78.         if(item ~= nil) then
  79.             if(item["name"] == cropName) then
  80.                 turtle.dropDown()
  81.             end
  82.         end
  83.     end
  84.  
  85. end
  86.  
  87.  
  88. --For the future: Have specific conditionals for "seedless" crops
  89. function plantHarvest()
  90.     isBlock, data = turtle.inspect()
  91.  
  92.     if(isBlock)
  93.     then
  94.         if(data['state']['age'] == 7) then
  95.             seedIndex = getSeedIndex("minecraft:wheat_seeds")
  96.             turtle.select(seedIndex)
  97.             turtle.dig()
  98.             turtle.place()
  99.             turtle.suck()
  100.  
  101.         end
  102.     else
  103.         seedIndex = getSeedIndex("minecraft:wheat_seeds")
  104.         turtle.suck()
  105.         turtle.select(seedIndex)
  106.         turtle.place()
  107.     end
  108. end
  109.  
  110. leftCounter = 0
  111. function countLeftTurns()
  112.     if turtle.forward() == false then
  113.         turtle.turnLeft()
  114.         leftCounter = leftCounter + 1
  115.  
  116.     end
  117. end
  118.  
  119.  
  120.     a=1
  121.     while(a~=0) do
  122.         startSequence()
  123.         turtle.turnLeft()
  124.         plantHarvest()
  125.         turtle.turnRight()
  126.         countLeftTurns()
  127.         print(leftCounter)
  128.         if(leftCounter / 4 == 1) then
  129.             leftCounter = 0
  130.             sleep(600)
  131.             for p = 1, 16, 1 do
  132.                 turtle.select(p)
  133.                 turtle.dropDown()
  134.             end
  135.         end
  136.     end
  137.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement