Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Soglia di carburante sotto la quale deve rifornirsi
- local LOW_FUEL_THRESHOLD = 500
- -- 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 isRightItem(slot,item)
- --test
- end
- function isSapling()
- return isBlock(2)
- end
- function isLog()
- return isBlock(4)
- end
- -- Funzione per controllare se il blocco davanti è acqua
- function isWater()
- local success, data = turtle.inspect()
- if success then
- return data.name == "minecraft:water" or data.name == "minecraft:flowing_water"
- end
- return false
- end
- function fillResource(direction, steps, slot, resource)
- print("Filling Up " .. resource .. "...")
- for i=1,3 do
- while not turtle.back() do
- print("turtle is stuck")
- forceBackMove()
- sleep(0.5)
- end
- 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 == "BoneMeal" then
- while turtle.getItemCount(slot) <= 5 do
- print(resource .. "...")
- sleep(15)
- local neededItems = (64-turtle.getItemCount(slot))
- turtle.suck(neededItems)
- end
- elseif resource == "fuel" then
- local maxfuel = turtle.getFuelLimit()
- while turtle.getFuelLevel() < maxfuel do
- print("Fuel: " .. turtle.getFuelLevel() .. "/" .. turtle.getFueleLimit())
- while turtle.getItemCount(slot) == 0 do
- turtle.suck(64)
- if turtle.getItemCount(slot) == 0 then
- sleep(15)
- end
- end
- turtle.refuel(1)
- end
- turtle.suck(64)
- end
- for i=1,steps do
- if direction == "left" then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- for i=1,3 do
- while not turtle.forward() do
- print("turtle is stuck")
- forceForwardMove()
- sleep(0.5)
- end
- end
- print("Filled")
- end
- function useBoneMeal()
- print("Fertilizing...")
- while not isLog() do
- checkFuel()
- if turtle.getItemCount(3) <= 5 then
- fillResource("left",1,3,"BoneMeal")
- else
- turtle.select(3)
- turtle.place()
- sleep(0.5)
- end
- end
- print("Tree has grown!!")
- end
- function dispenserToggler()
- rs.setBundledOutput("bottom", colors.gray)
- sleep(0.5)
- rs.setBundledOutput("bottom", 0)
- end
- function digAndPlant()
- while turtle.detect() do
- turtle.dig()
- end
- turtle.select(2)
- turtle.place()
- end
- function forceBackMove()
- turtle.turnLeft()
- turtle.turnLeft()
- while turtle.detect() do
- turtle.dig()
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- function forceForwardMove()
- while turtle.detect() do
- turtle.dig()
- end
- end
- function plantSapling()
- if turtle.getItemCount(2) <= 5 then
- fillResource("right", 1, 2, "sapling")
- end
- --Primo sapling
- while not turtle.forward() do
- forceForwardMove()
- end
- turtle.turnLeft()
- digAndPlant()
- turtle.turnRight()
- --Secondo sapling
- while not turtle.forward() do
- forceForwardMove()
- end
- turtle.turnLeft()
- digAndPlant()
- turtle.turnRight()
- --Terzo sapling
- while not turtle.back() do
- forceBackMove()
- end
- digAndPlant()
- --Quarto sapling
- while not turtle.back() do
- forceBackMove()
- end
- digAndPlant()
- end
- --abbatto l'albero e ripianto
- function chopTreeAndReplant()
- dispenserToggler()
- print("Chopping tree.") -- Taglia l'albero
- turtle.dig()
- sleep(7) -- aspetto che l'acqua rimuova le foglie
- dispenserToggler()
- sleep(3) --aspetto che l'acqua vada via
- print("Planting sapling.") -- Ripianto il sapling
- plantSapling()
- end
- -- controlla il livello di carburante
- function checkFuel()
- if turtle.getFuelLevel() < LOW_FUEL_THRESHOLD then
- if turtle.getItemCount(1) <= 5 then
- fillResource("left", 2, 1, "fuel")
- else
- turtle.select(1)
- turtle.refuel()
- end
- print("Refueled")
- end
- end
- while true do
- checkFuel()
- if colors.test(rs.getBundledInput("bottom"), colors.green) then
- print("Logs storage full.")
- sleep(50)
- else
- if isWater() then
- print("Water detected...")
- dispenserToggler()
- sleep(5)
- end
- if isLog() then
- print("Chopping tree.")
- chopTreeAndReplant()
- elseif not isSapling() then
- print("Planting sapling...")
- plantSapling()
- elseif isSapling() then
- useBoneMeal()
- print("Waiting....")
- end
- end
- sleep(3)
- end
Advertisement
Add Comment
Please, Sign In to add comment