Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local blocksMovedSinceLastChestplace = 0
- local chestSlot = 1 -- make sure to put this before fuelSlot, otherwise chests will be used for fuel
- local fuelSlot = 2 -- fuel will not be checked for on any slot before this
- local distanceBetweenChests = 100
- -- Functions
- function decidePlaceChest()
- if blocksMovedSinceLastChestplace >= distanceBetweenChests then
- local slotsFull = 0
- for i=1, 16, 1 do
- if i ~= torchSlot and i ~= chestSlot and i ~= fuelSlot then
- if turtle.getItemCount(i) > 0 then
- slotsFull = slotsFull + 1
- end
- end
- end
- if slotsFull >= 7 then
- placeChest()
- end
- blocksMovedSinceLastChestplace = 0
- end
- end
- function placeChest()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.select(chestSlot)
- if turtle.getItemCount(chestSlot) < 5 then
- setRed()
- print("Low on chests!")
- end
- turtle.select(chestSlot)
- while turtle.place() == false do
- turtle.dig()
- sleep(0.5)
- end
- for i=1, 16, 1 do
- if i ~= torchSlot and i ~= chestSlot and i ~= fuelSlot then
- turtle.select(i)
- turtle.drop()
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- function fuel()
- if turtle.getFuelLevel() < 5 then
- local alreadyNotified = false
- while true do
- local found = false
- for i=fuelSlot, 16, 1 do
- turtle.select(i)
- if turtle.refuel(1) == true then
- found = true
- break
- end
- end
- if found == true then
- break
- else
- if alreadyNotified == false then
- print("Need fuel!")
- alreadyNotified = true
- end
- end
- end
- turtle.select(1)
- end
- end
- function tryForward()
- local alreadyNotified = false
- fuel()
- while turtle.forward() == false do
- if alreadyNotified == false then
- print("Something is in my way!")
- alreadyNotified = true
- end
- turtle.dig()
- sleep(0.5)
- end
- blocksMovedSinceLastChestplace = blocksMovedSinceLastChestplace + 1
- end
- function tryUp()
- local alreadyNotified = false
- fuel()
- while turtle.up() == false do
- if alreadyNotified == false then
- print("Something is in my way!")
- alreadyNotified = true
- end
- turtle.digUp()
- sleep(0.5)
- end
- blocksMovedSinceLastChestplace = blocksMovedSinceLastChestplace + 1
- end
- function tryDown()
- local alreadyNotified = false
- fuel()
- while turtle.down() == false do
- if alreadyNotified == false then
- print("Something is in my way!")
- alreadyNotified = true
- end
- turtle.digDown()
- sleep(0.5)
- end
- blocksMovedSinceLastChestplace = blocksMovedSinceLastChestplace + 1
- end
- function digDistance(distance)
- for i=1, distance, 1 do
- digSingle()
- tryForward()
- end
- end
- function digSingle()
- while turtle.detect() == true do
- turtle.dig()
- end
- decidePlaceChest()
- end
- function digSingleUp()
- while turtle.detectUp() == true do
- turtle.digUp()
- end
- decidePlaceChest()
- end
- -- Scripts
- local args = { ... }
- -- or
- if table.getn(args) ~= 3 then
- print("incorrect number of args")
- print("cleararea <length> <width> <height>")
- return
- end
- if args[1] == nil or args[2] == nil or args[3] == nil then
- print("nil arg")
- print("cleararea <length> <width> <height>")
- return
- end
- if tonumber(args[1]) == nil or tonumber(args[2]) == nil or tonumber(args[3]) == nil then
- print("NAN")
- print("cleararea <length> <width> <height>")
- return
- end
- local length = tonumber(args[1])
- local width = tonumber(args[2])
- local height = tonumber(args[3])
- local newLength = length
- for i=1, height, 1 do
- digDistance(newLength)
- newLength = length - 1
- turtle.turnRight()
- digDistance(width-1)
- turtle.turnRight()
- digDistance(length-1)
- turtle.turnRight()
- digDistance(width-1)
- turtle.turnRight()
- if i ~= height then
- tryDown()
- end
- end
- for i=1, height-1, 1 do
- tryUp()
- end
- turtle.back()
- print("Complete")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement