Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local size = 10
- local currentPosition = {x = 0, y = 0, z =0, d = 0}
- local savePostion = {x = 0, y = 0, z =0, d = 0}
- local homePosition = {x = 0, y = 0, z =0, d = 0}
- x, y, z, d = 0, 0, 0, 0
- -- dig
- function excavate(size, depth)
- local isFinished = false
- local useDepth = depth ~= nil and depth > 0
- local depthCount = 0
- if useDepth then
- if startNextLevel() then
- depthCount = depthCount + 1
- isFinished = depth >= depthCount
- end
- else
- isFinished = startNextLevel()
- end
- while isFinished do
- --up and down or column
- for i = 0, size - 1 do
- --row or left to right
- for j = 0, size - 1 do
- dig("forward")
- go("forward")
- end
- if i ~= size - 1 then
- --even turns right
- if i % 2 == 0 then
- turn("right")
- dig("forward")
- go("forward")
- turn("right")
- --odd turns left
- else
- turn("left")
- dig("forward")
- go("forward")
- turn("left")
- end
- end
- end
- if size % 2 == 1 then --if the size is odd 180 if not 900
- turn("left")
- turn("left")
- else
- turn("left")
- end
- if useDepth then
- if startNextLevel() then
- depthCount = depthCount + 1
- isFinished = depth >= depthCount
- end
- else
- isFinished = startNextLevel()
- end
- end
- local function startNextLevel()
- local atNext = go("down")
- if not atNext then
- dig("down")
- atNext = go("down")
- end
- return atNext
- end
- end
- function dig(str)
- local success = false
- if string.lower(str) == "forward" or string.lower(str) == "f" then
- success = turtle.dig()
- elseif string.lower(str) == "up" or string.lower(str) == "u" then
- success = turtle.digUp()
- elseif string.lower(str) == "down" or string.lower(str) == "down" then
- success = turtle.digDown()
- end
- return success
- end
- --check fuel
- function checkfuel()
- end
- function go(str)
- local success = false
- if string.lower(str) == "down" or string.lower(str) == "d" then
- if turtle.down() then
- currentPosition["y"] = currentPosition["y"] - 1
- success = true
- else
- term.write("I'm stuck!")
- end
- end
- if string.lower(str) == "up" or string.lower(str) == "u" then
- currentPosition["y"] = currentPosition["y"] + 1
- success = true
- end
- if string.lower(str) == "forward" or sting.lower(str) == "f" then
- if d == 0 then currentPosition["z"] = currentPosition["z"] + 1 end
- if d == 1 then currentPosition["x"] = currentPosition["x"] - 1 end
- if d == 2 then currentPosition["z"] = currentPosition["z"] - 1 end
- if d == 3 then currentPosition["x"] = currentPosition["x"] + 1 end
- success = true
- end
- if string.lower(str) == "back" or string.lower(str) == "b" then
- if d == 0 then currentPosition["z"] = currentPosition["z"] - 1 end
- if d == 1 then currentPosition["x"] = currentPosition["x"] + 1 end
- if d == 2 then currentPosition["z"] = currentPosition["z"] + 1 end
- if d == 3 then currentPosition["x"] = currentPosition["x"] - 1 end
- success = true
- end
- return success
- end
- function turn(str)
- if string.lower(str) == "right" or string.lower(str) == "r" then
- turtle.turnright()
- currentPosition["d"] = (currentPosition["d"] + 1) % 4
- end
- if string.lower(str) == "left" or string.lower(str) == "l" then
- turtle.turnleft()
- currentPosition["d"] = (currentPosition["d"] - 1) % 4
- end
- end
- -- track positon
- function trackPosition()
- end
- --track Inventory
- function trackInventory()
- end
- function goToPosition(position, order, canDig)
- local isFinished = false
- if order == nil then order = {"x", "z", "y"} end
- if canDig == nil then canDig = false end
- end
- excavate(size,depth)
Add Comment
Please, Sign In to add comment