Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- -- north 0 osten 1 süden 2 westen 3 | n z+1 o x+1 s z-1 w x-1 | hoch y+1 runter y-1
- local function createVector(setx,sety,setz)
- return {x=setx,y=sety,z=setz}
- end
- function VectorAreEqual(vec1, vec2)
- return vec1.x == vec2.x and vec1.y == vec2.y and vec1.z == vec2.z
- end
- rows = 0
- columns = 0
- atHome = false
- maxSlots = 16
- facing = nil
- actualCoordinates = createVector(0,0,0)
- nextCheckPoint = createVector(0,0,0)
- neededStepsForCheckPoint = 0
- startCoordinates = createVector(0,0,0)
- for key, value in pairs(startCoordinates) do
- print(key .. ": " .. value)
- end
- function initilise()
- if #args == 2 then
- columns = tonumber(args[1])-1
- rows = tonumber(args[2])-1
- end
- if columns == 0 then
- term.clear()
- term.setCursorPos(1, 1)
- io.write("Columns: ")
- columns = tonumber(io.read()) -1
- end
- if rows == 0 then
- term.clear()
- term.setCursorPos(1, 1)
- io.write("Rows: ")
- rows = tonumber(io.read()) -1
- end
- term.clear()
- term.setCursorPos(1, 1)
- --end initial fase
- end
- function goTo(position)
- local x1, y1, z1 = gps.locate(5)
- while actualCoordinates.y < position.y do
- if tryUpwards() then
- --y1 = y1 +1
- else
- return true
- end
- end
- while actualCoordinates.y > position.y do
- if tryDownwards() then
- --y1 = y1 -1
- else
- return true
- end
- end
- while actualCoordinates.z < position.z do
- --nach süden
- faceTo(2)
- tryForwards()
- end
- while actualCoordinates.z > position.z do
- --nach norden
- faceTo(0)
- tryForwards()
- end
- while actualCoordinates.x > position.x do
- --nach westen
- faceTo(3)
- tryForwards()
- end
- while actualCoordinates.x < position.x do
- --nach osten
- faceTo(1)
- tryForwards()
- end
- end
- function faceTo(sideToFace)
- local diff = (sideToFace - facing) % 4
- if diff == 0 then
- return -- Already facing the desired direction
- elseif diff == 1 then
- turtle.turnRight()
- elseif diff == 2 then
- turtle.turnRight()
- turtle.turnRight()
- elseif diff == 3 then
- turtle.turnLeft()
- end
- facing = sideToFace
- end
- local function turnLeft()
- end
- local function turnRight()
- end
- local function mine()
- end
- function checkFuel()
- local minFuelLevel = tonumber(startCoordinates.x) + tonumber(startCoordinates.y) + tonumber(startCoordinates.z) + 1
- if minFuelLevel < 100 then
- minFuelLevel = 100
- end
- if turtle.getFuelLevel() <= minFuelLevel then
- refuelFromChest()
- checkFuel()
- end
- end
- function returnHome()
- goTo(startCoordinates)
- print("Finished")
- os.exit()
- end
- function refuelFromChest()
- local search = maxSlots
- if not pullInventarToChest() then
- for search = maxSlots, 3, -1 do
- turtle.select(search)
- turtle.refuel(turtle.getItemCount(search))
- end
- statusText = "Inventar full return home"
- info()
- returnHome()
- do return end
- end
- turtle.select(2)
- turtle.place()
- turtle.select(3)
- turtle.suck()
- turtle.refuel(turtle.getItemCount(3))
- turtle.drop()
- turtle.select(2)
- turtle.dig()
- end
- function proofBedrockDown()
- local succes, block = turtle.inspectDown()
- if succes then
- if block.name == "minecraft:bedrock" then
- return true
- else
- return false
- end
- else
- return false
- end
- end
- function proofBedrockFront()
- local succes, block = turtle.inspect()
- if succes then
- if block.name == "minecraft:bedrock" then
- return true
- else
- return false
- end
- else
- return false
- end
- end
- function pullInventarToChest()
- local search = 0
- turtle.dig()
- turtle.dig()
- turtle.select(1)
- turtle.place()
- for search = maxSlots, 3, -1 do
- turtle.select(search)
- turtle.drop()
- end
- turtle.select(1)
- turtle.dig()
- --Wenn inventar nicht geleert werden kann zurueck zum Anfang
- if turtle.getItemCount(16) ~= 0 and turtle.getItemCount(3) ~= 0 then
- statusText = "Inventar full return home"
- return false
- end
- return true
- end
- local function checkFull()
- local returnment = false
- if turtle.getItemCount(16) ~= 0 then
- returnment = not pullInventarToChest()
- end
- if returnment then
- pullInventarToChest()
- end
- end
- function tryForwards()
- --Nachtanken wenn benötigt
- checkFuel()
- if proofBedrockFront() then
- returnHome()
- return false
- end
- while not turtle.forward() do
- if turtle.detect() then
- if turtle.dig() then
- checkFull()
- end
- elseif turtle.attack() then
- checkFull()
- --wenn kein block vor der turtle ist dann ist es ein mob
- else
- sleep(0.5)
- end
- end
- --positionAktualisieren
- if facing == 0 then
- actualCoordinates.z = actualCoordinates.z - 1
- elseif facing == 1 then
- actualCoordinates.x = actualCoordinates.x + 1
- elseif facing == 2 then
- actualCoordinates.z = actualCoordinates.z + 1
- elseif facing == 3 then
- actualCoordinates.x = actualCoordinates.x - 1
- end
- turtle.digUp()
- turtle.digDown()
- checkFull()
- info()
- return true
- end
- function tryBackwards()
- checkFuel()
- if not turtle.back() then
- turtle.turnRight()
- turtle.turnRight()
- tryForwards()
- turtle.turnRight()
- turtle.turnRight()
- end
- if facing == 0 then
- actualCoordinates.z = actualCoordinates.z + 1
- elseif facing == 1 then
- actualCoordinates.x = actualCoordinates.x - 1
- elseif facing == 2 then
- actualCoordinates.z = actualCoordinates.z - 1
- elseif facing == 3 then
- actualCoordinates.x = actualCoordinates.x + 1
- end
- return true
- end
- function tryUpwards()
- checkFuel()
- while not turtle.up() do
- if turtle.detectUp() then
- if turtle.digUp() then
- checkFull()
- end
- elseif turtle.attackUp() then
- checkFull()
- else
- sleep(0.5)
- end
- end
- actualCoordinates.y = actualCoordinates.y +1
- return true
- end
- function tryDownwards()
- checkFuel()
- if proofBedrockDown() then
- returnHome()
- return false
- end
- while not turtle.down() do
- if turtle.detectDown() then
- if turtle.digDown() then
- checkFull()
- end
- elseif turtle.attackDown() then
- checkFull()
- else
- sleep(0.5)
- end
- end
- actualCoordinates.y = actualCoordinates.y -1
- return true
- end
- function getFacing()
- local x1, y1, z1 = gps.locate()
- sleep(0.5)
- tryForwards()
- sleep(0.5)
- local x2,y2,z2 = gps.locate()
- tryBackwards()
- if z1 > z2 then
- facing = 0 --norden
- elseif z1 < z2 then
- facing = 2 --süden
- elseif x1 < x2 then
- facing = 1 --osten
- elseif x1 > x2 then
- facing = 3 --westen
- end
- sleep(0.2)
- return facing
- end
- function mineTurnRight()
- local neededFacing = facing + 1
- if neededFacing == 4 then
- neededFacing = 0
- end
- faceTo(neededFacing)
- end
- function mineTurnLeft()
- local neededFacing = facing -1
- if facing == 0 then
- neededFacing = 3
- end
- faceTo(neededFacing)
- end
- function mineArea(width, length, reversed)
- --goTo(createVector(targetX,actualCoordinates.y,targetZ))
- if (width % 2) == 1 then
- reversed = 1
- end
- local reducedLength = length-1
- tryDownwards()
- tryUpwards()
- local startFacing = facing
- local actualWidth = 0
- while actualWidth < width do
- --print(actualWidth)
- local axis = facing % 2
- local multiplyer = -1
- if axis == 0 then
- multiplyer = 1
- end
- multiplyer = multiplyer
- local targetZ = actualCoordinates.z + (facing == 0 and (multiplyer * -reducedLength) or facing == 2 and (multiplyer * reducedLength) or 0)
- local targetX = actualCoordinates.x + (facing == 1 and (multiplyer * -reducedLength) or facing == 3 and (multiplyer * reducedLength) or 0)
- goTo(createVector(targetX,actualCoordinates.y,targetZ))
- if actualWidth < (width-1) then
- targetZ = actualCoordinates.z + (startFacing == 1 and reversed * 1 or startFacing == 3 and reversed * -1 or 0)
- targetX = actualCoordinates.x + (startFacing == 0 and reversed * 1 or startFacing == 2 and reversed * -1 or 0)
- goTo(createVector(targetX,actualCoordinates.y,targetZ))
- if actualWidth % 2 == 0 then
- if reversed == 1 then
- mineTurnRight()
- else
- mineTurnLeft()
- end
- else
- if reversed == 1 then
- mineTurnLeft()
- else
- mineTurnRight()
- end
- end
- end
- actualWidth = actualWidth +1
- end
- reversed = reversed * -1
- mineTurnRight()
- mineTurnRight()
- local x1, y1, z1 = gps.locate(5)
- actualCoordinates = createVector(x1,y1,z1)
- goTo(createVector(x1,y1-3,z1))
- mineArea(width,length,reversed)
- end
- function info()
- term.clear()
- term.setCursorPos(1, 1)
- print("---------------------------------------")
- print("-----------Made by IdZero------------")
- print("---------------------------------------")
- print("Mining size: " .. rows + 1 .. " by " .. columns + 1)
- print("")
- print("X: " .. actualCoordinates.x .. " Y: " .. actualCoordinates.y .. " Z: " .. actualCoordinates.z)
- print("Fuel level: " .. turtle.getFuelLevel())
- print("")
- --print("Status: " .. statusText)
- end
- if #args == 2 then
- columns = tonumber(args[1])-1
- rows = tonumber(args[2])-1
- end
- if columns == 0 then
- term.clear()
- term.setCursorPos(1, 1)
- io.write("Width: ")
- columns = tonumber(io.read()) -1
- end
- if rows == 0 then
- term.clear()
- term.setCursorPos(1, 1)
- io.write("Depth: ")
- rows = tonumber(io.read()) -1
- end
- term.clear()
- term.setCursorPos(1, 1)
- while turtle.getItemCount(1) ~= 1 do
- term.setCursorPos(1, 1)
- print("pleas place a enderchest with clear invertory into the first slot")
- sleep(5)
- end
- while turtle.getItemCount(2) ~= 1 do
- term.setCursorPos(1, 1)
- print("pleas place a enderchest with coal in it into the second slot")
- sleep(5)
- end
- local x, y, z = gps.locate(5)
- if not x then
- print("Missing GPS")
- else
- startCoordinates = createVector(x,y,z)
- actualCoordinates = createVector(x,y,z)
- print(tostring(startCoordinates.x) .. "|" .. tostring(startCoordinates.y) .. "|" .. tostring(startCoordinates.z))
- getFacing()
- print(facing)
- faceTo(0)
- --actualCoordinates.x = actualCoordinates.x +1
- --print(tostring(startCoordinates.x) .. "|" .. tostring(startCoordinates.y) .. "|" .. tostring(startCoordinates.z))
- --print(tostring(actualCoordinates.x) .. "|" .. tostring(actualCoordinates.y) .. "|" .. tostring(actualCoordinates.z))
- --goTo(createVector(125,89,177))
- --print(tostring(actualCoordinates.x) .. "|" .. tostring(actualCoordinates.y) .. "|" .. tostring(actualCoordinates.z))
- mineArea(columns,rows,1)
- --tryForwards()
- end
- --initilise()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement