Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dlimit = 5
- local px, py = 0, 0
- local smer = 0
- local patro, startpatro, navx, navy, navpatro, navsmer, plno
- local nebrat = {"minecraft:stone", "minecraft:dirt", "minecraft:gravel", "minecraft:sand", "minecraft:cobblestone", "minecraft:sandstone", "minecraft:bedrock"}
- function resetScreen()
- term.clear()
- term.setCursorPos(1,1)
- end
- function otoc(okolik)
- smer = smer + okolik
- if smer > 3 then
- smer = smer - 4
- end
- if smer < 0 then
- smer = smer + 4
- end
- end
- function kopejKolem()
- local tezit = true
- local success, data = turtle.inspectUp()
- local hore = data.name
- for ki=1, #nebrat, 1 do
- if nebrat[ki] == hore then
- tezit=false
- break
- end
- end
- if tezit then
- turtle.digUp()
- aaa()
- end
- tezit = true
- local success, data = turtle.inspectDown()
- local dole = data.name
- for ki=1, #nebrat, 1 do
- if nebrat[ki] == dole then
- tezit=false
- break
- end
- end
- if tezit then
- turtle.digDown()
- aaa()
- end
- end
- function urobmisto(posice)
- turtle.select(posice)
- for hledam = posice-1, 1, -1 do
- if turtle.compareTo(hledam) or turtle.getItemCount(hledam) == 0 then
- turtle.transferTo(hledam)
- if turtle.getItemCount() == 0 then
- return true
- end
- end
- end
- return false
- end
- function jemisto2()
- if turtle.getItemCount(16) > 0 then
- if plno then
- turtle.select(16)
- -- pokud je 16 bordel, vyhod to
- local data = turtle.getItemDetail()
- for ki=1, #nebrat, 1 do
- if nebrat[ki] == data.name then
- turtle.drop()
- turtle.select(1)
- return(0)
- end
- end
- -- nejde vyhodit? Zkus ho pridat na jiny stack
- for i = 1, 15, 1 do
- if turtle.compareTo(i) then
- turtle.transferTo(i)
- if turtle.getItemCount() == 0 then
- turtle.select(1)
- return(0)
- end
- end
- end
- turtle.select(1)
- return(turtle.getItemCount(16))
- else
- -- Vyhazej vsechen bordel
- for i=1, 16, 1 do
- local data = turtle.getItemDetail(i)
- if data then
- for ki=1, #nebrat, 1 do
- if nebrat[ki] == data.name then
- turtle.select(i)
- turtle.drop()
- break
- end
- end
- end
- end
- defrag()
- local citac = 1
- while citac < 16 and turtle.getItemCount(citac) > 0 do
- if turtle.getItemSpace(citac) > 0 then
- for i=citac+1, 16, 1 do
- turtle.select(i)
- if turtle.compareTo(citac) then
- turtle.transferTo(citac)
- if turtle.getItemSpace(citac) == 0 then
- break
- end
- end
- end
- end
- citac=citac+1
- end
- if defrag() == 15 then
- plno = true
- print("PLNO!")
- end
- end
- else
- turtle.select(1)
- return(0)
- end
- turtle.select(1)
- return(turtle.getItemCount(16))
- end
- function defrag()
- local nenasel
- local pplny = 0
- for i=1, 15, 1 do
- if turtle.getItemCount(i) == 0 then
- nenasel = true
- for j=i+1, 16, 1 do
- if turtle.getItemCount(j) > 0 then
- turtle.select(j)
- turtle.transferTo(i)
- pplny = i
- nenasel = false
- break
- end
- end
- if nenasel then return(pplny) end
- else
- pplny = i
- end
- end
- return(pplny)
- end
- function jemisto()
- local dira, slt
- if turtle.getItemCount(16) > 0 then
- vyhod()
- if turtle.getItemCount(16) == 0 then
- return(0)
- end
- repeat
- dira = true
- if not urobmisto(16) then
- for slt=15, 2, -1 do
- if urobmisto(slt) then
- dira = false
- break
- end
- end
- end
- until dira
- end
- return turtle.getItemCount(16)
- end
- function vratit()
- for i = px, 1, -1 do
- krok(-1, 0, false)
- end
- turtle.turnLeft()
- otoc(-1)
- for i = py, 1, -1 do
- krok(0, -1, false)
- end
- turtle.turnRight()
- otoc(1)
- turtle.turnRight()
- otoc(1)
- repeat
- krokUp()
- patro = patro+1
- until patro >= startpatro
- turtle.turnRight()
- otoc(1)
- for i=1, 16, 1 do
- turtle.select(i)
- turtle.drop()
- end
- plno = false
- turtle.turnLeft()
- otoc(-1)
- print("Stav paliva: " .. turtle.getFuelLevel() .. "/" .. turtle.getFuelLimit())
- chybi = turtle.getFuelLimit() - turtle.getFuelLevel()
- print("Je mozno nacerpat " .. chybi .. " jednotek paliva.")
- uhli = math.floor(chybi/80)
- print("Naberu " .. uhli .. " uhli.")
- turtle.turnLeft()
- otoc(-1)
- turtle.select(16)
- while uhli > 64 do
- turtle.suck(64)
- uhli = uhli - 64
- turtle.refuel()
- end
- turtle.suck(uhli)
- turtle.refuel()
- print("Stav paliva: " .. turtle.getFuelLevel() .. "/" .. turtle.getFuelLimit())
- turtle.turnRight()
- otoc(1)
- turtle.select(1)
- while patro > navpatro do
- while turtle.detectDown() do
- turtle.digDown()
- end
- turtle.down()
- patro = patro-1
- end
- print("Stojim na: " .. px .. ", " .. py)
- print("Vracim se na: " .. navx .. ", " .. navy)
- for i=py, navy-1, 1 do
- krok(0, 1, false)
- end
- turtle.turnRight()
- otoc(1)
- for i=px, navx-1, 1 do
- krok(1, 0, false)
- end
- if navsmer == 2 then
- turtle.turnRight()
- otoc(1)
- end
- if navsmer == 3 then
- turtle.turnRight()
- otoc(1)
- turtle.turnRight()
- otoc(1)
- end
- if navsmer == 0 then
- turtle.turnLeft()
- otoc(-1)
- end
- turtle.select(1)
- end
- function aaa()
- if jemisto2() > 0 then
- print("Vracim se...")
- print("SMER: " .. smer)
- navx = px
- navy = py
- navpatro = patro
- navsmer = smer
- if smer == 0 then
- print("SMER: testovany - 0")
- turtle.turnLeft()
- otoc(-1)
- vratit()
- elseif smer == 2 then
- print("SMER: testovany - 2")
- turtle.turnRight()
- otoc(1)
- vratit()
- elseif smer == 3 then
- print("SMER: testovany - 3")
- turtle.turnRight()
- otoc(1)
- turtle.turnRight()
- otoc(1)
- vratit()
- else
- print("SMER: testovany - 1")
- vratit()
- end
- end
- end
- function krok(dx, dy, tst)
- while turtle.detect() do
- turtle.dig()
- if tst then aaa() end
- end
- while not turtle.forward() do
- print("NEPODARIL SE KROK")
- sleep(0.3)
- end
- px = px+dx
- py = py+dy
- if tst then kopejKolem() end
- end
- function kopejrovne(delka, dx, dy, tst)
- for i=1, delka, 1 do
- krok(dx, dy, tst)
- end
- end
- function vyhod()
- turtle.select(16)
- local data = turtle.getItemDetail()
- for ki=1, #nebrat, 1 do
- if nebrat[ki] == data.name then
- turtle.drop()
- return
- end
- end
- for dolni=1, 15, 1 do
- coje = turtle.getItemDetail(dolni)
- if coje then
- for horni=1, #nebrat, 1 do
- if coje.name == nebrat[horni] then
- turtle.select(dolni)
- turtle.drop()
- break
- end
- end
- end
- end
- turtle.select(1)
- end
- function zatocvpravo()
- turtle.turnRight()
- otoc(1)
- krok(1, 0, true)
- turtle.turnRight()
- otoc(1)
- end
- function zatocvlevo()
- turtle.turnLeft()
- otoc(-1)
- krok(1, 0, true)
- turtle.turnLeft()
- otoc(-1)
- end
- function krokUp()
- while turtle.detectUp() do
- turtle.digUp()
- end
- turtle.up()
- end
- --- ZACINAME ---
- resetScreen()
- print("Stav paliva: " .. turtle.getFuelLevel() .. "/" .. turtle.getFuelLimit())
- write("Startovni Y souradnice zelvy: ")
- startpatro = tonumber(read())
- write("Velikost hrany dolu: ")
- local hrana = tonumber(read())
- local nst = ((startpatro-dlimit)*2 + hrana*2)
- print("Nejkratsi smysluplna trasa - dolu a chodba a zpet = " .. nst .. " bloku")
- print("Budu potrebovat nejmene " .. nst .. " jednotek paliva = " .. math.ceil(nst/80) .. " uhli.")
- print("Celkovou spotrebu odhaduji na: " .. math.ceil( ((startpatro-dlimit)*2) + (((startpatro-dlimit)/3) * (hrana*hrana)) ) .. " jednotek paliva = " .. math.ceil( (((startpatro-dlimit)*2) + (((startpatro-dlimit)/3) * (hrana*hrana)) )/80) .. " uhli" )
- print("Stav paliva: " .. turtle.getFuelLevel() .. "/" .. turtle.getFuelLimit())
- read()
- turtle.select(16)
- turtle.refuel()
- patro = startpatro
- turtle.select(1)
- local soubor = io.open("dibag.txt", "w")
- plno = false
- -- Sjede dolu
- while patro > dlimit do
- while turtle.detectDown() do
- turtle.digDown()
- end
- turtle.down()
- patro = patro-1
- end
- print("Dole: " .. px .. ", " .. py .. ", " .. patro)
- soubor:write("Dole: " .. px .. ", " .. py .. ", " .. patro .. "\n")
- while patro < startpatro do
- -- Kopej plochu
- local jkoncove
- local smery = 1
- for j=1, hrana, 1 do
- kopejrovne(hrana-1, 0, smery, true)
- soubor:write("rada " .. j .. " - " .. px .. ", " .. py .. ", " .. patro .. "\n")
- if j < hrana then
- if j%2 > 0 then
- zatocvpravo()
- smery = -1
- else
- zatocvlevo()
- smery = 1
- end
- end
- jkoncove = j
- end
- --print("Konec patra: " .. px .. ", " .. py .. ", " .. patro)
- -- Na konci plochy
- if jkoncove%2 > 0 then
- turtle.turnLeft()
- otoc(-1)
- turtle.turnLeft()
- otoc(-1)
- kopejrovne(hrana-1, 0, -1, false)
- end
- turtle.turnRight()
- otoc(1)
- kopejrovne(hrana-1, -1, 0, false)
- turtle.turnRight()
- otoc(1)
- if px == 0 and py == 0 then
- print("Pujdu vyse: " .. px .. ", " .. py .. ", " .. patro)
- else
- print("ERROR: Mám být 0, 0 a jsem: " .. px .. ", " .. py)
- read()
- end
- -- Vystoupej nahoru
- krokUp()
- patro = patro+1
- if patro < startpatro then
- krokUp()
- patro = patro+1
- end
- if patro < startpatro then
- krokUp()
- patro = patro+1
- end
- end
- soubor:close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement