Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ComputerCraft Mining Turtle Script
- -- Mines a 5x5 grid of shafts, each 30 blocks deep
- -- Harvests non-standard blocks, refuels with coal, and manages inventory
- -- Configuration
- local shaftDepth = 30
- local gridSize = 5
- local moveBetweenShafts = 2
- local chestLocation = "back" -- Direction where the chest is placed relative to starting position
- -- Block Types to Ignore
- local ignoredBlocks = {
- ["minecraft:stone"] = true,
- ["minecraft:granite"] = true,
- ["minecraft:diorite"] = true,
- ["minecraft:andesite"] = true,
- ["minecraft:chest"] = true,
- ["minecraft:gravel"] = true, -- Added gravel to ignored blocks
- ["minecraft:sand"] = true, -- Added sand to ignored blocks
- ["minecraft:dirt"] = true -- Added dirt to ignored blocks
- }
- -- Initialize variables
- local currentShaft = 1
- local totalShafts = gridSize * gridSize
- local startX, startY, startZ = 0, 0, 0 -- Starting coordinates (can be extended if needed)
- local miningPosition = {x = 0, y = 0, z = 0}
- -- Utility Functions
- -- Function to turn right
- local function turnRight()
- turtle.turnRight()
- end
- -- Function to turn left
- local function turnLeft()
- turtle.turnLeft()
- end
- -- Function to move forward with digging if needed
- local function moveForward()
- while not turtle.forward() do
- turtle.dig()
- sleep(0.5)
- end
- end
- -- Function to move backward with digging if needed
- local function moveBackward()
- while not turtle.back() do
- turtle.dig()
- sleep(0.5)
- end
- end
- -- Function to move up with digging if needed
- local function moveUp()
- while not turtle.up() do
- turtle.digUp()
- sleep(0.5)
- end
- end
- -- Function to move down with digging if needed
- local function moveDown()
- while not turtle.down() do
- turtle.digDown()
- sleep(0.5)
- end
- end
- -- Function to inspect and harvest blocks around the turtle
- local function harvestSurroundings()
- for i = 1, 4 do
- turtle.turnRight()
- local success, data = turtle.inspect()
- if success then
- local blockName = data.name
- if not ignoredBlocks[blockName] then
- turtle.dig()
- sleep(0.5)
- -- Check if the block was coal
- if blockName:find("coal") then
- turtle.select(1) -- Assuming slot 1 is always coal
- if not turtle.refuel(1) then
- -- If can't refuel, keep the coal in inventory
- -- Implement logic if needed
- end
- end
- end
- end
- end
- -- Return to original orientation
- for i = 1, 4 do
- turtle.turnLeft()
- end
- end
- -- Function to check if inventory is full
- local function isInventoryFull()
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- return false
- end
- end
- return true
- end
- -- Function to return to the starting position of a shaft
- local function returnToStart(depth)
- for i = 1, depth do
- moveUp()
- end
- end
- -- Function to deposit items into chest
- local function depositItems()
- -- Save current position and orientation
- local originalDirection = 0 -- 0: forward, 1: right, 2: back, 3: left
- -- Adjust based on current orientation if needed
- -- Move to chest
- turtle.turnRight()
- moveForward()
- -- Deposit all items except the first slot (coal)
- for i = 2, 16 do
- turtle.select(i)
- if turtle.getItemCount(i) > 0 then
- turtle.drop()
- end
- end
- -- Return to mining position
- moveBackward()
- turtle.turnLeft()
- end
- -- Function to mine a single shaft
- local function mineShaft()
- -- Mine down
- for i = 1, shaftDepth do
- if isInventoryFull() then
- depositItems()
- end
- harvestSurroundings()
- moveDown()
- end
- -- Mine back up
- returnToStart(shaftDepth)
- end
- -- Function to navigate the grid
- local function navigateGrid(shaftNumber)
- if shaftNumber % gridSize ~= 0 then
- -- Move to next shaft in the row
- for i = 1, moveBetweenShafts do
- moveForward()
- end
- else
- -- Move to next row
- if shaftNumber < totalShafts then
- if math.floor((shaftNumber - 1) / gridSize) % 2 == 0 then
- -- Even row: turn right, move forward, turn right
- turnRight()
- moveForward()
- turnRight()
- else
- -- Odd row: turn left, move forward, turn left
- turnLeft()
- moveForward()
- turnLeft()
- end
- end
- end
- end
- -- Main Mining Loop
- for shaft = 1, totalShafts do
- mineShaft()
- navigateGrid(shaft)
- end
- -- After mining all shafts, return to starting position
- -- Implement any additional logic if needed
- print("Mining operation completed.")
Advertisement
Advertisement