Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- logBakup = fs.open("minarLog.json", "r")
- turtle.select(1)
- turtle.refuel(1)
- -- Campo de mina
- local profundidad = 16
- local altura = 8
- local ancho = 256
- local totalItems = 832
- local soloMenas = true
- local menasDesechables = {"minecraft:gravel","minecraft:stone","minecraft:cobblestone"}
- local totalMovimientosNecesarios = ancho * altura * profundidad
- -- Movimientos totales
- local movimientos = turtle.getFuelLevel()
- local movimientosTotales = turtle.getFuelLevel()
- -- variables reciclables
- local ciclo = {}
- if fs.exists("minarLog.json") then
- local cicloBackup = logBakup.readAll()
- cicloBackup = textutils.unserialise(cicloBackup)
- ciclo = cicloBackup
- else
- -- Salir de reposo
- turtle.forward()
- ciclo = {altura = altura - 1, profundidad = profundidad - 1, ancho = ancho - 1, x = "right", y = "up", z = "front"}
- end
- local contarMovimientos = 0
- local contarMovimientosTotales = 0
- -- Proceso
- while movimientos > 0 do
- -- contar campos disponibles
- local contarCamposLibres = 0
- for i=3,16 do
- local numElementos = turtle.getItemCount(i)
- if numElementos == 0 then
- contarCamposLibres = contarCamposLibres + 1
- end
- end
- -- Hay campos disponibles?
- if contarCamposLibres == 0 then
- local bool, bloque = turtle.inspect()
- if bool then
- local hayEspacio = false
- for i=3,16 do
- local bloqueCampo = turtle.getItemDetail(i)
- for m, mena in ipairs(menasDesechables) do
- if mena == bloqueCampo.name then
- turtle.select(i)
- turtle.drop()
- hayEspacio = true
- end
- end
- if bloqueCampo.name == bloque.name then
- if turtle.getItemSpace(i) > 5 then
- hayEspacio = true
- end
- end
- end
- -- Hay que volver?
- if not hayEspacio then
- local volverAncho = (ancho - 1) - ciclo.ancho
- local volverAltura = 0
- local volverProfundidad = 0
- local combustibleNecesario
- if ciclo.z == "front" then
- volverProfundidad = (profundidad - 1) - ciclo.profundidad
- else
- volverProfundidad = ciclo.profundidad
- end
- if ciclo.z == "up" then
- volverAltura = (altura - 1) - ciclo.altura
- else
- volverAltura = ciclo.altura
- end
- -- Calcular combustible necesario para volver
- combustibleNecesario = (volverAncho + volverAltura + volverProfundidad) * 2
- if combustibleNecesario > turtle.getFuelLevel() then
- local carbonNecesario = math.ceil(combustibleNecesario/80)
- turtle.select(1)
- turtle.refuel(carbonNecesario)
- end
- -- Volver en X
- if ciclo.z == "front" then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- while volverAncho > 0 do
- turtle.forward()
- volverAncho = volverAncho - 1
- end
- -- volver en Y
- while volverAltura > 0 do
- turtle.down()
- volverAltura = volverAltura - 1
- end
- -- volver Z
- turtle.turnLeft()
- while volverProfundidad > 0 do
- turtle.forward()
- volverProfundidad = volverProfundidad - 1
- end
- -- Dejando cofre y todo el inventario
- if not turtle.detect() then
- turtle.dig()
- turtle.select(2)
- turtle.place()
- end
- for i=3,16 do
- turtle.select(i)
- if turtle.compareTo(1) then
- turtle.transferTo(1)
- end
- turtle.drop()
- end
- turtle.select(1)
- local regresarProfundidad = 0
- local regresarAltura = 0
- local regresarAncho = 0
- -- calcular profunidad necesaria para regresar
- -- Es necesario saber la direccion hacia donde esta minando sobre la profundidad,
- -- esto se calcula, conociendo el dato, si la altura esta en un numero par o impar
- if ciclo.z == "front" then
- regresarProfundidad = (profundidad - 1) - ciclo.profundidad
- else
- regresarProfundidad = ciclo.profundidad
- end
- -- calcular altura necesaria para regresar
- -- Es necesario saber hacia que direccion esta minando sobre la altura
- -- Para eso usaremos la variable ciclo.y
- if ciclo.y == "up" then
- regresarAltura = (altura - 1) - ciclo.altura
- else
- regresarAltura = ciclo.altura
- end
- -- calcular ancho necesario para regresar
- -- Es necesaria la posicion respecto a la x, para eso usaremos la variable
- -- ciclo.ancho
- regresarAncho = (ancho - 1) - ciclo.ancho
- -- mover hacia Z
- turtle.turnLeft()
- turtle.turnLeft()
- while regresarProfundidad > 0 do
- turtle.forward()
- regresarProfundidad = regresarProfundidad - 1
- end
- -- mover hacia Y
- while regresarAltura > 0 do
- turtle.up()
- regresarAltura = regresarAltura - 1
- end
- -- mover hacia X
- turtle.turnRight()
- while regresarAncho > 0 do
- turtle.forward()
- regresarAncho = regresarAncho - 1
- end
- if ciclo.z == "front" then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- end
- end
- -- Avanzar
- if turtle.detect() then
- turtle.dig()
- end
- while turtle.forward() == false do
- print("intentando avanzar...")
- if turtle.detect() then
- turtle.dig()
- end
- sleep(0.5)
- end
- ciclo.profundidad = ciclo.profundidad - 1
- print("avanzo!")
- if ciclo.profundidad == 0 and ciclo.altura > 0 then
- if ciclo.y == "down" then
- turtle.digDown()
- turtle.down()
- elseif ciclo.y == "up" then
- turtle.digUp()
- turtle.up()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- ciclo.altura = ciclo.altura - 1
- ciclo.profundidad = profundidad - 1
- if ciclo.z == "front" then
- ciclo.z = "back"
- else
- ciclo.z = "front"
- end
- end
- if ciclo.altura == 0 and ciclo.profundidad == 0 and ciclo.ancho > 0 then
- if ciclo.y == "up" then
- if altura%2 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- else
- if altura%2 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- turtle.dig()
- turtle.forward()
- if ciclo.y == "up" then
- if altura%2 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- else
- if altura%2 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- ciclo.ancho = ciclo.ancho - 1
- -- reanudando ciclo
- ciclo.altura = altura - 1
- ciclo.profundidad = profundidad - 1
- -- cambiando ciclo.y
- if ciclo.y == "down" then
- ciclo.y = "up"
- elseif ciclo.y == "up" then
- ciclo.y = "down"
- end
- if ciclo.z == "front" then
- ciclo.z = "back"
- else
- ciclo.z = "front"
- end
- end
- -- if ciclo.altura == 0 and ciclo.profundidad == 0 and ciclo.ancho == 0 then
- -- break
- -- end
- movimientos = turtle.getFuelLevel()
- if movimientos == 5 then
- turtle.select(1)
- turtle.refuel(1)
- end
- log = fs.open("minarLog.json", "w")
- log.write(textutils.serialise(ciclo))
- log.close()
- contarMovimientos = contarMovimientos + 1
- contarMovimientosTotales = contarMovimientosTotales + 1
- term.clear()
- term.setCursorPos(1,1)
- print("Movimientos totales: " .. contarMovimientosTotales .. "\nCombustible: " .. movimientos .. "\n\nMovimiento en X: " .. ciclo.x .. "\nMovimiento en Y: " .. ciclo.y .. "\nMovimiento en Z: " .. ciclo.z .. "\n\nPosicion en X: " .. ciclo.ancho .. "\nPosicion en Y: " .. ciclo.altura .. "\nPosicion en Z: " .. ciclo.profundidad)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement