Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- IO Test --
- dofile("NearEDGE-Functions")
- -- Direction is relative to the starting orientation of the turtle
- Dir = 0
- -- 0
- -- 3 1
- -- 2
- DirNames =
- {
- "in +Z",
- "in +X",
- "in -Z",
- "in -X"
- }
- -- Location is NOT the absolute location of the turtle.
- -- It is relative to the starting position of the turtle
- LocX = 0
- LocY = 0
- LocZ = 0
- function TurnLeft()
- turtle.turnLeft()
- Dir = (Dir-1)%4
- end
- function TurnRight()
- turtle.turnRight()
- Dir = (Dir+1)%4
- end
- function TurnShortest(dir)
- if((Dir-1)%4 == dir) then
- TurnLeft()
- else
- TurnRight()
- end
- end
- function UpdateLocZX()
- IsX = Dir%2
- isNeg = (Dir > 1)
- local Val = 1
- if(isNeg) then
- Val = -1
- end
- if(IsX ~= 0) then
- LocX = LocX + Val
- else
- LocZ = LocZ + Val
- end
- end
- function DoDigMove()
- assert(DigMove(), "Could not move " .. DirNames[Dir+1] .. "!")
- UpdateLocZX()
- end
- function DoDigMoveUp()
- assert(DigMoveUp(), "Could not move up!")
- LocY = LocY + 1
- end
- function DoDigMoveDown()
- assert(DigMoveDown(), "Could not move down!")
- LocY = LocY - 1
- end
- function TurnToDir(dir)
- while Dir ~= dir do
- TurnShortest(dir)
- end
- end
- function DigMoveToY(y)
- local DisY = (y-LocY)
- while LocY ~= y do
- if(DisY>0) then
- DoDigMoveUp()
- else
- DoDigMoveDown()
- end
- end
- end
- function DigMoveToX(x)
- local DisX = (x-LocX)
- local dir = 3
- if(DisX>0) then
- dir = 1
- end
- TurnToDir(dir)
- while LocX ~= x do
- DoDigMove()
- end
- end
- function DigMoveToZ(z)
- local DisZ = (z-LocZ)
- local dir = 2
- if(DisZ>0) then
- dir = 0
- end
- TurnToDir(dir)
- while LocZ ~= z do
- DoDigMove()
- end
- end
- function DigMoveTo(x, y, z)
- DigMoveToY(y)
- DigMoveToX(x)
- DigMoveToZ(z)
- end
- takeInitialStep = false
- LenX = 3
- LenZ = 3
- LenY = 3
- function CalculateFuelCost()
- local _fuelCost = (LenX*LenY*LenZ-1) + (LenX-1)+(LenY-1)+(LenZ-1)
- if(takeInitialStep) then
- _fuelCost = _fuelCost+2
- end
- return _fuelCost
- end
- function deposit()
- for i=1,16 do
- while turtle.drop() == false and turtle.getItemCount() ~= 0 do
- sleep(1)
- end
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- return true
- end
- function check()
- if turtle.getItemCount(15) == 0 then
- return false
- else
- return true
- end
- end
- -----------------------------------------------------------------
- cls()
- term.setCursorPos(8,6)
- textutils.slowPrint("DigCubeArea ----")
- term.setCursorPos(14,7)
- textutils.slowPrint("---- By NearEDGE")
- sleep(1)
- cls()
- print("DigCubeArea v1.0\n---------------------------------\n")
- LenZ = ReadNum("Bloques hacia delante a cavar:")
- cls()
- print("DigCubeArea v1.0\n---------------------------------\n")
- LenX = ReadNum("filas:")
- cls()
- print("DigCubeArea v1.0\n---------------------------------\n")
- LenY = ReadNum("alto:")
- cls()
- print("DigCubeArea v1.0\n---------------------------------\n")
- takeInitialStep = BooleanQuery("Empieza un bloque adelantado?")
- cls()
- print("DigCubeArea v1.0\n---------------------------------\n")
- __HaltOnInterruption = BooleanQuery("Parar al tener un obstaculo?")
- cls()
- print("DigCubeArea v1.0\n---------------------------------\n")
- print(string.format(" X: %i\n Y: %i\n Z: %i\n\n Take Initial Step: %s\n Halt on Interruption: %s\n", LenX, LenY, LenZ, tostring(takeInitialStep), tostring(__HaltOnInterruption)))
- continue = BooleanQuery("Is this correct?")
- cls()
- CurrentFuelLevel = turtle.getFuelLevel()
- if (continue and CurrentFuelLevel~= "unlimited") then
- FuelNeeded = CalculateFuelCost()
- if(FuelNeeded > turtle.getFuelLimit()) then
- print("Esta operación requiere demasiado combustible para esta turtle.\nIntentalo con un advanced turtle!\n\nNecesitas combustible: " .. FuelNeeded)
- continue = false
- else
- if(CurrentFuelLevel < FuelNeeded) then
- RecommendedFuel = GetRecommendedFuel(FuelNeeded)
- print("Esta operación gastara mas combustible del que tienes actualmente.\n\n Inserta al menos "..FuelNeeded.." unidades de combustible, luego pulsa enter para continuar.\n (Approx. "..RecommendedFuel[2].." "..RecommendedFuel[1].." (Recommended))\n")
- io.read()
- FuelConsumed = ConsumeFuel()
- CurrentFuelLevel = turtle.getFuelLevel()
- if(not FuelConsumed or CurrentFuelLevel < FuelNeeded) then
- print("Not enough fuel. Stopping!\n")
- continue = false
- end
- end
- end
- end
- -----------------------------------------------------------------
- if(not continue) then
- print("Intentalo otra vez!")
- else
- cls()
- print("DigCubeArea v1.0\n---------------------------------\n\n Empezando a cavar, suerte ;)!")
- ModX = 0
- ModZ = 0
- if(takeInitialStep) then
- DoDigMove()
- LocZ = 0
- end
- while LocY ~= LenY do
- while LocX ~= (LenX-1 + ModX) do
- while LocZ ~= (LenZ-1 + ModZ) do
- DoDigMove()
- end
- oldDir = Dir
- if check() then
- local lx,ly,lz = LocX, LocY, LocZ
- DigMoveTo(0,0,0)
- TurnToDir(2)
- deposit()
- DigMoveTo(lx,ly,lz)
- TurnToDir(Dir)
- end
- DirC = ((ModX*(1/(LenX-1)))*-2)+1
- while Dir ~= DirC do
- TurnShortest(DirC)
- end
- DoDigMove()
- DirC = (oldDir+2)%4
- while Dir ~= DirC do
- TurnShortest(DirC)
- end
- ModZ = LocZ*-1
- end
- while LocZ ~= (LenZ-1 + ModZ) do
- DoDigMove()
- end
- oldDir = Dir
- DirC = (oldDir+2)%4
- while Dir ~= DirC do
- TurnShortest(DirC)
- end
- ModZ = LocZ*-1
- ModX = LocX*-1
- if(LocY ~= LenY-1) then
- DoDigMoveUp()
- else
- break
- end
- end
- if(takeInitialStep) then
- DigMoveTo(0,0,-1)
- else
- DigMoveTo(0,0,0)
- end
- cls()
- print("Finished!")
- end
Add Comment
Please, Sign In to add comment