Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Configuration
- local saplingSlot = 1
- local fuelSlot = 2 -- (use stick)
- local woodSlot = 3
- local farmlenght = 10 -- must be even
- local farmwidth = 10
- local fuelScannedItem = ""
- local woodScannedItem = ""
- local sapplingScannedItem = ""
- local function findItem(itemName)
- for slot = 1, 16 do
- local itemDetail = turtle.getItemDetail(slot)
- if itemDetail and itemDetail.name == itemName then
- return slot
- end
- end
- return -1
- end
- -- Function to refuel the turtle
- local function refuel()
- if turtle.getFuelLevel() == "unlimited" or turtle.getFuelLevel() > 100 then
- return
- end
- repeat
- local slotNumber = findItem(fuelScannedItem)
- if slotNumber ~= -1 then
- turtle.select(slotNumber)
- if turtle.refuel(0) then
- turtle.refuel(1)
- else
- print("the sample provided is not fuel")
- end
- else
- print("no fuel")
- print("insert required fuel then press any key to start...")
- os.pullEvent("key")
- end
- until slotNumber ~= -1
- end
- -- Function to check if the block in front is wood
- local function isWoodAhead()
- local success, data = turtle.inspect()
- if success then
- -- Check if the block in front matches the wood slot item
- if data.name == woodScannedItem then
- return true
- end
- end
- return false
- end
- -- Function to check if the block on top is wood
- local function isWoodUp()
- local success, data = turtle.inspectUp()
- if success then
- -- Check if the block in front matches the wood slot item
- if data.name == woodScannedItem then
- return true
- end
- end
- return false
- end
- -- Function to go up until there is no more wood
- local function goUpUntilNoWood()
- while isWoodUp() do
- turtle.digUp()
- turtle.up()
- refuel()
- end
- while not turtle.detectDown() do
- turtle.down()
- end
- turtle.digDown()
- end
- -- Function to plant sapling
- local function plantSapling()
- local slotNumber = findItem(sapplingScannedItem)
- if slotNumber ~= -1 then
- turtle.select(slotNumber)
- turtle.placeDown()
- else
- print("no sappling, skipping")
- end
- end
- -- Function to unload inventory
- local function unloadInventory()
- for i = 4, 16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- -- Function to ensure the path is clear of wood or leaves
- local function clearpath()
- if isWoodAhead() then
- turtle.dig()
- turtle.forward()
- goUpUntilNoWood()
- plantSapling()
- else
- turtle.dig()
- turtle.forward()
- end
- turtle.suckDown()
- end
- -- Main function
- local function main()
- print("Slot | 1 | 2 | 3 | 4 |")
- print("Content | Sapling sample | Fuel sample | Wood sample | Fuel |")
- print("Press any key to start...")
- os.pullEvent("key")
- fuelScannedItem = turtle.getItemDetail(fuelSlot).name
- woodScannedItem = turtle.getItemDetail(woodSlot).name
- sapplingScannedItem = turtle.getItemDetail(saplingSlot).name
- print("fuel : "..fuelScannedItem)
- print("wood : "..woodScannedItem)
- print("sappling : "..sapplingScannedItem)
- print("Running")
- while true do
- -- Start zigzag pattern
- for i = 1, (farmlenght) do
- for j = 1, (farmwidth-1) do
- refuel()
- clearpath()
- end
- -- Turn at end of row
- if i < farmlenght then
- if i % 2 == 1 then
- turtle.turnRight()
- clearpath()
- turtle.turnRight()
- else
- turtle.turnLeft()
- clearpath()
- turtle.turnLeft()
- end
- end
- end
- -- Return to start
- turtle.turnRight()
- for i = 1, (farmlenght-1) do
- clearpath()
- end
- -- Unload inventory
- unloadInventory() -- face the hopper
- turtle.turnRight()
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement