Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --smart adaptive wood farming turtle by Ardevlirn
- --Instruction:
- --Create a path using the block you will place in slot 13
- --place dirt around the path (only at the same Y pos than the path)
- --place turtle on the path
- --place a chest next to the turtle and the path
- ----------------------------------
- --put 1 chest in slot 16,
- --at least 3 sappling in slot 15
- --1 wood in slot 14,
- --the block used for the path in slot 13
- --fuel in slot 12, if fuel is disabled no need to put some
- --those next variable can be changed
- --(will say when no more variable can be changed):
- --Will try to refuel when Fuel Level is under this amount :
- local minFuelForRefuel = 800
- --Will search the chest if there is less than this amount of fuel item in inventory:
- local minFuelInInventory = 12
- --If set to true will search the chest when under this amount of sappling left in inventory :
- local goSearchSapling = false
- local minSaplingInInventory = 3
- --PS: While searching for the chest the turtle will no longer place saplingID
- --and will not cut tree down
- ----------------------------------
- --those variable define in which slot each item must be placed
- local chestSlot = 16
- local saplingSlot = 15
- local woodSlot = 14
- local pathSlot = 13
- local fuelSlot = 12
- --no more variable to change
- -------------------------------------------------------------
- local function Energy()
- turtle.select(fuelSlot)
- if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < minFuelForRefuel then
- local charbonNumb = turtle.getItemCount()
- if charbonNumb > 12 then
- turtle.refuel(10)
- else
- turtle.refuel(charbonNumb-2)
- end
- end
- end
- local function chemin()
- turtle.select(pathSlot)
- return turtle.compareDown()
- end
- local function testbois()
- turtle.select(woodSlot)
- return turtle.compare()
- end
- local function testpousse()
- turtle.select(saplingSlot)
- return turtle.compare()
- end
- local function testcoffre()
- turtle.select(chestSlot)
- return turtle.compare()
- end
- local function plante()
- turtle.select(saplingSlot)
- if turtle.getItemCount(saplingSlot) > 2 then
- turtle.place()
- end
- end
- local function detectCoupe()
- local _, blockUp = turtle.inspectUp()
- if blockUp.name == "minecraft:log" or blockUp.name == "minecraft:leaves" then
- return true
- else
- return false
- end
- end
- local function preventStuck()
- local success,data = turtle.inspectDown()
- if data.name == "minecraft:log" or data.name == "minecraft:leaves" then
- return true
- else
- return false
- end
- end
- local function coupe()
- turtle.select(woodSlot)
- turtle.dig()
- turtle.forward()
- while detectCoupe() do
- turtle.digUp()
- turtle.up()
- for i=0,3 do
- if turtle.detect() then
- if testbois() then
- else
- turtle.dig()
- end
- end
- turtle.turnRight()
- end
- end
- if not turtle.back() then
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- turtle.turnRight()
- end
- while not chemin() do
- if preventStuck() then
- turtle.digDown()
- end
- turtle.down()
- end
- plante()
- turtle.suck()
- end
- local function vide(itemID)
- local selecteddItem = 0
- for slot = 1,11 do
- turtle.select(slot)
- selecteddItem = turtle.getItemDetail()
- if itemID and selecteddItem then
- if selecteddItem.name == itemID then
- turtle.drop()
- end
- else
- turtle.drop()
- end
- end
- end
- local function provision()
- vide()
- for i=1,16 do
- turtle.select(i)
- turtle.suck()
- end
- vide()
- end
- local function gocoffre()
- local foundChest = false
- while foundChest ~= true do
- for i=0,3 do
- if testcoffre() then
- foundChest = true
- break
- else
- turtle.turnRight()
- end
- end
- if foundChest ~= true then
- turtle.turnLeft()
- for i=0,3 do
- Energy()
- if turtle.forward() then
- if chemin() then
- break
- else
- Energy()
- turtle.back()
- turtle.turnRight()
- end
- else
- turtle.turnRight()
- end
- end
- end
- end
- provision()
- end
- --turtle script made by Ardevlirn
- local function settingUp()
- --gocoffre()
- while turtle.detectDown() ~= true or preventStuck() do
- Energy()
- if preventStuck() then
- turtle.digDown()
- end
- turtle.down()
- end
- local didMove = false
- while chemin() ~= true do
- if turtle.back() then
- didMove = true
- end
- if chemin() ~= true then
- if didMove then
- turtle.forward()
- end
- turtle.turnRight()
- end
- end
- end
- local function start()
- local stop = false
- settingUp()
- while stop ~= true do
- Energy()
- for i=0,3 do
- if testcoffre() then
- provision()
- elseif testbois() then
- Energy()
- coupe()
- turtle.select(saplingSlot)
- turtle.suck()
- elseif testpousse() then
- turtle.select(saplingSlot)
- turtle.suck()
- Energy()
- else
- plante()
- turtle.select(saplingSlot)
- turtle.suck()
- end
- turtle.turnRight()
- end
- if turtle.getItemCount(11) ~= nil and turtle.getItemCount(11) >= 1 then
- gocoffre()
- end
- if turtle.getItemCount(saplingSlot) ~= nil and goSearchSapling == true and turtle.getItemCount(saplingSlot) <= minSaplingInInventory then
- local selecteddItem = 0
- turtle.select(saplingSlot)
- local saplingID = turtle.getItemDetail()
- for slot = 1,11 do
- turtle.select(slot)
- selecteddItem = turtle.getItemDetail()
- if saplingID and selecteddItem then
- if selecteddItem.name == saplingID.name then
- turtle.transferTo(saplingSlot,(64-saplingID.count))
- end
- end
- end
- if turtle.getItemCount(saplingSlot) ~= nil and turtle.getItemCount(saplingSlot) <= minSaplingInInventory then
- gocoffre()
- end
- end
- turtle.turnLeft()
- for i=0,3 do
- Energy()
- if turtle.forward() then
- if chemin() then
- break
- else
- Energy()
- turtle.back()
- turtle.turnRight()
- end
- else
- turtle.turnRight()
- end
- end
- if turtle.getFuelLevel() ~= "unlimited" and turtle.getItemCount(fuelSlot) ~= nil and turtle.getItemCount(fuelSlot) <= minFuelInInventory then
- local selecteddItem = 0
- turtle.select(fuelSlot)
- local fuelID = turtle.getItemDetail()
- for slot = 1,11 do
- turtle.select(slot)
- selecteddItem = turtle.getItemDetail()
- if fuelID and selecteddItem then
- if selecteddItem.name == fuelID.name then
- turtle.transferTo(fuelSlot,(64-fuelID.count))
- end
- end
- end
- if turtle.getItemCount(fuelSlot) ~= nil and turtle.getItemCount(fuelSlot) <= minFuelInInventory then
- gocoffre()
- end
- end
- end
- end
- start()
Add Comment
Please, Sign In to add comment