Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- quarryWidth = 0
- quarryLength = 0
- quarryFloorHeight = 0
- quarryStartHeight = 0
- function forward(dist)
- for i = 1, dist do
- while turtle.forward() == false do
- turtle.dig()
- end
- end
- end
- function up(dist)
- for i = 1, dist do
- while turtle.up() == false do
- turtle.digUp()
- end
- end
- end
- function down(dist)
- for i = 1, dist do
- while turtle.down() == false do
- turtle.digDown()
- end
- end
- end
- function mineLayer(width, length)
- for i = 1, width do
- forward(length - 1)
- if (i % 2) == 1 then
- if i == width then
- break
- end
- turtle.turnRight()
- forward(1)
- turtle.turnRight()
- else
- if i == width then
- break
- end
- turtle.turnLeft()
- forward(1)
- turtle.turnLeft()
- end
- end
- if (width % 2) == 1 then
- turtle.turnLeft()
- turtle.turnLeft()
- forward(length - 1)
- end
- turtle.turnRight()
- forward(width - 1)
- turtle.turnLeft()
- end
- function depositLoot()
- for i = 2, 16 do
- turtle.select(i)
- while (turtle.drop() == false) and (turtle.getItemCount(i) ~= 0) do
- os.sleep(5)
- end
- end
- end
- function refuelFromChest()
- local fuelNeeded = (quarryLength * quarryWidth) + (2 * quarryStartHeight)
- turtle.select(1)
- while refuelToLevel(fuelNeeded) == false do
- while turtle.suckUp() == false do
- os.sleep(5)
- end
- end
- end
- function main()
- drawHeader()
- -- if disk drive exists with disk below turtle get quarry info and start mining
- -- if no disk drive exists prompt the user to build the quarry
- if disk.hasData('bottom') then
- if disk.getLabel('bottom') == "QuarryData" then
- if readQuarryData() == false then
- return
- end
- else
- print("No data disk in drive!")
- return
- end
- else
- if promptBuildQuarry() == false then
- return
- end
- end
- if promptStartMining() == false then
- return
- end
- end
- function promptBuildQuarry()
- drawHeader()
- print("No disk drive or disk below turtle do you want to create a new quarry (y/n)?")
- local input = read()
- if input ~= "y" then
- return false
- end
- return buildQuarry()
- end
- function buildQuarry()
- drawHeader()
- print("Please Ensure these items are at the correct slots in the turtle:")
- print("Slot 1: Any Fuel")
- print("Slot 2: 1 Disk Drive")
- print("Slot 3: 1 Floppy Disk")
- print("Slot 4: 3 Chests")
- print("Slot 5: 1 Lever")
- print()
- print("Are these items present, in their correct quantities, and in their correct locations (y/n)?")
- local input = read()
- if input ~= "y" then
- return false
- end
- print("Starting Setup...")
- os.sleep(3)
- drawHeader()
- -- ensure disk drive is in slot 2
- if (turtle.getItemCount(2) < 1) or not (turtle.getItemDetail(2).name == "computercraft:peripheral" and turtle.getItemDetail(2).damage == 0) then
- print("No Disk Drive in slot 2!")
- return false
- end
- -- ensure floppy disk in slot 3
- if (turtle.getItemCount(3) < 1) or (turtle.getItemDetail(3).name ~= "computercraft:disk_expanded") then
- print("No Floppy Disk in slot 3!")
- return false
- end
- -- ensure 3 chests are in slot 4
- if (turtle.getItemCount(4) < 3) or (turtle.getItemDetail(4).name ~= "minecraft:chest") then
- print("No Chests in slot 4!")
- return false
- end
- -- ensure 3 chests are in slot 4
- if (turtle.getItemCount(5) < 1) or (turtle.getItemDetail(5).name ~= "minecraft:lever") then
- print("No Lever in slot 5!")
- return false
- end
- -- prompt user for width of quarry
- print("Enter the width of the quarry (Max 64).")
- local width = math.floor(tonumber(read()))
- quarryWidth = width
- print()
- -- prompt user for length of quarry
- print("Enter the length of the quarry (Max 64).")
- local length = math.floor(tonumber(read()))
- quarryLength = length
- print()
- -- prompt user for y level
- print("Enter the Y-Level of the turtle.")
- local height = math.floor(tonumber(read()))
- quarryStartHeight = height
- quarryFloorHeight = height
- print()
- -- refuel turtle until the fuel level is 10
- if refuelToLevel(10) == false then
- print("Not enough fuel in slot 1!")
- return false
- end
- print("Placing Disk Drive...")
- -- break the block below the turtle then select the disk drive and place it below the turtle
- turtle.digDown()
- turtle.select(2)
- turtle.placeDown()
- print("Inserting Floppy Disk...")
- -- select the floppy disk and insert it into the disk drive
- turtle.select(3)
- turtle.dropDown(1)
- print("Placing Storage Chests...")
- -- turn 180 then break the block in front of the turtle then select the chest and place it in front of the turtle
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.select(4)
- turtle.place()
- -- move the turtle left one block breaking the block in the way
- turtle.turnLeft()
- forward(1)
- turtle.turnRight()
- -- break the block in front of the turtle then place a chest in front of the turtle
- turtle.dig()
- turtle.place()
- -- move the turtle right one block
- turtle.turnRight()
- forward(1)
- turtle.turnRight()
- print("Placing Fuel Chest...")
- -- turn right then place fuel chest breaking the block in the way
- turtle.digUp()
- turtle.placeUp()
- print("Placing Lever...")
- -- turn left then place lever breaking block in the way
- turtle.select(5)
- turtle.turnLeft()
- turtle.dig()
- turtle.place()
- print("Writing Data To Disk...")
- -- setup the flopy disk to hold info about this quarry
- -- change the name of the disk to QuarryData
- disk.setLabel('bottom', "QuarryData")
- -- write data to the disk
- writeQuarryData()
- print("Depositing Extra Items...")
- -- deposit extra items in the turtles inventory
- turtle.turnLeft()
- depositLoot()
- turtle.turnLeft()
- turtle.turnLeft()
- -- Quarry Setup Finished
- print("Setup Complete!")
- print()
- return true
- end
- function writeQuarryData()
- -- save the path that the disk files can be accessed at
- local diskPath = disk.getMountPath('bottom')
- -- if the data directory doesn't exist on the disk then create one
- if not fs.exists(diskPath .. '/data') then
- fs.makeDir(diskPath .. '/data')
- end
- -- write the width and length of the quarry to a file called QuarryData on the disk
- local size = {}
- size[1] = quarryWidth
- size[2] = quarryLength
- size[3] = quarryStartHeight
- size[4] = quarryFloorHeight
- local file = fs.open(diskPath .. '/data/QuarryData', 'w')
- file.flush()
- file.write(textutils.serialize(size))
- file.close()
- end
- function readQuarryData()
- local mountPath = disk.getMountPath('bottom')
- if fs.exists(mountPath .. '/data/QuarryData') then
- local file = fs.open(mountPath .. '/data/QuarryData', 'r')
- local size = textutils.unserialize(file.readAll())
- quarryWidth = size[1]
- quarryLength = size[2]
- quarryStartHeight = size[3]
- quarryFloorHeight = size[4]
- file.close()
- else
- return false
- end
- end
- function promptStartMining()
- print("Quarry Data received do you want to start mining now (y/n)?")
- local input = read()
- if input ~= "y" then
- return false
- end
- return miningLoop()
- end
- function miningLoop()
- while quarryFloorHeight > 5 do
- drawHeader()
- while redstone.getInput('left') == false do
- drawHeader()
- print("Awaiting redstone signal...")
- os.sleep(5)
- end
- print(quarryStartHeight)
- print(quarryFloorHeight)
- print("Refueling...")
- refuelFromChest()
- print("Entering Quarry...")
- forward(1)
- down(quarryStartHeight - quarryFloorHeight + 1)
- print("Mining Layer...")
- mineLayer(quarryWidth, quarryLength)
- quarryFloorHeight = quarryFloorHeight - 1
- print("Returning To Surface...")
- up(quarryStartHeight - quarryFloorHeight)
- forward(1)
- print("Updating Quarry Data...")
- writeQuarryData()
- print("Depositing Resources...")
- depositLoot()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- drawHeader()
- print("Quarry Complete!")
- return true
- end
- function drawHeader()
- term.clear()
- print("|-------------------------------------|")
- print("| Smart Quarry v0.0 |")
- print("|-------------------------------------|")
- print()
- end
- function refuelToLevel(level)
- turtle.select(1)
- while turtle.getFuelLevel() < level do
- if turtle.refuel(1) == false then
- return false
- end
- end
- return true
- end
- main()
Add Comment
Please, Sign In to add comment