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()
- local invTake = 0
- for i = 1, 16 do
- if turtle.getItemDetail(i) then
- invTake = invTake + 1
- end
- end
- if invTake <= 8 then
- return false
- else
- return true
- end
- end
- function goHomeAndBack()
- local xDig = x
- local yDig = y
- fuel()
- if xDig > 0 then moveForward("west", (0 - xDig)) elseif xDig < 0 then moveForward("east", math.abs(xDig)) end
- if yDig > 0 then moveForward("south", (0 - yDig)) elseif yDig < 0 then moveForward("north", math.abs(yDig)) end
- local success2, idtable2 = turtle.inspectDown()
- if success2 and idtable2.name == "minecraft:chest" then
- for i = 1, 16 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- if xDig > 0 then moveForward("east", xDig) elseif xDig < 0 then moveForward("west", (0 - xDig)) end
- if yDig > 0 then moveForward("north", yDig) elseif yDig < 0 then moveForward("south", (0 - yDig)) end
- 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
- else return "No available fuel or too much fuel"
- end
- end
- function basicDig()
- if turtle.detectUp() then turtle.digUp() end
- if turtle.detectDown() then turtle.digDown() end
- if turtle.detect() then turtle.dig() end
- end
- function moveForward(dirToGo, amount)
- if dirToGo ~= "north" or dirToGo ~= "south" or dirToGo ~= "east" or dirToGo ~= "west" or amount == 0 then return end
- 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
- local compassRotation = {"north", "east", "south", "west"}
- function turtleTurn(degAmt, startFace) --Use only in emergencies. Not integrated into coordinate plane
- local sNum = startFace
- if degAmt == 90 then
- turtle.turnRight()
- direction = compassRotation[startFace + 1]
- elseif degAmt == 180 then
- turtle.turnRight()
- turtle.turnRight()
- direction = compassRotation[startFace + 2]
- elseif degAmt == 270 then
- turtle.turnLeft()
- end
- end
- function switch(num)
- if num ~= 4 then return num + 1 end
- if num == 4 then return 1 end
- end
- function dig(amt) --Dig function; parameter "amt", same as digSize specified in beginning
- end
- dig(digSize)
Advertisement
Add Comment
Please, Sign In to add comment