Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local croplist={"Sugarcane", "Industrial Hemp", "Wheat", "Beetroot", "Netherwart", "Carrot", "Potato", "Botania flowers"}
- local croplistTall={true, true, false, false, false, false, false, false}
- local croplistSeed={false, false, true, true, true, true, true, false}
- local croplistTimer={32, 32, 32, 32, 32, 32, 32, 32}--minutes
- ---------------------Functions-----------------------------------
- --easy move function
- local function move(steps)
- for i=1,steps do
- while not turtle.forward() do
- local success,data=turtle.inspect()
- if success and data.name=="minecraft:reeds" then
- turtle.dig()
- else
- sleep(1)
- end
- end
- end
- end
- local function unload(seeds)
- local emptyslot=0
- local maxcount=0
- for i=1,15 do
- turtle.select(i)
- itemdata=turtle.getItemDetail()
- if itemdata==nil then
- emptyslot=emptyslot+1
- else
- if itemdata.count>maxcount then
- maxcount=itemdata.count
- end
- end
- end
- if emptyslot<3 and maxcount>50 then
- for i=1,15 do
- turtle.select(i)
- turtle.dropUp()
- end
- if seeds==false then
- turtle.select(16)
- turtle.dropUp()
- end
- turtle.select(1)
- end
- end
- --Reload fuel
- local function refuel()
- while turtle.getFuelLevel() < 120 do
- for i=1,16 do
- turtle.select(i)
- itemdata=turtle.getItemDetail()
- if itemdata==nil then
- turtle.suckDown(8)
- if turtle.refuel() then
- print("Refueled to "..turtle.getFuelLevel())
- return
- end
- end
- end
- turtle.select(1)
- turtle.dropUp()
- turtle.suckDown(8)
- if turtle.refuel() then
- print("Refueled to "..turtle.getFuelLevel())
- return
- else
- print("Refuel failed, no fuel!")
- print("Add fuel and hold down X to continue")
- repeat
- event,key= os.pullEvent("key")
- sleep(0.5)
- until key==keys.x
- end
- end
- end
- --Find home location in case of server restart
- local function home()
- turtle.up()
- local homecount=0
- while homecount<9 do
- homecount=0
- for i=1,9 do
- if turtle.forward()==true then
- homecount=homecount+1
- --print("Homecounter: "..homecount)
- else
- local success,data=turtle.inspect()
- if success and data.name=="minecraft:reeds" then
- turtle.dig()
- if turtle.forward()==true then
- homecount=homecount+1
- end
- else
- break
- end
- end
- end
- turtle.turnLeft()
- end
- turtle.turnLeft()
- end
- local function harvest(tall,seed)
- local spiral={8,8,8,7,7,6,6,5,5,4,4,3,3,2,2,1}
- if tall==true then
- turtle.dig()
- end
- move(1)
- if tall==false then
- turtle.down()
- end
- for i=1,#spiral do
- --print(spiral[i])
- for j=1,spiral[i] do
- turtle.digDown()
- if tall==true then
- turtle.dig()
- end
- if tall==true and seed==true then
- turtle.down()
- turtle.select(16)
- turtle.placeDown()
- turtle.up()
- elseif seed==true then
- turtle.select(16)
- turtle.placeDown()
- end
- move(1)
- end
- turtle.turnRight()
- end
- turtle.digDown()
- if tall==false then
- turtle.up()
- end
- turtle.turnLeft()
- move(4)
- turtle.turnLeft()
- move(4)
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -----------------------------------------
- if (fs.exists("choices") == false) then --Check if this is first time run, no saved choices on file
- while true do --Asks for type of crops
- print("Please pick the intended crops:")
- for i=1, #croplist do
- print(i..". "..croplist[i])
- end
- local answer = read()
- if tonumber(answer)==nill then
- print("-Wrong answer, input not a number-")
- else
- local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
- if (0 < answerv and answerv <= #croplist) then
- pick=answerv
- --print("Crop ", croplist[answerv], " chosen")
- break
- else
- print("-Wrong answer, input does not match range of choices-")
- end
- end
- end
- tallpick=croplistTall[pick]
- seedpick=croplistSeed[pick]
- timerpick=croplistTimer[pick]
- refuel()
- --Write choices to file
- local file = fs.open("choices","w")
- file.writeLine("tallpick="..tostring(tallpick))
- file.writeLine("seedpick="..tostring(seedpick))
- file.writeLine("timerpick="..tostring(timerpick))
- file.close()
- print("-------------------------------")
- print(" / )")
- print(" ' /")
- print("---' (_____")
- print(" ((__)")
- print(" _ ((___)")
- print(" -'((__)")
- print("--.___((_)")
- print("-------------------------------")
- end
- os.loadAPI("choices") -- Reads choices from file
- local tallpick= choices.tallpick
- local seedpick= choices.seedpick
- local timerpick=choices.timerpick
- print("Finding home base")
- move(1)
- home()
- unload(seedpick)
- refuel()
- while true do
- while redstone.getInput("left") do
- print("Disabled by redstone signal (5 min)")
- sleep(300)
- end
- print("Sleeping until crop growth")
- for i=timerpick,1,-1 do
- print(i.." minute(s) to go")
- sleep(60)
- end
- harvest(tallpick,seedpick)
- unload(seedpick)
- refuel()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement