Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Soglia di carburante sotto la quale stampare un avviso
- local LOW_FUEL_THRESHOLD = 100
- local LAST_BONEMEAL_CHECK = 0
- local PLANTING_LOOP = 0
- -- Funzione per controllare se il blocco davanti Γ¨ lo stesso tipo di quello nello slot dato
- function isBlock(slot)
- local success, data = turtle.inspect()
- local Detail = turtle.getItemDetail(slot)
- if success and Detail and data.name == Detail.name then
- return true
- end
- return false
- end
- function isSapling()
- return isBlock(2)
- end
- function isLog()
- return isBlock(4)
- end
- function fillResource(direction, steps, slot, resource)
- print("Filling UP " .. resource .. "...")
- for i=1,3 do
- turtle.back()
- end
- for i=1,steps do
- if direction == "left" then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- turtle.select(slot)
- turtle.suck(63)
- if resource == "Sapling" or resource == "fuel" then
- while turtle.getItemCount(slot) == 0 do
- print("...")
- sleep(15)
- turtle.suck(63)
- end
- else
- if turtle.getItemCount(slot) == 0 then
- LAST_BONEMEAL_CHECK = 100;
- end
- end
- for i=1,steps do
- if direction == "left" then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- for i=1,3 do
- turtle.forward()
- end
- print("Filled")
- end
- function useBoneMeal()
- print("Using bone meal...")
- while not isLog() do
- if turtle.getItemCount(3) == 0 then
- if LAST_BONEMEAL_CHECK == 0 then
- fillResource("left",1,3,"BoneMeal")
- else
- sleep(3)
- LAST_BONEMEAL_CHECK = LAST_BONEMEAL_CHECK - 1
- if LAST_BONEMEAL_CHECK % 10 == 0 then
- print("No bone meal new try " .. LAST_BONEMEAL_CHECK .. "/100")
- end
- end
- else
- turtle.select(3)
- turtle.place()
- sleep(1)
- end
- end
- print("Tree has grown.")
- end
- function dispenserToggler()
- rs.setOutput("bottom",true)
- sleep(0.5)
- rs.setOutput("bottom",false)
- end
- --abbatto l'albero e ripianto
- function chopTreeAndReplant()
- dispenserToggler()
- print("Chopping tree.") -- Taglia l'albero
- turtle.dig()
- sleep(5) -- aspetto che l'acqua rimuova le foglie
- dispenserToggler()
- sleep(3) --aspetto che l'acqua vada via
- print("Planting sapling.") -- Ripianto il sapling
- turtle.dig() --rimuove se ci sono delle foglie ritardate della immersive wheatering(mannaggia a chi l'ha programmata male)
- turtle.dig()
- turtle.select(2)
- turtle.place()
- end
- -- controlla il livello di carburante
- function checkFuel()
- if turtle.getFuelLevel() < LOW_FUEL_THRESHOLD then
- if turtle.getItemCount(1) == 0 then
- fillResource("left", 2, 1, "fuel")
- end
- turtle.select(1)
- turtle.refuel()
- print("Refueled")
- end
- end
- while true do
- checkFuel()
- if isLog() then
- print("Chopping tree.")
- chopTreeAndReplant()
- elseif not isSapling() then
- PLANTING_LOOP = PLANTING_LOOP + 1
- print("Planting sapling try:" .. PLANTING_LOOP .. "/10")
- if turtle.getItemCount(2) == 0 then
- fillResource("right", 1, 2, "sapling")
- end
- turtle.select(2)
- turtle.place()
- if PLANTING_LOOP >= 10 then
- PLANTING_LOOP = 0
- chopTreeAndReplant()
- end
- elseif isSapling() then
- PLANTING_LOOP = 0
- useBoneMeal()
- print("Waiting....")
- end
- sleep(3)
- end
Advertisement
Add Comment
Please, Sign In to add comment