Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --CCSeedBreeder by Teki
- local tArgs = { ... }
- local monitor = term.current()
- local sizeX,sizeY = monitor.getSize()
- monitor.clear()
- monitor.setCursorPos(1,1)
- local fuelChest = {1,3}
- local cropSticksChest = {1,2}
- local boneMealChest = {2,1}
- local seedsChest = {1,4}
- local trashChest = {2,4}
- local productionChest = {2,5}
- if #tArgs == 1 then
- if tArgs[1] == "del" then
- fs.delete(filePath)
- return 0
- elseif tArgs[1] == "help" then
- end
- else
- monitor.setCursorPos(1,1)
- monitor.write("A : Autonomous activator facing soil")
- monitor.setCursorPos(1,2)
- monitor.write("S : Soil (dirt must be tilled!)")
- monitor.setCursorPos(1,3)
- monitor.write("C : Computer controlled seed analyzer")
- monitor.setCursorPos(1,4)
- monitor.write("f : Fuel chest")
- monitor.setCursorPos(1,5)
- monitor.write("c : Crop sticks chest")
- monitor.setCursorPos(1,6)
- monitor.write("b : Bone meal chest")
- monitor.setCursorPos(1,7)
- monitor.write("s : Seeds chest")
- monitor.setCursorPos(1,8)
- monitor.write("t : Trash chest")
- monitor.setCursorPos(1,9)
- monitor.write("p : Production chest")
- monitor.setCursorPos(30,5)
- monitor.write(" A ")
- monitor.setCursorPos(30,6)
- monitor.write("ASSSA")
- monitor.setCursorPos(30,7)
- -- monitor.write("b Ctp")
- monitor.write(" C ")
- monitor.setCursorPos(30,8)
- -- monitor.write(" cfs ")
- monitor.write(" ")
- monitor.setCursorPos(29+fuelChest[2],9-fuelChest[1])
- monitor.write("f")
- monitor.setCursorPos(29+cropSticksChest[2],9-cropSticksChest[1])
- monitor.write("c")
- monitor.setCursorPos(29+boneMealChest[2],9-boneMealChest[1])
- monitor.write("b")
- monitor.setCursorPos(29+seedsChest[2],9-seedsChest[1])
- monitor.write("s")
- monitor.setCursorPos(29+trashChest[2],9-trashChest[1])
- monitor.write("t")
- monitor.setCursorPos(29+productionChest[2],9-productionChest[1])
- monitor.write("p")
- monitor.setCursorPos(1,10)
- monitor.write("Put the turtle on the fuel chest fuel")
- monitor.setCursorPos(1,11)
- monitor.write("seeds, crops sticks and bone meal in")
- monitor.setCursorPos(1,12)
- monitor.write("appropriate chests then start.")
- monitor.setCursorPos(1,13)
- monitor.write("Press Q to quit, S to start.")
- while true do
- local event, side, xPos, yPos = os.pullEvent()
- if event == "char" then
- if side == "Q" or side == "q" then
- return 0
- elseif side == "S" or side == "s" then
- break
- end
- end
- end
- end
- local savedValues
- local savedFile
- local filePath = "seedbreeder.save"
- local curX = fuelChest[1]
- local curY = fuelChest[2]
- local dir = 0
- local direction = nil
- local step = 0
- local seed1 = {0,0,0}
- local seed2 = {0,0,0}
- local seed3 = {0,0,0}
- local function roundTo(num, n)
- local mult = 10^(n or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- function pmsg(msg)
- monitor.setCursorPos(1,13)
- monitor.clearLine()
- monitor.write(msg)
- end
- function Save()
- savedFile = fs.open(filePath, "w")
- savedValues = {
- [1] = curX,
- [2] = curY,
- [3] = dir,
- [4] = step,
- [5] = seed1,
- [6] = seed2,
- [7] = seed3
- }
- savedFile.write(textutils.serialize(savedValues))
- savedFile.flush()
- savedFile.close()
- end
- function tForward(toX, toY)
- if dir == 0 then
- if curX < toX then
- if turtle.forward() then
- curX = curX + 1
- Save()
- elseif not turtle.detect() then
- turtle.attack()
- end
- else
- if curY < toY then
- turtle.turnRight()
- dir = 1
- Save()
- else
- turtle.turnLeft()
- dir = 3
- Save()
- end
- end
- elseif dir == 1 then
- if curY < toY then
- if turtle.forward() then
- curY = curY + 1
- Save()
- elseif not turtle.detect() then
- turtle.attack()
- end
- else
- if curX < toX then
- turtle.turnLeft()
- dir = 0
- Save()
- else
- turtle.turnRight()
- dir = 2
- Save()
- end
- end
- elseif dir == 2 then
- if curX > toX then
- if turtle.forward() then
- curX = curX - 1
- Save()
- elseif not turtle.detect() then
- turtle.attack()
- end
- else
- if curY < toY then
- turtle.turnLeft()
- dir = 1
- Save()
- else
- turtle.turnRight()
- dir = 3
- Save()
- end
- end
- elseif dir == 3 then
- if curY > toY then
- if turtle.forward() then
- curY = curY - 1
- Save()
- elseif not turtle.detect() then
- turtle.attack()
- end
- else
- if curX < toX then
- turtle.turnRight()
- dir = 0
- Save()
- else
- turtle.turnLeft()
- dir = 2
- Save()
- end
- end
- end
- end
- function goTo(toX, toY)
- toX = tonumber(toX)
- toY = tonumber(toY)
- while curX ~= toX or curY ~= toY do
- tForward(toX, toY)
- end
- end
- function activateAutonomous()
- redstone.setOutput("bottom", true)
- sleep(1)
- redstone.setOutput("bottom", false)
- end
- function findDirection()
- local ret, val = pcall(function() peripheral.call("bottom", "hasPlant", "NORTH") end)
- if ret then
- direction = "NORTH"
- end
- ret, val = pcall(function() peripheral.call("bottom", "hasPlant", "EAST") end)
- if ret then
- direction = "EAST"
- end
- ret, val = pcall(function() peripheral.call("bottom", "hasPlant", "SOUTH") end)
- if ret then
- direction = "SOUTH"
- end
- ret, val = pcall(function() peripheral.call("bottom", "hasPlant", "WEST") end)
- if ret then
- direction = "WEST"
- end
- end
- function stepLoop()
- pmsg("Fuel check ...")
- if turtle.getFuelLevel() <= 30 then
- goTo(fuelChest[1],fuelChest[2])
- while turtle.getFuelLevel() <= 26 do
- turtle.select(3)
- while turtle.suckDown(1) == false or turtle.getFuelLevel() <= 26 do
- pmsg("Waiting for fuel ...")
- sleep(1)
- end
- turtle.refuel(1)
- end
- end
- pmsg("Crop sticks check ...")
- turtle.select(1)
- if turtle.getItemCount() < 4 then
- goTo(cropSticksChest[1],cropSticksChest[2])
- while turtle.getItemCount() < 5 do
- turtle.suckDown(64 - turtle.getItemCount())
- pmsg("Waiting for crop sticks ...")
- sleep(1)
- end
- end
- pmsg("Bone Meal Check ...")
- turtle.select(2)
- if turtle.getItemCount() < 4 then
- goTo(boneMealChest[1],boneMealChest[2])
- while turtle.getItemCount() < 3 do
- turtle.suckDown(64 - turtle.getItemCount())
- pmsg("Waiting for bone meal ...")
- sleep(1)
- end
- end
- end
- function stepStart()
- step = 0
- pmsg("Step start ...")
- goTo(seedsChest[1],seedsChest[2])
- turtle.select(3)
- while turtle.suckDown(1) == false do
- pmsg("Waiting for a seed ...")
- sleep(1)
- end
- goTo(2,3)
- turtle.select(3)
- turtle.dropDown(1)
- peripheral.call("bottom", "analyze")
- while peripheral.call("bottom", "isAnalyzed") == false do
- sleep(0.05)
- end
- seed1[1],seed1[2],seed1[3] = peripheral.call("bottom", "getSpecimenStats")
- turtle.suckDown(1)
- stepA()
- goTo(seedsChest[1],seedsChest[2])
- turtle.select(3)
- while turtle.suckDown(1) == false do
- pmsg("Waiting for a seed ...")
- sleep(1)
- end
- goTo(2,3)
- turtle.dropDown(1)
- peripheral.call("bottom", "analyze")
- while peripheral.call("bottom", "isAnalyzed") == false do
- sleep(0.05)
- end
- seed3[1],seed3[2],seed3[3] = peripheral.call("bottom", "getSpecimenStats")
- turtle.suckDown(1)
- stepB()
- end
- function stepA()
- step = 1
- pmsg("Step 1 ...")
- goTo(3,2)
- turtle.select(1)
- turtle.digDown()
- turtle.placeDown(1)
- goTo(3,1)
- turtle.select(3)
- turtle.dropDown(1)
- activateAutonomous()
- turtle.select(2)
- turtle.dropDown(1)
- activateAutonomous()
- end
- function stepB()
- step = 2
- pmsg("Step 2 ...")
- goTo(3,4)
- turtle.select(1)
- turtle.digDown()
- turtle.placeDown(1)
- goTo(3,5)
- turtle.select(3)
- turtle.dropDown(1)
- activateAutonomous()
- turtle.select(2)
- turtle.dropDown(1)
- activateAutonomous()
- end
- function stepC()
- step = 3
- pmsg("Step 3 ...")
- goTo(3,3)
- turtle.select(1)
- turtle.digDown()
- goTo(4,3)
- turtle.select(1)
- turtle.dropDown(2)
- activateAutonomous()
- goTo(2,3)
- if direction == nil then
- findDirection()
- end
- while peripheral.call("bottom", "hasPlant", direction) == false do
- pmsg("Waiting for a seed to appear ... ")
- sleep(1)
- if peripheral.call("bottom", "hasPlant", direction) then break end
- end
- end
- function stepD()
- step = 4
- pmsg("Step 4 ...")
- goTo(3,3)
- turtle.select(1)
- turtle.digDown()
- -- turtle.select(3)
- -- turtle.transferTo(1,1)
- -- turtle.select(4)
- -- turtle.transferTo(3,1)
- goTo(2,3)
- turtle.select(3)
- turtle.dropDown(1)
- peripheral.call("bottom", "analyze")
- while peripheral.call("bottom", "isAnalyzed") == false do
- sleep(0.05)
- end
- seed2[1],seed2[2],seed2[3] = peripheral.call("bottom", "getSpecimenStats")
- turtle.suckDown()
- if seed2[1] + seed2[2] + seed2[3] == 30 then
- goTo(fuelChest[1],fuelChest[2])
- step = "done"
- elseif seed2[1] + seed2[2] + seed2[3] > seed1[1] + seed1[2] + seed1[3] or seed2[1] + seed2[2] + seed2[3] > seed3[1] + seed3[2] + seed3[3] then
- pmsg("Found better seed !")
- if seed1[1] + seed1[2] + seed1[3] > seed3[1] + seed3[2] + seed3[3] then
- stepB()
- seed3[1] = seed2[1]
- seed3[2] = seed2[2]
- seed3[3] = seed2[3]
- else
- stepA()
- seed1[1] = seed2[1]
- seed1[2] = seed2[2]
- seed1[3] = seed2[3]
- end
- end
- end
- function stepTrash()
- step = 5
- pmsg("Step trash ...")
- goTo(trashChest[1],trashChest[2])
- turtle.select(3)
- turtle.dropDown(1)
- turtle.select(4)
- turtle.dropDown(1)
- goTo(productionChest[1],productionChest[2])
- turtle.select(5)
- turtle.dropDown()
- end
- stepLoop()
- stepStart()
- while true do
- stepC()
- stepD()
- if step == "done" then
- break
- end
- stepTrash()
- stepLoop()
- end
- pmsg("Done !")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement