JaMaNi133

cotton

Nov 27th, 2022 (edited)
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.10 KB | None | 0 0
  1. local function selectItem(name)
  2.     for i = 1,16,1 do
  3.         local item = turtle.getItemDetail(i)
  4.         if item ~= nil then
  5.             if item["name"] == name then
  6.                 turtle.select(i)
  7.                 return
  8.             end
  9.         else
  10.             print("no cotton to plant")
  11.         end
  12.     end
  13. end
  14.  
  15.  
  16. local function harvest()
  17.     planted, block = turtle.inspectDown()
  18.     if planted then
  19.         if block["state"]["age"] == 3 then
  20.             turtle.digDown()
  21.             selectItem("harvestcraft:cottonitem")
  22.             turtle.placeDown()
  23.         end
  24.     else
  25.         selectItem("harvestcraft:cottonitem")
  26.         turtle.placeDown()
  27.     end
  28. end
  29.  
  30.  
  31. local function row(cols)
  32.     for x = 1,cols-1,1 do
  33.         turtle.forward()
  34.         harvest()
  35.     end
  36. end
  37.  
  38. local function harvestField(width,height)
  39.  
  40.     turtle.forward()
  41.     harvest()
  42.     for y = 1,(width/2)-1,1 do
  43.         row(height)
  44.         turtle.turnRight()
  45.         turtle.forward()
  46.         turtle.turnRight()
  47.         harvest()
  48.         row(height)
  49.         turtle.turnLeft()
  50.         turtle.forward()
  51.         turtle.turnLeft()
  52.         harvest()
  53.     end
  54.     row(height)
  55.     turtle.turnRight()
  56.     turtle.forward()
  57.     turtle.turnRight()
  58.     harvest()
  59.     row(height)
  60.  
  61.     turtle.forward()
  62.     turtle.turnRight()
  63.     for y = 1,width-1,1 do
  64.         turtle.forward()
  65.     end
  66.     --turtle.turnRight()
  67. end
  68.  
  69. local function relocate()
  70.     running = true
  71.     prevOnRail = false
  72.     while running do
  73.         onRail,railType = turtle.inspectUp()
  74.         if onRail then
  75.             if railType["name"] == "minecraft:wooden_slab" then
  76.                 if prevOnRail then
  77.                     turtle.forward()
  78.                 else
  79.                     turtle.turnRight()
  80.                 end
  81.             end
  82.             if railType["name"] == "minecraft:log" then
  83.                 turtle.turnRight()
  84.                 turtle.forward()
  85.             end
  86.             if railType["name"] == "minecraft:planks" then
  87.                 running = false
  88.             end
  89.         else
  90.             turtle.forward()
  91.         end
  92.         prevOnRail = onRail
  93.     end
  94.     running = true
  95.     while running do
  96.         turtle.turnRight()
  97.         cum,frontBlock = turtle.inspect()
  98.         if frontBlock["name"] == "minecraft:chest" then
  99.             running = false
  100.             turtle.turnRight()
  101.         end
  102.     end
  103.     turtle.turnRight()
  104. end
  105.  
  106.  
  107.  
  108. counter = 0
  109. local X,Y = ...
  110. relocate()
  111. print("ready")
  112. while true do
  113.     sleep(0.5)
  114.     --if redstone.getInput("top") then
  115.     if counter%600==0 then
  116.  
  117.         while turtle.getFuelLevel() < 400+X*(Y+1) do
  118.             turtle.select(16)
  119.             if turtle.suckDown() == false then
  120.                 print("no fuel")
  121.                 read()
  122.             end
  123.             turtle.refuel(8)
  124.             turtle.dropDown(64)
  125.         end
  126.         turtle.select(1)
  127.         harvestField(X,Y)
  128.         turtle.turnLeft()
  129.         for cum = 1,16,1 do
  130.             selectItem("harvestcraft:cottonitem")
  131.             turtle.drop(64)
  132.         end
  133.         turtle.select(1)
  134.         turtle.suck()
  135.         turtle.turnLeft()
  136.         turtle.turnLeft()
  137.     end
  138.     print(counter)
  139.     counter = counter + 1
  140. end
Add Comment
Please, Sign In to add comment