/
levas95
/
minecraft_Lua_turtle
Обзор
Документация
Войти
/
levas95
/
minecraft_Lua_turtle
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
bridge
195 строк
5 KB
levas95
Create
27 июн 2026, 13:23
Верифицирован
27 июн 2026, 13:23
8bcbb4f
Код
Авторство
О чём код?
-- global variable for start block for build local initialBlockType = nil -- Function to check items in the inventory function checkItems() -- Check torches in the first slot if turtle.getItemCount(1) == 0 then print("No torches in the first slot!") return false end -- if start block not safe if initialBlockType == nil then for i = 2, 16 do if turtle.getItemCount(i) > 0 then initialBlockType = turtle.getItemDetail(i).name break end end end -- Check blocks in other slots for i = 2, 16 do local item = turtle.getItemDetail(i) if item and item.name == initialBlockType then return true end end print("No building blocks in the inventory!") return false end -- Function to get a block from the inventory function getBlock() -- Check blocks in other slots for i = 2, 16 do local item = turtle.getItemDetail(i) if item and item.name == initialBlockType then turtle.select(i) return true end end return false end -- Function to check forward movement function safeMoveForward() if turtle.detect() then print("Failed to move forward! Stopping construction.") return false else local attempts = 0 while not turtle.forward() and attempts < 20 do attempts = attempts + 1 if not turtle.attack() then sleep(0.5) end end if attempts >= 20 then print("Maximum attempts reached! Stopping construction.") return false else return true end end end -- Function for safe backward movement function safeMoveBack() if not turtle.back() then turtle.turnRight() turtle.turnRight() if turtle.detect() then print("Failed to move forward! Stopping construction.") turtle.turnLeft() turtle.turnLeft() return false else local attempts = 0 while not turtle.forward() and attempts < 20 do attemepts = attempts + 1 if not turtle.attack() then sleep(0.5) end end if attempts >= 20 then print("Maximum attempts reached! Stopping construction.") turtle.turnLeft() turtle.turnLeft() return false end turtle.turnLeft() turtle.turnLeft() return true end end return true end -- Function for place down with attack and dig function placeDown2() local attempts = 0 while not turtle.placeDown() and attempts < 20 do attempts = attempts + 1 if turtle.detectDown() then turtle.digDown() else turtle.attackDown() end end end -- Main bridge building function function buildBridge(length) local blocksPlaced = 0 while blocksPlaced < length do -- Check available materials if not checkItems() then return end -- Place 5 sets of blocks (center, left, right) for i = 1, 5 do if not getBlock() then return end -- Central block placeDown2() -- Left block if getBlock() then turtle.turnLeft() if safeMoveForward() then placeDown2() if not safeMoveBack() then return end end end -- Right block if getBlock() then if safeMoveBack() then placeDown2() if not safeMoveForward() then return end turtle.turnRight() else turtle.turnRight() end end -- Check forward movement success if not safeMoveForward() then return end blocksPlaced = blocksPlaced + 1 if blocksPlaced >= length then return end end -- Place torch behind turtle.select(1) turtle.turnLeft() turtle.turnLeft() turtle.place() turtle.turnRight() turtle.turnRight() end end local tArgs = { ... } -- Get bridge length from arguments if #tArgs ~= 1 then print("Usage: buildBridge <bridge length>") else local length = tonumber(tArgs[1]) if length then buildBridge(length) else print("Error: bridge length must be a number!") end end