Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --variables
- atHome = true
- maxX = 50
- maxY = 50
- distanceDown = 90
- distanceUp = 15
- on = true
- requiredFuel = 0
- digX = 0
- digY = 0
- --functions
- function refuel()
- requiredFuel = (digX * 2)+(digY * 2)+200
- turtle.turnLeft()
- turtle.select(16)
- while turtle.getFuelLevel() < requiredFuel do
- shell.run("clear")
- print ("Getting Fuel")
- turtle.suck(64)
- turtle.refuel()
- print("Fuel Level: " .. tostring(turtle.getFuelLevel()) .. " / ".. tostring(requiredFuel))
- end
- shell.run("clear")
- turtle.select(1)
- turtle.turnRight()
- end
- function getDigLocation()
- shell.run("clear")
- if atHome == true then
- tmp = http.get( "http://192.168.1.2/cc/dig3/x.php" )
- digX = tonumber(tmp.readAll())
- tmp = http.get( "http://192.168.1.2/cc/dig3/y.php" )
- digY = tonumber(tmp.readAll())
- else
- tmp = http.get( "http://cablepost.ddns.net/cc/dig3/x.php" )
- digX = tonumber(tmp.readAll())
- tmp = http.get( "http://cablepost.ddns.net/cc/dig3/y.php" )
- digY = tonumber(tmp.readAll())
- end
- print("Dig location is: X="..tostring(digX)..",Y="..tostring(digY))
- end
- function increaceDigLocation()
- if atHome == true then
- http.get( "http://192.168.1.2/cc/dig3/y1.php" )
- http.get( "http://192.168.1.2/cc/dig3/y1.php" )
- if digY >= maxY then
- http.get( "http://192.168.1.2/cc/dig3/resetY.php" )
- http.get( "http://192.168.1.2/cc/dig3/x1.php" )
- end
- if digX >= maxX then
- http.get( "http://192.168.1.2/cc/dig3/reset.php" )
- print("digging complete")
- on = false
- end
- else
- http.get( "http://cablepost.ddns.net/cc/dig3/y1.php" )
- http.get( "http://cablepost.ddns.net/cc/dig3/y1.php" )
- if digY >= maxY then
- http.get( "http://cablepost.ddns.net/cc/dig3/resetY.php" )
- http.get( "http://cablepost.ddns.net/cc/dig3/x1.php" )
- end
- if digX >= maxX then
- http.get( "http://cablepost.ddns.net/cc/dig3/reset.php" )
- print("digging complete")
- on = false
- end
- end
- end
- function drop()
- shell.run("clear")
- turtle.turnRight()
- for i = 1,16 do
- turtle.select(i)
- local data = turtle.getItemDetail()
- if data then
- print(data.name)
- if data.name == "minecraft:coal" then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.drop(64)
- turtle.turnLeft()
- turtle.turnLeft()
- end
- end
- turtle.drop(64)
- end
- turtle.select(1)
- turtle.turnLeft()
- end
- function dig()
- shell.run("clear")
- print("Digging...")
- print("Fuel Level: " .. tostring(turtle.getFuelLevel()) .. " / ".. tostring(requiredFuel))
- print("Dig location is: X="..tostring(digX)..",Y="..tostring(digY))
- turtle.select(1)
- print("Going up")
- timesM = 0
- while timesM <= distanceUp do
- turtle.up()
- timesM = timesM + 1
- end
- turtle.turnRight()
- print("matching X axis")
- timesM = 0
- while timesM <= digX do
- turtle.dig()
- turtle.forward()
- timesM = timesM + 1
- end
- turtle.turnLeft()
- print("Matching Y axis")
- timesM = 0
- while timesM <= digY do
- turtle.dig()
- turtle.forward()
- timesM = timesM + 1
- end
- print("going down")
- timesM = 0
- while timesM <= distanceDown do
- turtle.dig()
- turtle.digDown()
- turtle.down()
- timesM = timesM + 1
- end
- turtle.dig()
- print("going up")
- timesM = 0
- while timesM <= 80 do
- while turtle.detectUp() do
- print("There is a block above me.")
- turtle.digUp()
- end
- turtle.up()
- timesM = timesM + 1
- end
- print("backing-up to home")
- timesM = 0
- while timesM <= digY do
- turtle.back()
- timesM = timesM + 1
- end
- turtle.turnRight()
- timesM = 0
- while timesM <= digX do
- turtle.back()
- timesM = timesM + 1
- end
- turtle.turnLeft()
- print("returning to ground")
- on2 = true
- while on2 == true do
- turtle.down()
- if turtle.detectDown() then
- break
- end
- end
- end
- function checkEnd()
- shell.run("clear")
- if turtle.detect() then
- turtle.dig()
- turtle.turnRight()
- turtle.select(1)
- turtle.drop(64)
- --drop()
- turtle.turnLeft()
- on = false
- end
- end
- --script
- while on == true do
- getDigLocation()
- refuel()
- dig()
- drop()
- increaceDigLocation()
- checkEnd()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement