Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --=======================================Standard Lbrary=====================================--
- function smartFuel()
- if turtle.getFuelLevel() <= 0 then
- onSlot = turtle.getSelectedSlot()
- while not turtle.refuel(1) do
- onSlot = onSlot + 1
- if onSlot == 17 then
- onSlot = 1
- end
- turtle.select(onSlot)
- end
- end
- end
- function smartFor()
- while not turtle.forward() do
- turtle.attack()
- turtle.dig()
- smartFuel()
- end
- end
- function smartUp()
- while not turtle.up() do
- turtle.attackUp()
- turtle.digUp()
- smartFuel()
- end
- end
- function smartDown()
- while not turtle.down() do
- turtle.attackDown()
- turtle.digDown()
- smartFuel()
- cleanse()
- end
- end
- function smartMove(dir)
- if dir == -1 then
- turtle.turnLeft()
- smartFor()
- elseif dir == 1 then
- turtle.turnRight()
- smartFor()
- elseif dir == 2 then
- smartFor()
- elseif dir == -2 then
- turtle.turnRight()
- turtle.turnRight()
- smartFor()
- elseif dir == 3 then
- smartUp()
- elseif dir == -3 then
- smartDown()
- end
- end
- --=======================================CoodLibrary==========================-
- --start with "initCoords
- --====initCoords=====--
- function initCoords()
- x = 0
- y = 0
- z = 0
- --0 is forwards, 1 is left, goes clockwise to 3
- facing = 0
- --used to remember location before returning to origin
- tempX = 0
- tempY = 0
- tempZ = 0
- tempFacing = 0
- end
- function trackedFor()
- smartFor()
- if facing == 0 then
- y = y+1
- elseif facing == 1 then
- x = x+1
- elseif facing == 2 then
- y = y-1
- elseif facing == 3 then
- x = x-1
- end
- end
- function trackedUp()
- smartUp()
- z = z+1
- end
- function trackedDown()
- smartDown()
- z = z-1
- end
- function trackedRight()
- changeFacing(1)
- turtle.turnRight()
- end
- function trackedLeft()
- changeFacing(-1)
- turtle.turnLeft()
- end
- function trackedMove(dir)
- if dir == -1 then
- trackedLeft()
- trackedFor()
- elseif dir == 1 then
- trackedRight()
- trackedFor()
- elseif dir == 2 then
- trackedFor()
- elseif dir == -2 then
- trackedRight()
- trackedRight()
- trackedFor()
- elseif dir == 3 then
- trackedUp()
- elseif dir == -3 then
- trackedDown()
- end
- end
- function changeFacing(change)
- facing = facing + change
- facing = facing % 4
- end
- function face(targetFacing)
- while facing ~= targetFacing do
- turtle.turnRight()
- changeFacing(1)
- end
- end
- function toCoords(tarX,tarY,tarZ,tarFace)
- if z > tarZ then
- for i=tarZ+1,z do
- trackedMove(-3)
- end
- elseif z < tarZ then
- for i=z,tarZ-1 do
- trackedMove(3)
- end
- end
- if y > tarY then
- face(2)
- for i=tarY+1,y do
- trackedMove(2)
- end
- elseif y < tarY then
- face(0)
- for i=y,tarY-1 do
- trackedMove(2)
- end
- end
- if x > tarX then
- face(3)
- for i=tarX+1,x do
- trackedMove(2)
- end
- elseif x < tarX then
- face(1)
- for i=x,tarX-1 do
- trackedMove(2)
- end
- end
- face(tarFace)
- end
- function saveCoords()
- tempX = x
- tempY = y
- tempZ = z
- tempFacing = facing
- end
- function toSavedCoords()
- toCoords(tempX,tempY,tempZ,tempFacing)
- end
- --=======================================Quarry Functions=====================================--
- --======inputVars======--
- function inputVars()
- print("For the program to work, make sure the turtle's fuel is placed in the upper-left slot, and a chest is placed directly behind the turtle's starting position.")
- print("How far forwards from the turtle do you want the quarry to go?")
- CHUNKS = tonumber(read())/4
- print("How far to the left of the turtle do you want the quarry to go?")
- PITS = tonumber(read())/5
- print("How far do you want the turtle to dive before starting the quarry?")
- DIVE = tonumber(read())
- print("How deep is the quarry?")
- DEPTH = tonumber(read())
- coalEstimate = math.ceil(((((((6+(DEPTH*2))*CHUNKS)*2)*PITS)+(DIVE*2))/80)*1.1)
- print("This quarry will require approximately " .. tostring(coalEstimate) .. " coal to complete. Is what you entered correct? Enter 'N' to re enter input, or any other button to start quarry")
- if read() == "N" then
- inputVars()
- end
- end
- DEPTH = 1
- --how deep do I go before I start the quarry?
- DIVE = 0
- --which ores not to mine
- blackList = {"minecraft:stone","minecraft:grass","minecraft:dirt","minecraft:sand","minecraft:gravel","minecraft:sandstone","minecraft:cobblestone"}
- --copper, uran,yellorite,marble,tin,lead, alu, silver, quartz
- --======dump======--
- function dump()
- --becomes true if every slot has non-blacklisted items
- local full = true
- for x = 1,16 do
- itemData = turtle.getItemDetail(x)
- if itemData then
- if onBlackList(itemData.name) then
- turtle.select(x)
- turtle.drop()
- full = false
- end
- end
- end
- if full then
- saveCoords()
- toCoords(0,0,0,2)
- storeGoods()
- toSavedCoords()
- end
- end
- --======hasRoom======--
- --returns if no slot is empty
- function hasRoom()
- for x = 1,16 do
- if turtle.getItemCount(x) == 0 then
- return true
- end
- end
- return false
- end
- --======onBlackList======--
- function onBlackList(target)
- for z = 0,table.getn(blackList) do
- if target == blackList[z] then
- return true
- end
- end
- return false
- end
- --======smartComp======--
- function smartComp()
- local sucess, data = turtle.inspect()
- if sucess then
- if not onBlackList(data.name) then
- turtle.dig()
- end
- end
- end
- --=====storeGoods======--
- --excludes slot 1, saved for fuel
- --call when facing chest
- function storeGoods()
- for c = 2, 16 do
- turtle.select(c)
- turtle.drop()
- end
- end
- --======Store======--
- function store()
- turtle.dig()
- turtle.select(1)
- turtle.place()
- dropAll()
- turtle.select(1)
- turtle.dig()
- end
- --======cleanse======--
- function cleanse()
- data = turtle.getItemDetail(16)
- if data then
- dump()
- --store()
- end
- end
- --======smartMine======--
- function smartMine(dir)
- trackedMove(3*dir)
- smartComp()
- turtle.turnRight()
- smartComp()
- turtle.turnRight()
- smartComp()
- turtle.turnRight()
- smartComp()
- turtle.turnRight()
- end
- --======Scale======--
- --must be facing "east"
- function scale(dir)
- for i = 0, DEPTH, 1 do
- if dir == -1 then
- smartMine(-1)
- elseif dir == 1 then
- smartMine(1)
- end
- end
- trackedMove(1)
- trackedMove(-1)
- trackedMove(2)
- end
- --======chunk(2 holes in the ground)======--
- function chunk()
- scale(-1)
- scale(1)
- end
- --======Slice(a line of some chunks)======--
- --1 is west, -1 is east
- function slice(dir)
- for j = 0,CHUNKS-1 do
- chunk()
- end
- if dir == 1 then
- trackedMove(-1)
- trackedMove(2)
- trackedMove(2)
- trackedMove(-1)
- elseif dir == -1 then
- trackedMove(1)
- trackedMove(2)
- trackedMove(1)
- end
- end
- --======goBack======--
- function goBack()
- trackedMove(1)
- for v = 1, (PITS*5)-1 do
- trackedMove(2)
- end
- end
- --======pit(one or more slices)======--
- function pit()
- slice(1)
- slice(-1)
- end
- --===================Function Start========================-
- initCoords()
- inputVars()
- for i = 1, DIVE do
- trackedMove(-3)
- end
- for l = 1, PITS do
- pit()
- end
- --goBack()
- --for i = 1, DIVE do
- -- trackedMove(3)
- --end
- toCoords(0,0,0,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement