Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Kód pro stavění krychle nebo kvádru pomocí Turtle v Minecraftu
- local args = {...}
- local width = tonumber(args[1])
- local height = tonumber(args[2])
- local length = tonumber(args[3])
- if width == nil or height == nil or length == nil then
- print("Usage: build <width> <height> <length>")
- return
- end
- local currentX, currentY, currentZ = 0, 0, 0
- local totalBlocks = width * height * length
- -- Uložení velikostí do souboru
- local file = fs.open("dimensions.txt", "w")
- file.writeLine(width)
- file.writeLine(height)
- file.writeLine(length)
- file.close()
- -- Funkce pro doplnění paliva
- local function refuel()
- print("Čekám na doplnění paliva...")
- while turtle.getFuelLevel() < totalBlocks do
- for i = 1, 16 do
- turtle.select(i)
- if turtle.refuel(0) then
- turtle.refuel()
- end
- end
- os.sleep(1)
- end
- print("Palivo doplněno.")
- end
- -- Funkce pro doplnění itemů
- local function getItems()
- turtle.turnLeft()
- turtle.turnLeft()
- while not turtle.detect() do
- turtle.forward()
- end
- for i = 1, 16 do
- turtle.select(i)
- turtle.suck()
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- -- Kontrola coalu ve slotu
- local function checkCoal()
- for i = 1, 16 do
- turtle.select(i)
- local currentItem = turtle.getItemDetail()
- if currentItem and currentItem.name == "minecraft:coal" then
- turtle.drop()
- getItems()
- end
- end
- end
- -- Funkce pro pohyb
- local function moveForward()
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- end
- local function moveUp()
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.up()
- end
- local function moveDown()
- if turtle.detectDown() then
- turtle.digDown()
- end
- turtle.down()
- end
- -- Stavění
- local function build()
- for y = 1, height do
- for z = 1, length do
- for x = 1, width do
- if turtle.getFuelLevel() < 1 then
- refuel()
- end
- checkCoal()
- turtle.placeDown()
- if x < width then
- moveForward()
- end
- currentX = currentX + 1
- end
- if z < length then
- if z % 2 == 0 then
- turtle.turnRight()
- moveForward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- moveForward()
- turtle.turnLeft()
- end
- currentZ = currentZ + 1
- end
- end
- if y < height then
- moveUp()
- turtle.turnRight()
- turtle.turnRight()
- currentY = currentY + 1
- currentZ = 0
- end
- end
- end
- -- Pozastavení stavění
- local function pause()
- while true do
- local event, key = os.pullEvent("key")
- if key == keys.p then
- break
- end
- end
- end
- -- Uložení souřadnic do souboru
- local function saveCoordinates()
- local file = fs.open("coordinates.txt", "w")
- file.writeLine(currentX)
- file.writeLine(currentY)
- file.writeLine(currentZ)
- file.close()
- end
- -- Načtení souřadnic ze souboru
- local function loadCoordinates()
- if fs.exists("coordinates.txt") then
- local file = fs.open("coordinates.txt", "r")
- currentX = tonumber(file.readLine())
- currentY = tonumber(file.readLine())
- currentZ = tonumber(file.readLine())
- file.close()
- end
- end
- -- Hlavní program
- loadCoordinates()
- print("Stavění krychle/kvádru o rozměrech " .. width .. "x" .. height .. "x" .. length)
- while true do
- parallel.waitForAny(build, pause)
- saveCoordinates()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement