Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function go(character)
- if character=="f" then
- turtle.forward()
- elseif character=="b" then
- turtle.back()
- elseif character=="u" then
- turtle.up()
- elseif character=="d" then
- turtle.down()
- elseif character=="r" then
- turtle.turnRight()
- elseif character=="l" then
- turtle.turnLeft()
- end
- end
- function followList(list, inverse)
- --list is a string
- opposites={f="b",b="f",u="d",d="u",l="r",r="l"}
- if inverse then
- list=string.reverse(list)
- end
- for i=1,string.len(list) do
- local c=list:sub(i,i)
- if inverse then
- c=opposites[c]
- end
- go(c)
- end
- end
- function checkmeal()
- local meal
- meal=turtle.getItemCount(16)
- if meal >= 4 then
- return true
- else
- return false
- end
- end
- function meal()
- turtle.select(16)
- turtle.placeDown()
- turtle.placeDown()
- turtle.placeDown()
- turtle.placeDown()
- turtle.select(1)
- end
- function findPlantDirection(SeedAnalyzer)
- --only call this function if there is a plant or double crop next to the sa, otherwise there will be problems
- local function raiseErrorIfNoCrop(Cardinal,saParam)
- saParam.hasPlant(Cardinal)
- end
- local listAllDir={"NORTH","EAST","SOUTH","WEST"}
- for key,value in pairs(listAllDir) do
- if pcall(raiseErrorIfNoCrop,value,SeedAnalyzer) then
- return value
- end
- end
- end
- function getWaitTime(percent)
- percent=math.floor(percent)
- local growthStage={}
- growthStage[0]=0
- growthStage[14]=1
- growthStage[28]=2
- growthStage[42]=3
- growthStage[57]=4
- growthStage[71]=5
- growthStage[85]=6
- growthStage[100]=7
- local wTime={[0]=120,[1]=120,[2]=120,[3]=120,[4]=60,[5]=20,[6]=10,[7]=0}
- return wTime[growthStage[percent]]
- end
- function waitForGrowth(SeedAnalyzer)
- local direction=findPlantDirection(SeedAnalyzer)
- local percent
- local t
- while true do
- percent=SeedAnalyzer.getGrowthStage(direction)
- if percent==100 then
- break
- end
- t=getWaitTime(percent)
- os.sleep(t)
- end
- end
- function waitForPlant(SeedAnalyzer)
- local direction=findPlantDirection(SeedAnalyzer)
- while true do
- if SeedAnalyzer.hasPlant(direction) then
- break
- end
- os.sleep(15)
- end
- end
- function updatePeripheral()
- followList("ud")
- end
- function plant()
- turtle.select(2)
- redstone.setOutput("front",true)
- turtle.drop(1)
- os.sleep(1.5)
- redstone.setOutput("front",false)
- turtle.select(1)
- if checkmeal() then
- followList("ruuflf")
- meal()
- --go to sa1
- followList("bd")
- else
- --go to sa1
- followList("rufl")
- end
- end
- --bind the sa peripheral between plant and clone funcs
- function clone(sa)
- waitForGrowth(sa)
- --go to sa2
- followList("rfl")
- updatePeripheral()
- waitForPlant(sa)
- if checkmeal() then
- followList("uf")
- meal()
- followList("uf",true)
- end
- waitForGrowth(sa)
- --go to sa3
- followList("ffflfr")
- updatePeripheral()
- waitForPlant(sa)
- if checkmeal() then
- followList("ub")
- meal()
- followList("ub",true)
- end
- waitForGrowth(sa)
- end
- function breakParent()
- --go to parent
- followList("bb")
- --break plant
- turtle.digDown()
- end
- function switchCrops()
- --go to piston
- followList("blfrdd")
- --pulse redstone
- redstone.setOutput("back",true)
- os.sleep(2)
- redstone.setOutput("back",false)
- end
- function mutate(sa)
- --go to sa1
- followList("uurfl")
- waitForPlant(sa)
- --go to sa4
- followList("rflfff")
- waitForPlant(sa)
- end
- function breakEachPlant()
- --this function also places the crop stick for the next cycle
- go("b")
- turtle.digDown()
- followList("lf")
- turtle.digDown()
- followList("lf")
- turtle.digDown()
- --place crop
- turtle.placeDown()
- followList("lf")
- turtle.digDown()
- followList("lf")
- end
- function getSeedStats(sa)
- turtle.dropDown()
- sa.analyze()
- os.sleep(3.5)
- local stats={sa.getSpecimenStats()}
- turtle.suckDown()
- return stats
- end
- function checkSlot(t,slotNumber)
- if turtle.getItemCount(slotNumber)>=1 then
- table.insert(t,slotNumber)
- end
- end
- function bestSeedSlotNumber(seedProfiles)
- local mGrowth=-1
- local mGain=-1
- local mStrength=-1
- local slotNumber=0
- for k,v in pairs(seedProfiles) do
- if v[1]>mGrowth then
- mGrowth=v[1]
- end
- end
- for k,v in pairs(seedProfiles) do
- if v[1]==mGrowth and v[2]>mGain then
- mGain=v[2]
- end
- end
- for k,v in pairs(seedProfiles) do
- if v[1]==mGrowth and v[2]==mGain and v[3]>mStrength then
- mStrength=v[3]
- end
- end
- for k,v in pairs(seedProfiles) do
- if v[1]==mGrowth and v[2]==mGain and v[3]==mStrength then
- slotNumber=v.slot
- break
- end
- end
- return slotNumber
- end
- function manageInventory(sa)
- --info
- local sticksToDrop=turtle.getItemCount(1)-59
- local fiberToDrop=turtle.getItemCount(3)-52
- local seedSlots={}
- checkSlot(seedSlots,2)
- checkSlot(seedSlots,4)
- checkSlot(seedSlots,5)
- checkSlot(seedSlots,6)
- local isMaxed=false
- --analyze
- go("f")
- local seedProfiles={}
- for key,value in pairs(seedSlots) do
- turtle.select(value)
- local stats=getSeedStats(sa)
- stats.slot=value
- table.insert(seedProfiles,stats)
- end
- --choose
- local bestSlot=bestSeedSlotNumber(seedProfiles)
- --check if the seed is maxed
- for k,v in pairs(seedProfiles) do
- if v.slot==bestSlot then
- if v[1]==10 and v[2]==10 and v[3]==10 then
- isMaxed=true
- break
- end
- end
- end
- --delete
- followList("bbblffd")--go to trash can
- if sticksToDrop>=1 then
- turtle.select(1)
- turtle.drop(sticksToDrop)
- end
- if fiberToDrop>=1 then
- turtle.select(3)
- turtle.drop(fiberToDrop)
- end
- --drop bad seeds
- for k,v in pairs(seedSlots) do
- if v~=bestSlot then
- turtle.select(v)
- turtle.drop()
- end
- end
- --leave a single seed remaining
- if turtle.getItemCount(bestSlot)>1 then
- turtle.select(bestSlot)
- local numberOfBestSeedsToDrop=turtle.getItemCount(bestSlot)-1
- turtle.drop(numberOfBestSeedsToDrop)
- end
- --cleanup
- --move best seed to slot 2
- if bestSlot~=2 then
- turtle.select(bestSlot)
- turtle.transferTo(2)
- end
- --select default slot
- turtle.select(1)
- --face the aa
- go("r")
- return isMaxed
- end
- function maximizeSeed()
- --preqs are that the structure is built, there is a crop in 1, crosscrops in clone spots, crops in slot 1 but not more than 59, any seed in slot 2
- --bone meal goes in slot 16 which is bottom right corner
- local isMaxed=false
- while not isMaxed do
- plant()
- local sa=peripheral.wrap("bottom")
- clone(sa)
- breakParent()
- switchCrops()
- mutate(sa)
- breakEachPlant()
- isMaxed=manageInventory(sa)
- end
- end
- --main
- maximizeSeed()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement