Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local S_WOOD = 1
- local S_CCOAL = 16
- local S_SAPLING = 2
- local S_DIRT = 15
- local SLEEP_TIME = 120
- local qty_wood = 0
- local count_checked = 0
- function waitForEnoughItems(itemName, n, slot)
- turtle.select(slot)
- while turtle.getItemCount(slot) < n do
- if itemName then print(string.format("Insert %s into slot %d",itemName,slot)) end
- os.sleep(0.5)
- os.pullEvent("turtle_inventory")
- end
- end
- function waitForEnoughFuel(minLevel, slot)
- local qty = turtle.getFuelLevel()
- local refuel = function()
- if qty > minLevel then return qty end
- turtle.select(slot)
- turtle.refuel()
- qty = turtle.getFuelLevel()
- print("fuel: ",qty)
- return qty
- end
- while refuel() < minLevel do
- print(string.format("Insert fuel-items into slot %d: %d/%d", slot, qty, minLevel))
- os.sleep(1)
- os.pullEvent("turtle_inventory")
- end
- end
- function isWood(direction)
- turtle.select(S_WOOD)
- if direction == "top" then
- return turtle.compareUp()
- else
- return turtle.compare()
- end
- end
- function cutWoods()
- turtle.select(S_WOOD)
- turtle.dig()
- turtle.forward()
- while turtle.detectUp() do
- turtle.digUp()
- turtle.up()
- end
- end
- function cutLeaves()
- turtle.select(S_SAPLING)
- while not turtle.detectDown() do
- for i=1,4 do
- turtle.dig()
- turtle.turnRight()
- end
- turtle.down()
- end
- end
- function placeItem(slot, direction)
- turtle.select(slot)
- if direction == "down" then
- turtle.placeDown()
- else
- turtle.place()
- end
- end
- function getSapling()
- turtle.select(S_DIRT)
- turtle.digDown()
- turtle.down()
- for i=1,4 do
- turtle.select(S_SAPLING)
- turtle.suck()
- turtle.turnRight()
- end
- turtle.up()
- placeItem(S_DIRT, "down")
- turtle.back()
- placeItem(S_SAPLING)
- end
- function dropItem(slot, nLeaves)
- turtle.select(slot)
- local n = turtle.getItemCount()
- if n > nLeaves then
- if slot == S_WOOD then
- qty_wood = qty_wood + (n-nLeaves)
- print(qty_wood)
- end
- return turtle.drop(n-nLeaves)
- else
- return false, "No items to drop"
- end
- end
- function fillItemSlot(slot, direction)
- turtle.select(slot)
- local n = turtle.getItemSpace()
- if direction == "down" then
- return turtle.suckDown(n)
- else
- return turtle.suck(n)
- end
- end
- function makeCoal()
- turtle.back()
- turtle.back()
- turtle.back()
- turtle.turnRight()
- turtle.turnRight()
- fillItemSlot(S_CCOAL, "down")
- dropItem(S_CCOAL, 2)
- if turtle.getFuelLevel() < 80 then
- turtle.select(S_CCOAL)
- assert(turtle.refuel(1), "FuelLevel is low.")
- end
- turtle.up()
- turtle.up()
- assert(dropItem(S_WOOD, 2), "The chest for woods is full.")
- turtle.down()
- turtle.down()
- turtle.turnLeft()
- dropItem(S_WOOD, 2)
- dropItem(S_SAPLING, 32)
- turtle.turnLeft()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- end
- -- main
- waitForEnoughItems("BirchSapling", 2, S_SAPLING)
- waitForEnoughItems("BirchWood", 1, S_WOOD)
- waitForEnoughItems("Dirt", 2, S_DIRT)
- waitForEnoughFuel(80, S_CCOAL)
- while true do
- local isWood = isWood()
- if isWood or count_checked > 1 then
- print("Start cutting.")
- count_checked = 0
- cutWoods()
- cutLeaves()
- getSapling()
- if isWood then makeCoal() end
- else
- count_checked = count_checked+1
- print("It isn't wood.")
- end
- turtle.select(S_SAPLING)
- turtle.suckUp()
- turtle.suckDown()
- turtle.suck()
- os.sleep(SLEEP_TIME)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement