Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --vars
- local Args = {...}
- slotSeed = 1
- rowCount = 0
- colCount = 0
- isFlax = false
- turtleHigh = false
- vegs ={ ["enhancedfarming:tomato_crop"] =6, ["minecraft:carrots"] =7, ["minecraft:wheat"] =7, ["minecraft:potatoes"] =7, ["farmersdelight:cabbages"] =7, ["minecraft:beetroots"] =3, ["farmersdelight:onions"] =7, ["farmersdelight:tomatoes"] =7, ["enhancedfarming:aubergine_crop"] =6, ["enhancedfarming:corn_crop"] =7, ["enhancedfarming:lettuce_crop"] =5, ["enhancedfarming:garlic_crop"] =5, ["enhancedfarming:cucumber_crop"] =5, ["minecraft:pumpkin"] =0, ["minecraft:melon"] =0, ["supplementaries:flax"] = 7}
- seds = {["minecraft:wheat_seeds"] = true,["minecraft:pumpkin_seeds"] = true,["minecraft:melon_seeds"] = true,["minecraft:beetroot_seeds"] = true,["farmersdelight:cabbage_seeds"] = true,["farmersdelight:tomato_seeds"] = true,["enhancedfarming:mint_seeds"] = true,["enhancedfarming:tomato_seeds"] = true,["enhancedfarming:cucumber_seeds"] = true,["enhancedfarming:aubergine_seeds"] = true,["enhancedfarming:grape_seeds"] = true,["enhancedfarming:pineapple_seeds"] = true,["enhancedfarming:farm_seeds"] = true,["enhancedfarming:onion_seeds"] = true,["enhancedfarming:garlic_seeds"] = true,["enhancedfarming:lettuce_seeds"] = true,["farmersdelight:onion"] = true,["minecraft:carrot"] = true,["minecraft:potato"] = true,["enhancedfarming:corn_seeds"] = true, ["supplementaries:flax_seeds"] = true}
- function emptyToChest()
- turtle.back()
- turtle.down()
- for i = 3, 16 do -- loop through the slots
- turtle.select(i) -- change to the slot
- if turtle.refuel(0) == false then -- if it's not valid fuel
- turtle.dropDown()
- end
- end
- turtle.up()
- turtle.forward()
- end
- function isHarvestReady(itm, age)
- if age == nil then
- age = 0
- end
- print("1-Found", itm, "looking up harvest age")
- print("2-HaAge:", vegs[itm], "Age:", age)
- if vegs[itm] == age then
- print("Harvest")
- return true
- else
- print("dontHarvest")
- return false
- end
- end
- function hasTag(data, tag)
- if data.tags and data.tags[tag] then
- return true
- else
- return false
- end
- end
- function isFence(data)
- if hasTag(data, "forge:fences") or hasTag(data, "forge:fence_gates") then
- return true
- else
- return false
- end
- end
- function goUp()
- if turtleHigh == false then
- turtleHigh = true
- turtle.up()
- end
- end
- function goDown()
- if turtleHigh == true then
- turtleHigh= false
- turtle.down()
- end
- end
- function row()
- local fenceCount = 0
- rowCount=rowCount+1
- local cc = 0
- for i = 1,64 do
- cc = cc + 1
- local success, d = turtle.inspectDown()
- if success == false and isFlax == true then --air block
- goDown()
- success, d = turtle.inspectDown()
- end
- if success == true then
- local n = d.name
- local ag = d.state.age
- if isFence(d) then
- print("fence detected")
- fenceCount = fenceCount + 1
- if i > 3 then --garden must be 4 wide to prevent false positive
- break --hit fence, must be end of row
- end
- end
- if hasTag(d, "computercraft:turtle_hoe_harvestable") then
- if isHarvestReady(n, ag) then
- print("3- Harvest/Plant needed - Crop age:", ag )
- print("Using Seeds from Slot #3")
- --turtle.select(3)
- selectSeeds()
- turtle.digDown()
- if isFlax == true then
- goDown()
- end
- turtle.digDown()
- turtle.placeDown()
- end
- end
- else --success false
- print("3b -lookup failed, try planting")
- --turtle.select(3)
- selectSeeds()
- -- if isFlax then
- -- turtle.down()
- -- end
- turtle.digDown()
- turtle.placeDown()
- end
- if isFlax then
- goUp()
- end
- turtle.forward()
- checkFuel()
- if fenceCount == 3 then --three fences in a row, assume we are at the end
- resetPos()
- reset=1
- return
- end
- end
- colCount = cc
- end
- function resetPos()
- if isFlax == true then
- goDown()
- end
- print("rows:", rowCount)
- print("cols:", colCount)
- --We need to reset because we are end of farm.
- -- move back 3 - 3 fence reads
- rowCount = rowCount - 1
- print("going back")
- if rowCount % 2 == 0 then --on wrong side, we need to go back to the right side.
- turtle.back()
- turtle.back()
- turtle.back()
- turtle.back()
- turtle.turnLeft()
- for i = 1,rowCount do
- turtle.forward()
- end
- turtle.turnRight()
- print("should be home")
- --turtle.forward()
- else
- for i = 1, colCount-4 do
- turtle.forward()
- end
- turtle.turnRight()
- for i = 1,rowCount do
- turtle.forward()
- end
- turtle.turnRight()
- print("should be home")
- end
- end
- function checkFuel()
- local fuellevel = turtle.getFuelLevel()
- if fuellevel < 3 then
- print("out of fuel - Add fuel and run start")
- os.shutdown()
- end
- end
- function leftReset()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- --turtle.forward()
- checkFuel()
- end
- function rightReset()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- --turtle.forward()
- checkFuel()
- end
- function resetAE()
- turtle.turnRight()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.forward()
- end
- function refuel()
- for i = 1, 16 do -- loop through the slots
- turtle.select(i) -- change to the slot
- if turtle.refuel(0) then -- if it's valid fuel
- local halfStack = math.ceil(turtle.getItemCount(i)/2) -- work out half of the amount of fuel in the slot
- turtle.refuel(halfStack) -- consume half the stack as fuel
- end
- end
- local fuellevel = turtle.getFuelLevel()
- if fuellevel < 20 then
- rednet.broadcast(os.getComputerLabel() .. " is low on fuel!","fuelturtle")
- end
- end
- function selectSeeds()
- local ss = slotSeed
- for i = 1, 16 do
- turtle.select(ss)
- local d2 = turtle.getItemDetail(ss)
- if d2 then
- --print(d2.name)
- if seds[d2.name] then --Has seed Tag
- print("Found Seeds, slot:", ss, d2.name)
- slotSeed = ss
- return true
- end
- end
- ss = ss + 1
- if ss == 17 then
- ss = 1
- end
- end
- print("No Seeds")
- rednet.broadcast(os.getComputerLabel() .. " is out of seeds!","fuelturtle")
- return false
- end
- --Main Function
- if Args[1] == "flax" then
- isFlax = true
- end
- while true do
- rednet.broadcast(os.getComputerLabel() .. " running","fuelturtle")
- fenceCount = 0
- rowCount = 0
- colCount = 0
- reset=0
- rednet.open("right")
- for i=1,64 do
- if isFlax then
- goUp()
- end
- row()
- if reset == 1 then break end
- rightReset()
- refuel()
- if isFlax then
- goUp()
- end
- row()
- if reset == 1 then break end
- leftReset()
- refuel()
- end
- --resetAE()
- print("Empty Inv")
- emptyToChest()
- print("sleep 15 mins")
- print("Current Fuel:" ,turtle.getFuelLevel())
- refuel()
- os.sleep(900)
- end
Add Comment
Please, Sign In to add comment