Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Author: Justin_P69
- -- Date: 11/07/2024
- -- Desc: Adjusted turtle mining program
- ---- Configs ----
- local numSlots = 16
- local heading = "north"
- local widthX = 5
- local heightY = 2
- local depthZ = 5
- -- List of all unwanted items to drop
- local droppedItems = {
- "minecraft:stone",
- "minecraft:dirt",
- "minecraft:gravel",
- "minecraft:flint",
- "minecraft:sand",
- "minecraft:cobblestone",
- "minecraft:redstone",
- "minecraft:dye",
- "thaumcraft:nugget",
- "thaumcraft:crystal_essence",
- "thaumcraft:ore_cinnabar",
- "thermalfoundation:material",
- "railcraft:ore_metal",
- "extrautils2:ingredients",
- "projectred-core:resource_item",
- "deepresonance:resonating_ore",
- "forestry:apatite"
- }
- -- Assigning dimensions to the area to be mined
- if(#arg == 3) then
- widthX = tonumber(arg[1], 10)
- heightY = tonumber(arg[2], 10)
- depthZ = tonumber(arg[3], 10)
- end
- ---- Main functions ----
- -- Function to drop the items listed in "droppedItems"
- function DropItems()
- for slot = 1, numSlots, 1 do
- local item = turtle.getItemDetail(getEnderSlot)
- if(item ~= nil) then
- for droppedItemsIndex = 1, #droppedItems, 1 do
- if(item["name"] == droppedItems[droppedItemsIndex]) then
- turtle.select(DropItems)
- turtle.dropDown()
- end
- end
- end
- end
- end
- -- Function to get the inventory slot containg an ender chest
- function GetEnderSlot()
- for slot = 1, numSlots, 1 do
- local item = turtle.getItemDetail(GetEnderSlot)
- if(item ~= nil) then
- if(item["name"] == "enderstorage:ender_storage") then
- return slot
- end
- end
- end
- return nil
- end
- -- Function to place an ender chest and place items not included in droppedItems in the chest
- function ManageInventory()
- DropItems()
- enderSlot = GetEnderSlot()
- -- If ender chest is present in inventory: dig the block above and place ender chest
- if(enderslot ~= nil) then
- turtle.select(enderSlot)
- turtle.digUp()
- turtle.placeUp()
- end
- -- Put all items except ender chests, and coal in ender chest
- for slot = 1, numSlots, 1 do
- local item = turtle.getItemDetail(slot)
- if(item ~= nil) then
- if(item["name"] ~= "minecraft:coal_block" and item["name"] ~= "minecraft:coal" and item["name"] ~= "enderstorage:ender_storage") then
- turtle.select(slot)
- turtle.dropUp()
- end
- end
- end
- turtle.digUp()
- end
- -- Function to check fuel level and refuel if necessary
- function CheckFuel()
- turtle.select(1)
- if(turtle.getFuelLevel() < 50) then
- print("Attempting to refuel...")
- for slot = 1, numSlots, 1 do
- turtle.select(slot)
- if(turtle.refuel(1)) then
- return true
- end
- end
- return false
- else
- return true
- end
- end
- -- Function to detect blocks around the turtle and mine them
- function DetectAndDig()
- while(turtle.detectUp() or turtle.detectDown() or turtle.detect()) do
- turtle.dig()
- turtle.digUp()
- turtle.digDown()
- end
- end
- function Forward()
- DetectAndDig()
- turtle.forward()
- end
- function RightHalfTurn()
- turtle.turnRight()
- DetectAndDig()
- turtle.forward()
- turtle.turnRight()
- DetectAndDig()
- end
- function LeftHalfTurn()
- turtle.turnLeft()
- DetectAndDig()
- turtle.forward()
- turtle.turnLeft()
- DetectAndDig()
- end
- -- Function to tell the turtle which direction it is facing
- function InvertDirection()
- if(heading == "north") then
- heading = "south"
- elseif(heading == "south") then
- heading = "north"
- elseif(heading == "west") then
- heading = "east"
- elseif(heading == "east") then
- heading = "west"
- end
- end
- function TurnAround(level)
- if(level % 2 == 1) then
- if(heading == "north" or heading == "west") then
- LeftHalfTurn()
- elseif(heading == "south" or heading == "east") then
- RightHalfTurn()
- end
- else
- if(heading == "north" or heading == "west") then
- RightHalfTurn()
- elseif(heading == "south" or heading == "east") then
- LeftHalfTurn()
- end
- end
- InvertDirection()
- end
- -- Function to go up to the next level to mine
- function Up3Levels()
- turtle.turnRight()
- turtle.turnRight()
- InvertDirection()
- turtle.digDown()
- turtle.digUp()
- turtle.up()
- turtle.digUp()
- turtle.up()
- turtle.digUp()
- turtle.up()
- end
- function Main()
- for level = 1, heightY, 1 do
- for x = 1, widthX, 1 do
- for z = 1, depthZ, 1 do
- if(not CheckFuel()) then
- print("Turtle is out of fuel.")
- return
- end
- Forward()
- print(string.format("X: %d Z: %d", x, z))
- end
- if(x ~= widthX) then
- TurnAround(level)
- end
- ManageInventory()
- end
- Up3Levels()
- end
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement