Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- A sub-lava level miner
- by Alphanumeric Sheep Pig
- A branch mining program that
- mines a 2 high branch mine in a roughly
- 100x100 block area to the front and left.
- It places torches along the way, builds a
- floor, ceiling and walls, turns any lava
- to obsidian, can handle sand and gravel,
- and places a chest and offloads its
- inventory along the way when full.
- Before use, give the turtle the following:
- Slot 1: Coal
- Slot 2: Cobblestone
- Slot 3: Chests
- Slot 4: Torches
- Slot 5: Water bucket
- ]]
- ----------------------------------------------------------------------------------
- -- Save starting coords to keep track of location
- x = 0 -- positive right
- y = 0 -- positive forward
- z = 0 -- positive up
- f = 0 -- number of left turns required to return to original direction
- ----------------------------------------------------------------------------------
- -- Functions to replace basic movement commands with shortcuts that keep track of direction
- function up()
- if turtle.up() then
- z=z+1
- return true
- else
- turtle.digUp()
- return false
- end
- end
- function down()
- if turtle.down() then
- z=z-1
- return true
- else
- return false
- end
- end
- function forward()
- if turtle.forward() then
- if f==0 then y=y+1
- elseif f==1 then x=x+1
- elseif f==2 then y=y-1
- elseif f==3 then x=x-1
- end
- return true
- else
- return false
- end
- end
- function back()
- if turtle.back() then
- if f==0 then y=y-1
- elseif f==1 then x=x-1
- elseif f==2 then y=y+1
- elseif f==3 then x=x+1
- end
- return true
- else
- return false
- end
- end
- function left()
- if turtle.turnLeft() then
- f = f+1
- while f > 3 do
- f = f-4
- end
- return true
- else
- return false
- end
- end
- function right()
- if turtle.turnRight() then
- f = f-1
- while f < 0 do
- f = f+4
- end
- return true
- else
- return false
- end
- end
- function forwardDist()
- return x+y
- end
- ----------------------------------------------------------------------------------
- -- Basic actions
- function dig()
- turtle.select(2)
- repeat
- turtle.dig()
- sleep(0.7)
- until forward()
- back()
- end
- function placeTorch()
- left()
- left()
- turtle.select(4)
- turtle.place()
- left()
- left()
- end
- function placeCobble()
- turtle.select(2)
- turtle.place()
- end
- function placeCobbleUp()
- turtle.select(2)
- turtle.placeUp()
- end
- function placeCobbleDown()
- turtle.select(2)
- turtle.placeDown()
- end
- function placeCobbleSides()
- left()
- placeCobble()
- right()
- right()
- placeCobble()
- left()
- end
- function fuel()
- if turtle.getFuelLevel() < 50 then
- turtle.select(1)
- turtle.refuel(1)
- end
- end
- function waterAhead()
- dig()
- turtle.select(5)
- if turtle.place() == false then
- exit()
- end
- turtle.place()
- end
- function waterHere()
- back()
- waterAhead()
- forward()
- end
- function fixheight()
- while z>0 do
- print("In the wrong Place")
- back()
- down()
- end
- end
- function faceFront()
- while f > 0 do
- left()
- end
- end
- function reset()
- faceFront()
- fixheight()
- end
- function noWalls()
- placeCobbleDown()
- up()
- placeCobbleUp()
- down()
- end
- function walls()
- placeCobbleDown()
- placeCobbleSides()
- up()
- placeCobbleUp()
- placeCobbleSides()
- down()
- end
- function doubleWater()
- waterAhead()
- up()
- waterAhead()
- -- waterHere()
- down()
- end
- function tunnel()
- forward()
- walls()
- doubleWater()
- end
- function wallFront()
- placeCobble()
- up()
- placeCobble()
- down()
- end
- function tunnelWithoutWalls()
- forward()
- noWalls()
- doubleWater()
- end
- function offload()
- up()
- waterHere()
- down()
- back()
- left()
- tunnelWithoutWalls()
- tunnelWithoutWalls()
- wallFront()
- back()
- turtle.select(3)
- turtle.place()
- for slot = 6,16,1 do
- turtle.select(slot)
- turtle.drop()
- end
- turtle.select(2)
- right()
- end
- function checkInventory()
- for slot = 1,5,1 do
- if turtle.getItemCount(slot) == 0 then
- print("Out of materials")
- exit()
- end
- end
- if turtle.getItemCount(16) > 0 then
- offload()
- end
- end
- ----------------------------------------------------------------------------------
- -- Advanced functions
- function branch(l)
- for i = 1,l,1 do
- fuel()
- tunnel()
- fixheight()
- if forwardDist()%13==0 then
- placeTorch()
- end
- checkInventory()
- print("Moved: ",x," left, ",y," forward, ",z," up.")
- print()
- end
- end
- function mine(n,m)
- branch(n)
- wallFront()
- left()
- tunnelWithoutWalls()
- branch(m)
- wallFront()
- left()
- tunnelWithoutWalls()
- branch(n)
- wallFront()
- right()
- tunnelWithoutWalls()
- branch(m)
- wallFront()
- right()
- tunnelWithoutWalls()
- end
- for i = 1,12,1 do
- mine(100,4)
- end
- print("Done")
Advertisement
Add Comment
Please, Sign In to add comment