Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function serialize(data, name) -- this is for setting the variable "data" what you want and "name" is the file name. when saving a number to the file make sure to write as tonumber(read()) (this overwrites each time)
- if not fs.exists('/data') then
- fs.makeDir('/data')
- end
- local f = fs.open('/data/'..name, 'w')
- f.write(textutils.serialize(data))
- f.close()
- end
- function unserialize(name) --this will bring up the file name in my program i need to make x = unserialize(name) this will set my variable to the saved number
- if fs.exists('/data/'..name) then
- local f = fs.open('/data/'..name, 'r')
- data = textutils.unserialize(f.readAll())
- f.close()
- end
- return data
- end
- --this sets up a host computer for gps network (below text)
- --shell.run("gps","host",x,y,z)
- --then on the turtle side you can set x, y, z = gps.locate(1) the one is the time till it times out if it cant find position
- function recieve() --this is the recieve side to run scripts
- modem = peripheral.wrap("left")
- modem.open(0)
- while true do
- event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- if message == "up" then
- turtle.up()
- end
- if message == "down" then
- turtle.down()
- end
- end
- end
- function getHeading() --gets heading and stores it in file = heading and variable is p (1 north is negative, 3 south is positive, 4 east is negative, and 2 west is positive )
- loc1 = vector.new(gps.locate(2,false))
- for i = 1,10 do
- if turtle.detect() == true then
- turtle.dig()
- else
- end
- end
- turtle.forward()
- loc2 = vector.new(gps.locate(2,false))
- if loc2.z - loc1.z < 0 then
- p = 1
- elseif loc2.x - loc1.x > 0 then
- p = 2
- elseif loc2.z - loc1.z > 0 then
- p = 3
- elseif loc2.x - loc1.x < 0 then
- p = 4
- end
- serialize(p, "heading")
- end
- function dig() --dig and sleeps
- while turtle.dig() == true do
- sleep(0.5)
- end
- end
- function digup()
- while turtle.digUp() == true do
- sleep(0.5)
- end
- end
- function digdown()
- while turtle.digDown() == true do
- sleep(0.5)
- end
- end
- function forward() --forward and sleeps
- while turtle.forward() == false do
- sleep(1)
- turtle.dig()
- end
- if heading == 1 then
- z_c_f = z_c_i - 1
- z_c_i = z_c_f
- elseif heading == 2 then
- x_c_f = x_c_i + 1
- x_c_i = x_c_f
- elseif heading == 3 then
- z_c_f = z_c_i + 1
- z_c_i = z_c_f
- elseif heading == 4 then
- x_c_f = x_c_i - 1
- x_c_i = x_c_f
- end
- serialize(x_c_f, "xfinal")
- serialize(z_c_f, "zfinal")
- end
- function right() --turns right and sleeps
- turtle.turnRight()
- if heading <= 3 then
- heading = heading + 1
- else
- heading = 1
- end
- end
- function left() --turns left and sleeps
- turtle.turnLeft()
- if heading >= 2 then
- heading = heading - 1
- else
- heading = 4
- end
- end
- function down() --goes down and sleeps
- while turtle.down() == false do
- sleep(1)
- turtle.digDown()
- end
- y_c_f = y_c_i - 1
- y_c_i = y_c_f
- serialize(y_c_f, "yfinal")
- end
- function up() --goes up and sleeps
- while turtle.up() == false do
- sleep(1)
- turtle.digUp()
- end
- y_c_f = y_c_i + 1
- y_c_i = y_c_f
- serialize(y_c_f, "yfinal")
- end
- function inspect()
- turtle.inspect()
- end
- function detect()
- turtle.detect()
- end
- function clearinventory()
- for i = 2, 16 do
- turtle.select(i)
- turtle.dropUp()
- end
- turtle.select(1)
- end
- function backtostart()
- x_c_f = x_c_f - x_i
- y_c_f = y_c_f - y_i
- z_c_f = z_c_f - z_i
- print(x_c_f)
- print(y_c_f)
- print(z_c_f)
- if x_c_f == 0 then
- movex = 0
- else
- movex = x_c_f - x_i
- end
- if y_c_f == 0 then
- movey = 0
- else
- movey = y_c_f - y_i
- end
- if z_c_f == 0 then
- movez = 0
- else
- movez = z_c_f - z_i
- end
- --move the turtle to correct y position
- if movey > 0 then
- for i = 1, movey do
- while digdown() == true do
- digdown()
- end
- down()
- end
- else
- for i = -1, movey, -1 do
- while digup() == true do
- digup()
- end
- up()
- end
- end
- --move the turtle to correct x position
- if movex > 0 then
- if heading == 1 then
- left()
- for i = 1, movex do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 2 then
- right()
- right()
- for i = 1, movex do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 3 then
- right()
- for i = 1, movex do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 4 then
- for i = 1, movex do
- while dig() == true do
- dig()
- end
- forward()
- end
- end
- elseif movex == 0 then
- elseif movex < 0 then
- if heading == 1 then
- right()
- for i = -1, movex, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 2 then
- for i = -1, movex, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 3 then
- left()
- for i = -1, movex, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 4 then
- right()
- right()
- for i = -1, movex, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- end
- end
- --move turtle to correct z position
- if movez < 0 then
- if heading == 1 then
- right()
- right()
- for i = -1, movez, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 2 then
- right()
- for i = -1, movez, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 3 then
- for i = -1, movez, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 4 then
- left()
- for i = -1, movez, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- end
- elseif movez == 0 then
- elseif movez > 0 then
- if heading == 1 then
- for i = 1, movez do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 2 then
- left()
- for i = 1, movez do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 3 then
- right()
- right()
- for i = 1, movez do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 4 then
- right()
- for i = 1, movez do
- while dig() == true do
- dig()
- end
- forward()
- end
- end
- end
- end
- function returntowork()
- x_c_f = unserialize("xreturn")
- y_c_f = unserialize("yreturn")
- z_c_f = unserialize("zreturn")
- x_c_f = x_c_f*1
- y_c_f = y_c_f*1
- z_c_f = z_c_f*1
- if x_c_f == 0 then
- movex = 0
- else
- movex = x_c_f - x_i
- end
- if y_c_f == 0 then
- movey = 0
- else
- movey = y_c_f - y_i
- end
- if z_c_f == 0 then
- movez = 0
- else
- movez = z_c_f - z_i
- end
- --move turtle to correct z position
- if movez < 0 then
- if heading == 1 then
- for i = -1, movez, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 2 then
- left()
- for i = -1, movez, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 3 then
- right()
- right()
- for i = -1, movez, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 4 then
- right()
- for i = -1, movez, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- end
- elseif movez == 0 then
- elseif movez > 0 then
- if heading == 1 then
- right()
- right()
- for i = 1, movez do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 2 then
- right()
- for i = 1, movez do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 3 then
- for i = 1, movez do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 4 then
- left()
- for i = 1, movez do
- while dig() == true do
- dig()
- end
- forward()
- end
- end
- end
- --move the turtle to correct x position
- if movex > 0 then
- if heading == 1 then
- right()
- for i = 1, movex do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 2 then
- for i = 1, movex do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 3 then
- left()
- for i = 1, movex do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 4 then
- right()
- right()
- for i = 1, movex do
- while dig() == true do
- dig()
- end
- forward()
- end
- end
- elseif movex == 0 then
- elseif movex < 0 then
- if heading == 1 then
- left()
- for i = -1, movex, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 2 then
- right()
- right()
- for i = -1, movex, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 3 then
- right()
- for i = -1, movex, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- elseif heading == 4 then
- for i = -1, movex, -1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- end
- end
- --move the turtle to correct y position
- if movey > 0 then
- for i = 1, movey do
- while digup() == true do
- digup()
- end
- up()
- end
- else
- for i = -1, movey, -1 do
- while digdown() == true do
- digdown()
- end
- down()
- end
- end
- headingreturn = tonumber(unserialize("headingreturn"))
- while heading ~= headingreturn do
- right()
- end
- end
- function inventorycheck()
- if turtle.getItemCount(16) > 0 then
- serialize(x_c_f, "xreturn")
- serialize(y_c_f, "yreturn")
- serialize(z_c_f, "zreturn")
- serialize(heading, "headingreturn")
- backtostart()
- clearinventory()
- returntowork()
- else
- end
- end
- function refuel()
- if turtle.getItemCount(1) == 0 or turtle.getItemDetail(1).name ~= "minecraft:coal" and turtle.getItemDetail(1).name ~= "actuallyadditions:block_misc") then
- backtostart()
- print("Waiting for fuel to be placed in slot 1.")
- while turtle.getItemCount(1) == 0 or turtle.getItemDetail(1).name ~= "minecraft:coal" do
- sleep(1)
- end
- while turtle.getFuelLevel() < 1000 do
- turtle.select(1)
- turtle.refuel(1)
- end
- returntowork()
- elseif turtle.getItemCount(1) > 0 then
- while turtle.getFuelLevel() < 19900 do
- turtle.select(1)
- turtle.refuel(1)
- sleep(1)
- end
- end
- end
- function digcubebottomleft() --efficiently mines out an area determined by the user
- print("Place coal blocks or coal in slot 1. Also dig a pit trap 2 blocks in front of the turtle in case a mob spawns in front of it. (optional but could slightly speed up process)")
- print("What is the width? this number expands to the right with the first part of the cube being in front of the turtle.")
- w = tonumber(read())
- print("What is the length? This number expands into the area you are excavating.")
- l = tonumber(read())
- print("What is the height? This number is the how many blocks up the cube expands up from starting position")
- h = tonumber(read())
- print("what is the current direction the turtle is facing? (type 1 for north, 2 for east, 3 for south and 4 for west)")
- heading = tonumber(read())
- while dig() == true do --this get the turtle into position
- dig()
- end
- forward()
- if l > w and l > h then --if the cube has a long length like a tunnel this will be the function it follows
- for a = 1, h do
- for b = 1, w do --this digs into the cube
- for c = 1, (l-1) do --this digs the length
- while dig() == true do
- dig()
- end
- forward()
- end
- if w%2 == 1 then
- if b < w then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
- if b < w then
- if a%2 == 1 then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- else
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- end
- end
- else
- end
- end
- end
- if a < h then
- while digup() == true do --this is to go up to next layer
- digup()
- end
- up()
- right()
- right()
- else
- end
- end
- elseif w > l and w > h then -- this is when the width is greater than the length and height
- for d = 1 , l-1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- right()
- for a = 1, h do
- for b = 1, l do --this digs into the cube
- for c = 1, (w-1) do --this digs the length
- while dig() == true do
- dig()
- end
- forward()
- end
- if w%2 == 1 then
- if b < l then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
- if b < l then
- if a%2 == 1 then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- else
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- end
- end
- else
- end
- end
- end
- if a < h then
- while digup() == true do --this is to go up to next layer
- digup()
- end
- up()
- right()
- right()
- else
- end
- end
- elseif h > w and h > l then
- for a = 1, w do
- for b = 1, l do --this digs into the cube
- for c = 1, (h-1) do --this digs the length
- if l%2 == 1 then
- if a%2 == 1 then
- if b%2 == 1 then
- while digup() == true do
- digup()
- end
- up()
- else
- while digdown() == true do
- digdown()
- end
- down()
- end
- else
- if b%2 == 1 then
- while digdown() == true do
- digdown()
- end
- down()
- else
- while digup() == true do
- digup()
- end
- up()
- end
- end
- else
- if b%2 == 1 then
- while digup() == true do
- digup()
- end
- up()
- else
- while digdown() == true do
- digdown()
- end
- down()
- end
- end
- end
- if b < l then
- while dig() == true do
- dig()
- end
- forward()
- inventorycheck()
- refuel()
- else
- end
- end
- if a < w then
- if a%2 == 1 then
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- end
- elseif w == l then
- for a = 1, h do
- for b = 1, w do --this digs into the cube
- for c = 1, (l-1) do --this digs the length
- while dig() == true do
- dig()
- end
- forward()
- end
- if w%2 == 1 then
- if b < w then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
- if b < w then
- if a%2 == 1 then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- else
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- end
- end
- else
- end
- end
- end
- if a < h then
- while digup() == true do --this is to go up to next layer
- digup()
- end
- up()
- right()
- right()
- else
- end
- end
- elseif w == h then
- for d = 1 , l-1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- right()
- for a = 1, h do
- for b = 1, l do --this digs into the cube
- for c = 1, (w-1) do --this digs the length
- while dig() == true do
- dig()
- end
- forward()
- end
- if w%2 == 1 then
- if b < l then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
- if b < l then
- if a%2 == 1 then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- else
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- end
- end
- else
- end
- end
- end
- if a < h then
- while digup() == true do --this is to go up to next layer
- digup()
- end
- up()
- right()
- right()
- else
- end
- end
- elseif h == l then
- for a = 1, h do
- for b = 1, w do --this digs into the cube
- for c = 1, (l-1) do --this digs the length
- while dig() == true do
- dig()
- end
- forward()
- end
- if w%2 == 1 then
- if b < w then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
- if b < w then
- if a%2 == 1 then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- else
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- end
- end
- else
- end
- end
- end
- if a < h then
- while digup() == true do --this is to go up to next layer
- digup()
- end
- up()
- right()
- right()
- else
- end
- end
- elseif w == h and l == h then
- for a = 1, h do
- for b = 1, w do --this digs into the cube
- for c = 1, (l-1) do --this digs the length
- while dig() == true do
- dig()
- end
- forward()
- end
- if w%2 == 1 then
- if b < w then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
- if b < w then
- if a%2 == 1 then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- else
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- end
- end
- else
- end
- end
- end
- if a < h then
- while digup() == true do --this is to go up to next layer
- digup()
- end
- up()
- right()
- right()
- else
- end
- end
- end
- backtostart()
- clearinventory()
- end
- function digcubetopleft() --efficiently mines out an area determined by the user
- print("Place coal blocks or coal in slot 1. Also dig a pit trap 2 blocks in front of the turtle in case a mob spawns in front of it. (optional but could slightly speed up process)")
- print("What is the width? this number expands to the right with the first part of the cube being in front of the turtle.")
- w = tonumber(read())
- print("What is the length? This number expands into the area you are excavating.")
- l = tonumber(read())
- print("What is the height? This number is the how many blocks up the cube expands up from starting position")
- h = tonumber(read())
- print("what is the current direction the turtle is facing? (type 1 for north, 2 for east, 3 for south and 4 for west)")
- heading = tonumber(read())
- while dig() == true do --this get the turtle into position
- dig()
- end
- forward()
- if l > w and l > h then --if the cube has a long length like a tunnel this will be the function it follows
- for a = 1, h do
- for b = 1, w do --this digs into the cube
- for c = 1, (l-1) do --this digs the length
- while dig() == true do
- dig()
- end
- forward()
- end
- if w%2 == 1 then
- if b < w then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
- if b < w then
- if a%2 == 1 then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- else
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- end
- end
- else
- end
- end
- end
- if a < h then
- while digdown() == true do --this is to go up to next layer
- digdown()
- end
- down()
- right()
- right()
- else
- end
- end
- elseif w > l and w > h then -- this is when the width is greater than the length and height
- for d = 1 , l-1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- right()
- for a = 1, h do
- for b = 1, l do --this digs into the cube
- for c = 1, (w-1) do --this digs the length
- while dig() == true do
- dig()
- end
- forward()
- end
- if w%2 == 1 then
- if b < l then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
- if b < l then
- if a%2 == 1 then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- else
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- end
- end
- else
- end
- end
- end
- if a < h then
- while digdown() == true do --this is to go up to next layer
- digdown()
- end
- down()
- right()
- right()
- else
- end
- end
- elseif h > w and h > l then
- for a = 1, w do
- for b = 1, l do --this digs into the cube
- for c = 1, (h-1) do --this digs the length
- if l%2 == 1 then
- if a%2 == 1 then
- if b%2 == 1 then
- while digdown() == true do
- digdown()
- end
- down()
- else
- while digup() == true do
- digup()
- end
- up()
- end
- else
- if b%2 == 1 then
- while digup() == true do
- digup()
- end
- up()
- else
- while digdown() == true do
- digdown()
- end
- down()
- end
- end
- else
- if b%2 == 1 then
- while digdown() == true do
- digdown()
- end
- down()
- else
- while digup() == true do
- digup()
- end
- up()
- end
- end
- end
- if b < l then
- while dig() == true do
- dig()
- end
- forward()
- inventorycheck()
- refuel()
- else
- end
- end
- if a < w then
- if a%2 == 1 then
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- end
- elseif w == l then
- for a = 1, h do
- for b = 1, w do --this digs into the cube
- for c = 1, (l-1) do --this digs the length
- while dig() == true do
- dig()
- end
- forward()
- end
- if w%2 == 1 then
- if b < w then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
- if b < w then
- if a%2 == 1 then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- else
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- end
- end
- else
- end
- end
- end
- if a < h then
- while digdown() == true do --this is to go up to next layer
- digdown()
- end
- down()
- right()
- right()
- else
- end
- end
- elseif w == h then
- for d = 1 , l-1 do
- while dig() == true do
- dig()
- end
- forward()
- end
- right()
- for a = 1, h do
- for b = 1, l do --this digs into the cube
- for c = 1, (w-1) do --this digs the length
- while dig() == true do
- dig()
- end
- forward()
- end
- if w%2 == 1 then
- if b < l then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
- if b < l then
- if a%2 == 1 then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- else
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- end
- end
- else
- end
- end
- end
- if a < h then
- while digdown() == true do --this is to go up to next layer
- digdown()
- end
- down()
- right()
- right()
- else
- end
- end
- elseif h == l then
- for a = 1, h do
- for b = 1, w do --this digs into the cube
- for c = 1, (l-1) do --this digs the length
- while dig() == true do
- dig()
- end
- forward()
- end
- if w%2 == 1 then
- if b < w then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
- if b < w then
- if a%2 == 1 then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- else
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- end
- end
- else
- end
- end
- end
- if a < h then
- while digdown() == true do --this is to go up to next layer
- digdown()
- end
- down()
- right()
- right()
- else
- end
- end
- elseif w == h and l == h then
- for a = 1, h do
- for b = 1, w do --this digs into the cube
- for c = 1, (l-1) do --this digs the length
- while dig() == true do
- dig()
- end
- forward()
- end
- if w%2 == 1 then
- if b < w then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- end
- else -- this is the nightmare scenario where the width is even causing the turns to be different from layer to layer
- if b < w then
- if a%2 == 1 then
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- else
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- end
- else
- if b%2 == 1 then --this checks to see if it needs to go right or left odd b needs to go right
- left()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- left()
- else
- right()
- inventorycheck()
- refuel()
- while dig() == true do
- dig()
- end
- forward()
- right()
- end
- end
- else
- end
- end
- end
- if a < h then
- while digdown() == true do --this is to go up to next layer
- digdown()
- end
- down()
- right()
- right()
- else
- end
- end
- end
- backtostart()
- clearinventory()
- end
- -- MAIN PROGRAM //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- x_i = 0 --this is if you are not using gps and not getting real world coords
- y_i = 0
- z_i = 0
- x_c_f = 0 --stands for *_current_final represents the last position the turtle was at before it stopped mining
- y_c_f = 0
- z_c_f = 0
- x_c_i = 0 --you need x_c_i and such as a placeholder in function forward to keep values increasing or decreasing
- y_c_i = 0
- z_c_i = 0
- print("You can choose from two directions to dig. From top left down and to the right, or from bottom left up and to the right. 1 for top left and 2 for bottom left.")
- direction = tonumber(read())
- if direction == 1 then
- digcubetopleft()
- elseif direction == 2 then
- digcubebottomleft()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement