Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- X = 0
- Y = 0
- Z = 0
- FACE = 0 --North=0,East=1,South=2,West=3
- HOME = {-659, 70, 75, 3}
- ORE_DEPOT = {-667, 70, 61, 3}
- COAL_DEPOT = {-667, 70, 64, 3}
- DIAMOND_DEPOT = {-667, 70, 67, 3}
- REDSTONE_DEPOT = {-667, 70, 70, 3}
- OTHER_DEPOT = {-667, 70, 82, 3}
- MINE_STAGING_AREA = {-661,70,37,0}
- MINE_EXIT_AREA = {-662,70,37,0}
- FURNACE_ROW_START = {-649,70,77}
- STOPWATCH = 0
- NOBREAK = {"minecraft:chest","minecraft:furnace","computercraft:turtle_expanded","minecraft:bedrock"}
- TRASH = {"minecraft:cobblestone","minecraft:stone","minecraft:dirt","minecraft:sand",
- "minecraft:sandstone","chisel:limestone2","minecraft:red_sandstone","chisel:marble2",
- "minecraft:gravel","minecraft:quartz","minecraft:flint"}
- ORES = {"minecraft:gold_ore","minecraft:iron_ore","thermalfoundation:ore","ic2:blockmetal",
- "galacticraftcore:basic_block_core"}
- KEEP = {"minecraft:gold_ore","minecraft:iron_ore","minecraft:diamond","minecraft:coal","minecraft:redstone",
- "minecraft:element_77","ic2:itemoreiridium","minecraft:emerald","minecraft:diamond_ore","minecraft:redstone_ore",
- "minecraft:lit_redstone_ore","minecraft:coal_ore","minecraft:emerald_ore"}
- function isTrash(name)
- for _,v in pairs(KEEP) do
- if v == name then
- return false
- end
- end
- return true
- end
- function dontBreak(block)
- for _,v in pairs(NOBREAK) do
- if v == name then
- return true
- end
- end
- return false
- end
- function isOre(name)
- for _,v in pairs(ORES) do
- if v == name then
- return true
- end
- end
- return false
- end
- function getCurrentLocation()
- local a = {X,Y,Z,FACE}
- return a
- end
- function determineLocation()
- local x,y,z = gps.locate()
- if not x then
- X,Y,Z,FACE = getInitialCoordinates()
- else
- X=x
- Y=y
- Z=z
- findFacing()
- end
- end
- function getInitialCoordinates()
- print("Input x position: ")
- local x = tonumber(read())
- print("Input y position: ")
- local y = tonumber(read())
- print("Input z position: ")
- local z = tonumber(read())
- print("Input facing position: ")
- local face = tonumber(read())
- return x,y,z,face
- end
- function findFacing()
- local x1 = X
- local z1 = Z
- turtle.forward()
- local x2,y2,z2 = gps.locate()
- if x2>x1 then
- FACE = 1
- elseif x2<x1 then
- FACE = 3
- elseif z2>z1 then
- FACE = 2
- elseif z2<z1 then
- FACE = 0
- else
- print("UNABLE TO RESOLVE FACING DIRECTION")
- end
- turtle.back()
- end
- function turnTowards(dir)
- if(dir==FACE) then
- return
- end
- if dir == (FACE +1)%4 then
- if(turtle.turnRight()) then
- FACE = (FACE+1)%4
- end
- else
- if turtle.turnLeft() then
- FACE = (FACE-1)%4
- end
- end
- end
- function updatePosition()
- if FACE==0 then
- Z=Z-1
- end
- if FACE==1 then
- X=X+1
- end
- if FACE==2 then
- Z=Z+1
- end
- if FACE==3 then
- X=X-1
- end
- end
- function updateAltitude(num)
- Y=Y+num
- end
- function smartMoveForward()
- STOPWATCH = STOPWATCH + 1
- local blockPresent, data = turtle.inspect()
- if blockPresent then
- if dontBreak(data.name) then
- smartMoveUp()
- smartMoveForward()
- smartMoveForward()
- smartMoveDown()
- else
- turtle.dig()
- end
- end
- if turtle.forward() then
- updatePosition()
- end
- end
- function smartMoveUp()
- local blockPresent, data = turtle.inspectUp()
- if blockPresent then
- if dontBreak(data.name) then
- smartMoveNorth()
- smartMoveUp()
- smartMoveUp()
- smartMoveSouth()
- else
- turtle.digUp()
- end
- end
- if turtle.up() then
- updateAltitude(1)
- end
- end
- function password()
- print("Enter password: ")
- while true do
- pass = tonumber(read())
- if pass==4794 then
- return true
- end
- end
- end
- function smartMoveDown()
- local blockPresent, data = turtle.inspectDown()
- if blockPresent then
- if dontBreak(data.name) then
- smartMoveNorth()
- smartMoveDown()
- smartMoveDown()
- smartMoveSouth()
- else
- turtle.digDown()
- end
- end
- if turtle.down() then
- updateAltitude(-1)
- end
- end
- function smartMoveWest()
- while FACE~=3 do
- turnTowards(3)
- end
- return smartMoveForward()
- end
- function smartMoveEast()
- while FACE~=1 do
- turnTowards(1)
- end
- return smartMoveForward()
- end
- function smartMoveNorth()
- while FACE~=0 do
- turnTowards(0)
- end
- return smartMoveForward()
- end
- function smartMoveSouth()
- while FACE~=2 do
- turnTowards(2)
- end
- return smartMoveForward()
- end
- function inspectUp()
- return turtle.inspectUp()
- end
- function inspectDown()
- return turtle.inspectDown()
- end
- function inspectWest()
- while FACE~=3 do
- turnTowards(3)
- end
- return turtle.inspect()
- end
- function inspectEast()
- while FACE~=1 do
- turnTowards(1)
- end
- return turtle.inspect()
- end
- function inspectNorth()
- while FACE~=0 do
- turnTowards(0)
- end
- return turtle.inspect()
- end
- function inspectSouth()
- while FACE~=2 do
- turnTowards(2)
- end
- return turtle.inspect()
- end
- function moveto(loc)
- for i=1,50 do
- for j=1,100 do
- if Y>loc[2] then
- smartMoveDown()
- end
- if Y<loc[2] then
- smartMoveUp()
- end
- end
- for j=1,100 do
- if X>loc[1] then
- smartMoveWest()
- end
- if X<loc[1] then
- smartMoveEast()
- end
- end
- for j=1,100 do
- if Z>loc[3] then
- smartMoveNorth()
- end
- if Z<loc[3] then
- smartMoveSouth()
- end
- end
- while FACE~=loc[4] do
- turnTowards(loc[4])
- end
- end
- end
- function surfaceWalk(loc)
- local block,data = turtle.inspectDown()
- if not block() then
- smartMoveDown()
- end
- block,data = turtle.inspect()
- end
- function depositMaterials()
- moveto(ORE_DEPOT)
- for i=1,16 do
- if(turtle.getItemCount(i)>0) then
- if isOre(turtle.getItemDetail(i).name) then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- moveto(COAL_DEPOT)
- for i=1,16 do
- if(turtle.getItemCount(i)>0) then
- if turtle.getItemDetail(i).name=="minecraft:coal" then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- moveto(DIAMOND_DEPOT)
- for i=1,16 do
- if(turtle.getItemCount(i)>0) then
- if turtle.getItemDetail(i).name=="minecraft:diamond" then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- moveto(REDSTONE_DEPOT)
- for i=1,16 do
- if(turtle.getItemCount(i)>0) then
- if turtle.getItemDetail(i).name=="minecraft:redstone" then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- moveto(OTHER_DEPOT)
- for i=2,16 do
- if(turtle.getItemCount(i)>0) then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- function veinFollow()
- local initialFacing = FACE
- local success,data = turtle.inspectUp()
- if success and not isTrash(data.name) then
- smartMoveUp()
- veinFollow()
- smartMoveDown()
- end
- success,data = turtle.inspectDown()
- if success and not isTrash(data.name) then
- smartMoveDown()
- veinFollow(material)
- smartMoveUp()
- end
- success,data = inspectNorth()
- if success and not isTrash(data.name) then
- smartMoveNorth()
- veinFollow()
- smartMoveSouth()
- end
- success,data = inspectEast()
- if success and not isTrash(data.name) then
- smartMoveEast()
- veinFollow()
- smartMoveWest()
- end
- success,data = inspectSouth()
- if success and not isTrash(data.name) then
- smartMoveSouth()
- veinFollow()
- smartMoveNorth()
- end
- success,data = inspectWest()
- if success and not isTrash(data.name) then
- smartMoveWest()
- veinFollow()
- smartMoveEast()
- end
- turnTowards(initialFacing)
- turnTowards(initialFacing)
- end
- function dumpTrash()
- for i=2,16 do
- if(turtle.getItemCount(i)>0) then
- if isTrash(turtle.getItemDetail(i).name) then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- end
- function inventoryFull()
- for i=1,16 do
- if turtle.getItemCount(i)==0 then
- return false
- end
- end
- return true
- end
- function isFullLava(success,data)
- return success and (data.name=="minecraft:lava" or data.name=="minecraft:flowing_lava") and data.state.level==0
- end
- function collectLava()
- local initialFacing = FACE
- print("collecting lava")
- print(turtle.getFuelLevel())
- if isFullLava(inspectUp()) and turtle.getFuelLevel() < 19000 then
- turtle.select(1)
- turtle.placeUp()
- turtle.refuel()
- smartMoveUp()
- collectLava()
- smartMoveDown()
- end
- if isFullLava(inspectDown()) and turtle.getFuelLevel() < 19000 then
- turtle.select(1)
- turtle.placeDown()
- turtle.refuel()
- smartMoveDown()
- collectLava()
- smartMoveUp()
- end
- if isFullLava(inspectNorth()) and turtle.getFuelLevel() < 19000 then
- turtle.select(1)
- turtle.place()
- turtle.refuel()
- smartMoveNorth()
- collectLava()
- smartMoveSouth()
- end
- if isFullLava(inspectEast()) and turtle.getFuelLevel() < 19000 then
- turtle.select(1)
- turtle.place()
- turtle.refuel()
- smartMoveEast()
- collectLava()
- smartMoveWest()
- end
- if isFullLava(inspectSouth()) and turtle.getFuelLevel() < 19000 then
- turtle.select(1)
- turtle.place()
- turtle.refuel()
- smartMoveSouth()
- collectLava()
- smartMoveNorth()
- end
- if isFullLava(inspectWest()) and turtle.getFuelLevel() < 19000 then
- turtle.select(1)
- turtle.place()
- turtle.refuel()
- smartMoveWest()
- collectLava()
- smartMoveEast()
- end
- turnTowards(initialFacing)
- turnTowards(initialFacing)
- end
- function mine(loc)
- success,data = turtle.inspectUp()
- if success then
- if isFullLava(success,data) then
- collectLava()
- end
- if not isTrash(data.name) then
- turtle.digUp()
- smartMoveUp()
- veinFollow()
- smartMoveDown()
- end
- end
- success,data = turtle.inspectDown()
- if success then
- if isFullLava(success,data) then
- collectLava()
- end
- if not isTrash(data.name) then
- turtle.digDown()
- smartMoveDown()
- veinFollow()
- smartMoveUp()
- end
- end
- success,data = turtle.inspect()
- if success then
- if isFullLava(success,data) then
- collectLava()
- end
- if not isTrash(data.name) then
- turtle.dig()
- smartMoveForward()
- veinFollow()
- else
- turtle.dig()
- end
- end
- end
- function fillInventory()
- for i=2,16 do
- turtle.select(i)
- turtle.suck()
- end
- end
- function mineLayer(loc,width,depth)
- moveto(loc)
- for j=1,(width/2) do
- for i=1,depth do
- smartMoveNorth()
- mine()
- end
- smartMoveWest()
- for i=1,depth do
- smartMoveSouth()
- mine()
- end
- smartMoveWest()
- dumpTrash()
- end
- end
- function mineLoop()
- moveto(MINE_STAGING_AREA)
- local mineLocation = {X+math.random(-100,100), 15, Z+math.random(-100,100), FACE}
- moveto(mineLocation)
- while turtle.getFuelLevel()>1000 and not inventoryFull() and STOPWATCH<2000 do
- mineLayer(mineLocation,20,20)
- if mineLocation[2] >= 9 then
- mineLocation[2] = mineLocation[2]-3
- else
- if turtle.getFuelLevel()>12000 then
- mineLocation = {X+math.random(-20,20), 40+math.random(-10,10), Z+math.random(-20,20), FACE}
- else
- mineLocation = {X+math.random(-20,20), 15, Z+math.random(-20,20), FACE}
- end
- end
- end
- moveto(MINE_EXIT_AREA)
- depositMaterials()
- moveto(HOME)
- end
- function main()
- determineLocation()
- while turtle.getFuelLevel()>2000 do
- mineLoop()
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement