Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Declare nescessary variables
- local x, y = 0,0
- local direction = "north"
- local homeCoordX, homeCoordY = 0, 0
- local digSize = ...
- local success, idtable = turtle.inspectDown()
- if success and idtable.name == "minecraft:chest" then --Make sure there is a chest at Home
- print("Success")
- else
- error("Need chest below turtle to start digging!")
- end
- function testForAvailableFuel()
- for i = 1, 16 do
- turtle.select(i)
- if turtle.refuel(0) then --If the item in slot i is fuel, then return true but don't use it.
- return true
- end
- end
- return false
- end
- --[[function testForInvSpace() --Unsure how to go about function
- for i = 1, 16 do
- turtle.select(i)
- if turtle.
- end]]
- function fuel()
- local testSuccess = testForAvailableFuel()
- if turtle.getFuelLevel() <= math.floor(turtle.getFuelLimit()/2) and testSuccess == true then --If the turtle's fuel is less than half the limit AND there is fuel available
- for i = 1, 16 do
- turtle.select(i)
- if turtle.refuel(0) then
- turtle.refuel(math.floor(turtle.getItemCount(i)/2))
- end
- end
- end
- end
- function digForward(dirToGo, amount)
- for i = 1, amount do
- if dirToGo == "north" then --If needs to go north..
- y = y + 1
- if direction == "north" then --And is facing north..
- turtle.forward()
- elseif direction == "south" then --Facing south..
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- elseif direction == "west" then
- turtle.turnRight()
- turtle.forward()
- elseif direction == "east" then
- turtle.turnLeft()
- turtle.forward()
- end
- direction = "north"
- elseif dirToGo == "east" then --If needs to go east..
- x = x + 1
- if direction == "north" then
- turtle.turnRight()
- turtle.forward()
- elseif direction == "west" then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- elseif direction == "east" then
- turtle.forward()
- elseif direction == "south" then
- turtle.turnLeft()
- turtle.forward()
- end
- direction = "east"
- elseif dirToGo == "south" then --If needs to go south..
- y = y - 1
- if direction == "south" then
- turtle.forward()
- elseif direction == "north" then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- elseif direction == "east" then
- turtle.turnRight()
- turtle.forward()
- elseif direction == "west" then
- turtle.turnLeft()
- turtle.forward()
- end
- direction = "south"
- elseif dirToGo == "west" then --If needs to go west..
- x = x - 1
- if direction == "west" then
- turtle.forward()
- elseif direction == "east" then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- elseif direction == "south" then
- turtle.turnRight()
- turtle.forward()
- elseif direction == "north" then
- turtle.turnLeft()
- turtle.forward()
- end
- direction = "west"
- end
- fuel()
- end
- end
- --[[Turtle needs to dig in a perfect square, digSize x digSize in size.
- To do this, go north digSize, east digSize - 1, south digSize - 1, etc.]]
- function basicDig()
- if turtle.detectUp() then turtle.digUp() end
- if turtle.detectDown() then turtle.digDown() end
- if turtle.detect() then turtle.dig() end
- end
- local compassRotation = {"north", "east", "south", "west"}
- function dig(amt) --Dig function; parameter "amt", same as digSize specified in beginning
- local digLeft = amt
- for i = 1, digLeft do
- basicDig()
- end
- dig(digSize)
Advertisement
Add Comment
Please, Sign In to add comment