Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local maxDistance = args[1] or 100
- local distance = 0
- local blacklist = { 'minecraft:cobblestone', 'minecraft:dirt',
- 'minecraft:gravel', 'minecraft:flint', 'minecraft:redstone'}
- local function has_value (tab, val)
- for i, value in ipairs(tab) do
- if value == val then
- return true
- end
- end
- return false
- end
- function MoveFront()
- if turtle.detect() then
- turtle.dig()
- if turtle.forward() == false then
- MoveFront()
- end
- else
- turtle.forward()
- end
- end
- function PlaceTorch()
- turtle.select(3)
- turtle.placeDown()
- end
- function DigUp()
- if turtle.detectUp() then
- turtle.digUp()
- end
- end
- function DigDown()
- if turtle.detectDown() then
- turtle.digDown()
- end
- end
- -- Mines 3x3 infront of the turtle.
- function Mine()
- MoveFront()
- DigUp()
- DigDown()
- turtle.turnLeft()
- MoveFront()
- DigUp()
- DigDown()
- turtle.turnRight()
- turtle.turnRight()
- MoveFront()
- MoveFront()
- DigUp()
- DigDown()
- turtle.back()
- turtle.turnLeft()
- end
- -- Checks if chests are present in slot 2, and if torches are present in slot 3.
- function CheckForItem(n)
- --chest checking
- if n == 1 then
- if turtle.getItemDetail(2).name == "minecraft:chest" then
- return true
- else
- return false
- end
- end
- --torch checking
- if n == 2 then
- if turtle.getItemDetail(3).name == "minecraft:torch" then
- return true
- else
- return false
- end
- end
- end
- function CheckGround()
- turtle.down()
- if turtle.detectDown() then
- turtle.up()
- return true
- else
- --find cobble, then place
- for i = 4,16 do
- if turtle.getItemDetail(i).name == "minecraft:cobblestone" then
- turtle.select(i)
- turtle.placeDown()
- break
- else
- return false
- end
- end
- turtle.up()
- return true
- end
- end
- -- true if it can drop off items, false if it cant due to no chests
- function Deposit()
- if CheckForItem(1) and CheckGround() then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.select(2)
- turtle.placeDown()
- turtle.select(1)
- for i = 4,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- if has_value(blacklist, turtle.getItemDetail(i).name) then
- turtle.dropUp()
- else
- turtle.dropDown()
- end
- end
- end
- turtle.select(1)
- turtle.turnLeft()
- turtle.turnLeft()
- return true
- else
- return false
- end
- end
- function Refuel()
- for i = 1,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- if turtle.refuel(2) then
- break
- end
- end
- end
- turtle.select(1)
- end
- -- deposit -> refuel -> mine
- while true do
- if distance > maxDistance then
- Deposit()
- break
- end
- if turtle.getItemCount(16) > 0 and distance % 8 ~= 0 then
- if CheckForItem(1) then
- Deposit()
- else
- break --stop the turtle if it can't store items
- end
- elseif turtle.getFuelLevel() < 5 then
- Refuel()
- else
- Mine()
- distance = distance + 1 -- place torch every 8th block
- if distance % 8 == 0 then
- if CheckForItem(2) then
- PlaceTorch()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement