Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- WallBuilder
- 0.2 changed playOneLevel() to recordOneLevel() by Guuguy
- 0.1 (https://pastebin.com/rcmQYjk8) by Zs0lt
- ]]
- local tArgs={...}
- local currentlevel = 1
- local maxlevel = 1
- local program = ""
- local PC=0
- local materialCount=0
- local function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- function Update()
- clear()
- print("Building level: "..currentlevel.."/"..maxlevel)
- print("Fuel remaining: "..turtle.getFuelLevel())
- print("")
- local data = turtle.getItemDetail()
- if data then
- print("Builing material: {"..materialCount.."}")
- print(data.name)
- print("")
- end
- print("Program: {"..PC.."/"..string.len(program).."}")
- print("["..program.."]")
- if PC>0 then
- local t= " "
- for i = 1 ,PC-1 do
- t=t.." "
- end
- print(t.."^")
- end
- end
- function selectBlock()
- if turtle.getItemCount(16) ==0 then
- print("Waiting for material")
- while turtle.getItemCount(16) ==0 do
- sleep(.5)
- end
- turtle.select(2)
- end
- if turtle.getItemCount() >0 and turtle.compareTo(16) then
- return true
- end
- materialCount=0
- local selected = -1
- for i = 2, 16 do
- if turtle.getItemCount(i) >0 then
- turtle.select(i)
- if turtle.compareTo(16) then
- materialCount= materialCount+turtle.getItemCount(i)
- if selected == -1 then
- selected = i
- end
- end
- end
- end
- if selected==-1 then
- return false
- else
- turtle.select(selected)
- end
- end
- function placeBlock()
- if not refuel(5) then
- print("Waiting for fuel")
- while not refuel(5) do
- sleep(.5)
- end
- end
- selectBlock()
- turtle.place()
- materialCount=materialCount-1
- Update()
- end
- function placeBlockDown()
- if not refuel(5) then
- print("Waiting for fuel")
- while not refuel(5) do
- sleep(.5)
- end
- end
- selectBlock()
- turtle.placeDown()
- materialCount=materialCount-1
- Update()
- end
- function turn180()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function findnext( )
- if turtle.detect() then
- program = program.."F"
- return false
- end
- turtle.forward()
- if turtle.detectDown() then
- program = program.."F"
- return true
- end
- turtle.back()
- turtle.turnLeft()
- if turtle.detect() then
- program = program.."L"
- return false
- end
- turtle.forward()
- if turtle.detectDown() then
- program = program.."L"
- return true
- end
- turtle.back()
- turtle.turnLeft()
- turtle.turnLeft()
- if turtle.detect() then
- program = program.."R"
- return false
- end
- turtle.forward()
- if turtle.detectDown() then
- program = program.."R"
- return true
- end
- turtle.back()
- turtle.turnLeft()
- return false
- end
- function refuel( ammount )
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" then
- return true
- end
- local needed = ammount or (xPos + zPos + depth + 2)
- if turtle.getFuelLevel() < needed then
- local fueled = false
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- turtle.select(n)
- if turtle.refuel(1) then
- while turtle.getItemCount(n) > 0 and turtle.getFuelLevel() < needed do
- turtle.refuel(1)
- end
- if turtle.getFuelLevel() >= needed then
- turtle.select(1)
- return true
- end
- end
- end
- end
- turtle.select(1)
- return false
- end
- return true
- end
- function recordOneLevel()
- while true do
- if turtle.detect() then
- return true
- end
- if findnext() then
- turn180()
- placeBlock()
- turn180()
- else
- return true
- end
- end
- end
- function playOneLevel()
- for i=1, string.len(program) do
- local x = string.sub(program, i, i)
- PC=i
- if x=="F" then
- turtle.back()
- else
- if x=="L" then
- turtle.turnLeft()
- turtle.back()
- else
- if x=="R" then
- turtle.turnRight()
- turtle.back()
- end
- end
- end
- placeBlock()
- end
- end
- if tArgs[1] == nil then
- clear()
- print("How how many levels?")
- tArgs[1] = read()
- end
- maxlevel = tArgs[1]
- currentlevel = 1
- refuel(5)
- recordOneLevel()
- turtle.up()
- placeBlockDown()
- turtle.forward()
- turn180()
- for i = 2, tArgs[1] do
- currentlevel = i
- refuel(5)
- -- playOneLevel()
- recordOneLevel()
- turtle.up()
- placeBlockDown()
- turtle.back()
- end
- turn180()
Add Comment
Please, Sign In to add comment