Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This program must be pasted to a Turtle (Basic or Advanced)
- -- If the turtle has a modem
- maxWidth = 1
- maxLength = 1
- maxHeight = 1
- actualWidth = 1
- actualLength = 1
- actualHeight = 1
- RL=1
- -- Improved version of dig()
- -- z1 : actual height
- -- 1) Refuels if needed (slot 1)
- -- 2) Digs forwards until it can move, then moves
- -- 3) If inventory is full, goes down to ground,
- -- places and dumps inventory in a chest (slot 2),
- -- then gets back into place
- function digPlus()
- -- Refuels if fuel below 60
- if turtle.getFuelLevel()<60 then
- turtle.select(1)
- turtle.refuel(1)
- end
- -- Digs until it can go forward
- turtle.dig()
- while turtle.forward()==false do
- turtle.dig()
- end
- local n=0
- for i=1, 16 do
- if turtle.getItemCount(i)>0 then
- n=n+1
- end
- end
- if n==16 then
- local dwn = 0
- if fromTop() then
- dwn = maxHeight-actualHeight
- else
- dwn = actualHeight-1
- end
- for i=1, dwn do
- turtle.digDown()
- turtle.down()
- end
- turtle.select(2)
- turtle.digDown()
- turtle.placeDown()
- for i=3, 16 do
- turtle.select(i)
- turtle.dropDown()
- end
- for i=1, dwn do
- turtle.up()
- end
- end
- end
- function digZsquare()
- while actualWidth <= maxWidth do
- digXline()
- if actualWidth < maxWidth then
- if fromLeft() == (RL%2==1) then
- turtle.turnRight()
- digPlus()
- turtle.turnRight()
- else
- turtle.turnLeft()
- digPlus()
- turtle.turnLeft()
- end
- RL=RL+1
- actualLength=1
- end
- actualWidth=actualWidth+1
- end
- end
- function digXline()
- while actualLength < maxLength do
- digPlus()
- actualLength=actualLength+1
- term.setCursorPos(14,2)
- term.write("Width : "..actualWidth.."/"..maxWidth)
- term.setCursorPos(14,4)
- term.write("Length : "..actualLength.."/"..maxLength)
- term.setCursorPos(14,6)
- term.write("Height : "..actualHeight.."/"..maxHeight)
- local perc = math.floor(100*(actualLength + maxLength*(actualWidth-1)+maxWidth*maxLength*(actualHeight-1))/(maxWidth*maxLength*maxHeight))
- term.setCursorPos(34,9)
- term.write(perc.."%")
- if math.floor(perc*28/100)>0 then
- term.setCursorPos(2+math.floor(perc*28/100),9)
- term.write("#")
- end
- if hasModem then
- rednet.send(7, perc.."%"..actualWidth.."x"..maxWidth.."X"..actualLength.."y"..maxLength.."Y"..actualHeight.."z"..maxHeight.."Z", "Turtle")
- end
- end
- end
- function fromTop()
- return corner>2
- end
- function fromLeft()
- return corner==1 or corner==2
- end
- -- Gets type of computer based on screen size and screen color
- function getTypeOfComputer()
- local x, y = term.getSize()
- local type = ""
- if x==51 and y==19 then
- type = "computer"
- elseif x==26 and y==20 then
- type = "pocket"
- elseif x==39 and y==13 then
- type = "turtle"
- else
- type = "monitor"
- end
- if term.isColor() then
- type = "adv_"..type
- end
- return type
- end
- function checkForModem()
- for _,side in ipairs(rs.getSides()) do
- if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
- rednet.open(side)
- return true
- end
- end
- return false
- end
- function errorScreen(msg)
- term.clear()
- local x, y = term.getSize()
- for i=1, x do
- for k=1, y do
- if k==1 or k==y or i==1 or i==x then
- term.setCursorPos(i, k)
- term.write("!")
- end
- end
- end
- local lines = 0
- lines = math.floor(string.len(msg)/(x-4))
- for i=0, lines do
- term.setCursorPos(3, math.floor(y/2)+i)
- if i==lines-1 then
- term.write(string.sub(msg, lines*(x-4)+1))
- else
- term.write(string.sub(msg, lines*(x-4)+1, lines*(x-3)+1))
- end
- end
- sleep(10)
- end
- Name = os.getComputerLabel()
- Type = getTypeOfComputer()
- hasModem = checkForModem()
- if not Type == "turtle" then
- errorScreen("This is not a turtle, be sure to download the program on an actual turtle, then try to run it")
- else
- term.clear()
- term.setCursorPos(1,1)
- print("Before starting, be sure to have placed:")
- print("- Some fuel in slot 1")
- print("- Some chests in slot 2")
- print(" ")
- print("Keep in mind that the turtle will start ")
- print("from the bottom left size of the room")
- print(" ")
- print("Press ENTER to get started\n\n")
- io.read()
- -- Throws error if fuel and chests or not provided
- if turtle.select(1) and not turtle.refuel(0) then
- errorScreen("You have to place fuel in slot #1 to proceed. Every type of fuel is accepted")
- end
- if turtle.select(2) and not turtle.getItemDetail().name=="chest" then
- errorScreen("You have to place some chests in slot #2. Only chests will be accepted, no other type of container will work")
- end
- -- Asks for sizes
- term.clear()
- term.setCursorPos(1,1)
- print("Insert Width: ")
- maxWidth = tonumber(read())
- print("Insert Length: ")
- maxLength = tonumber(read())
- print("Insert Height: ")
- maxHeight = tonumber(read())
- term.clear()
- corner = -1
- while corner > 4 or corner < 1 do
- term.clear()
- term.setCursorPos(1,1)
- print("From which corner are you starting to dig?")
- print("1 - Bottom left")
- print("2 - Bottom right")
- print("3 - Top left")
- print("4 - Top right")
- corner = tonumber(io.read())
- end
- term.clear()
- term.setCursorPos(2,3)
- term.write("PROGRESS ")
- term.setCursorPos(2,4)
- term.write(" /")
- term.setCursorPos(2,5)
- term.write("DIMENSION ")
- term.setCursorPos(2,8)
- term.write(",----------------------------.")
- term.setCursorPos(2,9)
- term.write("| |")
- term.setCursorPos(2,10)
- term.write("'----------------------------'")
- while actualHeight <= maxHeight do
- digZsquare()
- if actualHeight < maxHeight then
- if fromTop() then
- turtle.digDown()
- turtle.down()
- else
- turtle.digUp()
- turtle.up()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- actualLength=1
- actualWidth=1
- actualHeight=actualHeight+1
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement