Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- usage: "Wall <X> <Y> <Direction>"
- -- <X> = number of blocks over
- -- <Y> = number of block up
- -- <Direction> = direction the wall will be built
- -- accepts "Left" or "Right"
- -- The turtle will look at slot 1 to find what block it has to work with. It will look to see if there are any successive blocks
- -- with the same block type. All 16 slots can be used as long as the block type is the same. If a different type of block is in
- -- slot 4, for example, only slots 1, 2, and 3 will be used.
- -- See this program in action at https://youtu.be/fLfqDiI0tsY
- local variables = {...}
- x = tonumber(variables[1])
- y = tonumber(variables[2])
- success = null
- data = {}
- data.name = null
- block = {}
- block2 = {}
- slots = 0
- locationX = 0
- locationY = 0
- direction = "left"
- directionY = "up"
- function printUsage()
- print("Wall program usage:\nWall <X> <Y> <Direction>\n\t<X> = number of blocks over\n\t<Y> = number of blocks up\n\t<Direction> = direction the wall will be build\n\t\taccepts 'Left' or 'Right'")
- end
- function start()
- if tonumber(variables[1]) == null then
- printUsage()
- return false
- end
- if tonumber(variables[2]) == null then
- printUsage()
- return false
- end
- if variables[3] ~= null then
- if string.lower(variables[3]) == "left" then
- print("direction set Left")
- direction = "left"
- elseif string.lower(variables[3]) == "right" then
- print("direction set Right")
- direction = "right"
- else
- printUsage()
- return false
- end
- end
- turtle.select(1)
- if turtle.getItemDetail() == null then
- print ("place some blocks in the turtle")
- return false
- end
- slots = 1
- block = turtle.getItemDetail()
- for i=2, 16 do
- turtle.select(i)
- if turtle.getItemDetail() == null then
- break
- end
- block2 = turtle.getItemDetail()
- if block.name == block2.name then
- slots = i
- else
- break
- end
- end
- turtle.select(1)
- print("Turtle will build a wall " .. x .. " by " .. y .. " blocks")
- end
- function tryForward()
- while turtle.forward() ~= true do
- success, data = turtle.inspect()
- if data.name == "minecraft:bedrock" then
- return false
- elseif success then
- turtle.dig()
- elseif turtle.attack() then
- turtle.suck()
- else
- sleep(0.5)
- end
- end
- return true
- end
- function tryDown()
- while turtle.down() ~= true do
- success, data = turtle.inspectDown()
- if data.name == "minecraft:bedrock" then
- return false
- elseif success then
- turtle.digDown()
- elseif turtle.attackDown() then
- turtle.suckDown()
- else
- sleep(0.5)
- end
- end
- locationY = locationY - 1
- return true
- end
- function tryUp()
- while turtle.up() ~= true do
- success, data = turtle.inspectUp()
- if data.name == "minecraft:bedrock" then
- return false
- elseif success then
- turtle.digUp()
- elseif turtle.attackUp() then
- turtle.suckUp()
- else
- sleep(0.5)
- end
- end
- locationY = locationY + 1
- return true
- end
- function slideLeft()
- turtle.turnLeft()
- tryForward()
- turtle.turnRight()
- tryPlace()
- end
- function slideRight()
- turtle.turnRight()
- tryForward()
- turtle.turnLeft()
- tryPlace()
- end
- function digUp()
- while turtle.detectUp() == true do
- turtle.digUp()
- sleep(0.5)
- end
- end
- function dig()
- while turtle.detect == true do
- turtle.dig()
- sleep(0.5)
- end
- end
- function tryPlace()
- invCheck()
- success, data = turtle.inspect()
- if data.name ~= block.name then
- while turtle.dig() == true do
- sleep(0.5)
- end
- turtle.place()
- end
- end
- function invCheck()
- if turtle.getItemDetail() ~= null then
- block2 = turtle.getItemDetail()
- else
- block2.name = "empty"
- end
- if block.name ~= block2.name then
- if turtle.getSelectedSlot() < slots then
- turtle.select(turtle.getSelectedSlot() + 1)
- else
- local locationX2 = locationX
- local locationY2 = locationY
- locationX = locationX + 1
- goHome()
- print("Out of items. Please replace and press Enter")
- turtle.select(1)
- if turtle.getItemDetail() ~= null then
- block2 = turtle.getItemDetail()
- else
- block2.name = "blank"
- end
- while block2.name ~= block.name do
- block2 = turtle.getItemDetail()
- local event, key = os.pullEvent("key")
- if key == 28 then
- break
- end
- end
- goBack(locationX2,locationY2)
- locationX = locationX - 1
- end
- end
- end
- function nextRow()
- if locationX < x then
- if direction == "left" then
- fuelCheck()
- slideLeft()
- elseif direction == "right" then
- fuelCheck()
- slideRight()
- end
- locationX = locationX + 1
- end
- end
- function buildRow()
- if directionY=="up" then
- while locationY<y-1 do
- fuelCheck()
- tryUp()
- tryPlace()
- end
- directionY = "down"
- elseif directionY=="down" then
- while locationY>0 do
- fuelCheck()
- tryDown()
- tryPlace()
- end
- directionY = "up"
- end
- end
- function goHome()
- if direction == "left" then
- turtle.turnRight()
- elseif direction == "right" then
- turtle.turnLeft()
- end
- for i=1,locationX-1 do
- tryForward()
- end
- if direction == "right" then
- turtle.turnRight()
- elseif direction == "left" then
- turtle.turnLeft()
- end
- for i=1,locationY do
- tryDown()
- end
- end
- function goBack(X2,Y2)
- if direction == "left" then
- turtle.turnLeft()
- elseif direction == "right" then
- turtle.turnRight()
- end
- for i=1,X2 do
- tryForward()
- end
- if direction == "left" then
- turtle.turnRight()
- elseif direction == "right" then
- turtle.turnLeft()
- end
- for i=1,Y2 do
- tryUp()
- end
- end
- function refuel()
- print("Put fuel in any free slot and press any key")
- local suc = false
- while true do
- local event, key = os.pullEvent("key")
- if key ~= null then
- break
- end
- end
- local curSlot = turtle.getSelectedSlot()
- for i=1,16 do
- turtle.select(i)
- if turtle.refuel() == true then
- suc = true
- end
- end
- turtle.select(curSlot)
- if suc == true then
- return true
- else
- return false
- end
- end
- function fuelCheck()
- if turtle.getFuelLevel() <= locationX + locationY +2 then
- local locationX2 = locationX
- local locationY2 = locationY
- locationX = locationX + 1
- goHome()
- while refuel() == false do
- end
- goBack(locationX2,locationY2)
- locationX = locationX - 1
- end
- return true
- end
- --Program Start
- if start() == false then
- return
- end
- while locationX < x do
- tryPlace()
- buildRow()
- if locationX < x-1 then
- nextRow()
- else
- locationX = locationX + 1
- end
- end
- goHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement