Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- can only harvest wheat.
- -- will automatically turn dirt into farmland.
- -- farm size has to be 8x8, no water in this area.
- -- place turtle on the left side of an edge, one block above ground.
- -- place a chest under the turtle, it will fill it.
- -- place seeds in the four top slots. in every slot should be at least one seed to prevent bugs.
- -- place fuel in the botton right slot.
- seedsSlots = {1, 2, 3, 4}
- harvestSlots = {5, 6, 7, 8, 9, 10, 11, 12}
- fuelSlot = 16
- wheat = {name = 'minecraft:wheat', metadata = 7}
- function findSlotWithSpace()
- for i = 1, #harvestSlots do
- turtle.select(harvestSlots[i])
- if turtle.getItemSpace() > 0 then
- return true
- end
- end
- return false
- end
- function findSlotWithSeeds()
- for i = 1, #seedsSlots do
- turtle.select(seedsSlots[i])
- if turtle.getItemCount() > 0 then
- turtle.placeDown()
- return true
- end
- end
- return false
- end
- function searchForHarvestedSeeds()
- for i = 1, #harvestSlots do
- turtle.select(harvestSlots[i])
- local item = turtle.getItemDetail()
- if item ~= nil and item.name == "minecraft:wheat_seeds" then
- for i = 1, #seedsSlots do
- turtle.transferTo(seedsSlots[i])
- end
- end
- end
- end
- function harvestAndPlant()
- local success,data = turtle.inspectDown()
- if success == false then -- nothing found
- turtle.digDown() -- changes grass to farmland
- else
- if data.name ~= wheat.name or data.metadata ~= wheat.metadata then
- return
- end
- findSlotWithSpace()
- turtle.digDown()
- end
- if not findSlotWithSeeds() then
- searchForHarvestedSeeds()
- findSlotWithSeeds()
- end
- turtle.placeDown()
- end
- function forwardAndHarvest(n)
- for i = 1, n do
- turtle.forward()
- harvestAndPlant()
- end
- end
- function tillEightByEight()
- -- line 1 and turn
- forwardAndHarvest(8)
- turtle.turnRight()
- forwardAndHarvest(1)
- turtle.turnRight()
- -- line 2 and turn
- forwardAndHarvest(7)
- turtle.turnLeft()
- forwardAndHarvest(1)
- turtle.turnLeft()
- -- line 3 and turn
- forwardAndHarvest(7)
- turtle.turnRight()
- forwardAndHarvest(1)
- turtle.turnRight()
- -- line 4 and turn
- forwardAndHarvest(7)
- turtle.turnLeft()
- forwardAndHarvest(1)
- turtle.turnLeft()
- -- line 5 and turn
- forwardAndHarvest(7)
- turtle.turnRight()
- forwardAndHarvest(1)
- turtle.turnRight()
- -- line 6 and turn
- forwardAndHarvest(7)
- turtle.turnLeft()
- forwardAndHarvest(1)
- turtle.turnLeft()
- -- line 7 and turn
- forwardAndHarvest(7)
- turtle.turnRight()
- forwardAndHarvest(1)
- turtle.turnRight()
- -- line 8
- forwardAndHarvest(7)
- -- move to chest
- turtle.turnRight()
- for i = 1, 7 do
- turtle.forward()
- end
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function unload()
- local seeds = 0
- local wheat = 0
- for i = 1, #harvestSlots do
- turtle.select(harvestSlots[i])
- local item = turtle.getItemDetail()
- if item ~= nil then
- if item.name == "minecraft:wheat_seeds" then
- seeds = seeds + getItemCount()
- elseif item.name == "minecraft:wheat" then
- wheat = wheat + getItemCount()
- else
- print(item.name)
- end
- turtle.dropDown()
- end
- end
- print(seeds.." seeds harvested")
- print(wheat.." wheat harvested")
- end
- function refuel()
- if turtle.getFuelLevel() < turtle.getFuelLimit() then
- turtle.select(fuelSlot)
- turtle.refuel()
- end
- end
- 'minecraft:wheat'
- if item ~= nil and item.name == "minecraft:wheat_seeds" then
- -- main program
- function main()
- refuel()
- local fuelBegin = turtle.getFuelLevel()
- if fuelBegin < 200 then
- print("Not enough fuel left.")
- return
- end
- tillEightByEight()
- searchForHarvestedSeeds()
- unload()
- local fuelEnd = turtle.getFuelLevel()
- print("fuel consumed: "..(fuelBegin - fuelEnd))
- os.sleep(1)
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement