Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local arg = {...}
- -- Variables
- local userInput_distance = tonumber(arg[1])
- local userInput_nether = tonumber(arg[2])
- local userInput_debug = arg[3]
- local torchSpacing = 7
- local ignoreFirstBlock = 1 -- Prevents turtle from attempting to place a torch at program launch
- local currentIteration = tonumber(userInput_distance)
- local direction = 1 -- 0: Left // 1: Forward // 2: Right // 3: Rear
- local height = 0 -- 0: Down // 1: Up
- local readyToLaunch = false
- local flag_Nether = false
- function clearScreen()
- term.clear()
- term.setCursorPos(1,1)
- end
- function lavaProtection()
- local success, data = turtle.inspect()
- if data.name == "minecraft:lava" then
- turtle.select(13)
- turtle.place()
- end
- end
- function findSortItem(item,slot)
- local itemDetect
- for i=1,16 do
- itemDetect = turtle.getItemDetail(i)
- if itemDetect then
- print(itemDetect)
- if(itemDetect.name == item) then
- print("Item found in slot",i)
- turtle.select(i)
- turtle.transferTo(slot)
- end
- end
- end
- end
- function inventoryCheck() -- TO DO ORGANIZE THIS SHIT, ADD CHECKS FOR BLOCK AND SWAP
- local torch = turtle.getItemDetail(16)
- local chest = turtle.getItemDetail(15)
- local block = turtle.getItemDetail(13)
- if (torch == nil) or (chest == nil) then
- clearScreen()
- print("I'm not prepared to mine!")
- print("I need an Ender Chest in slot 15 and a Torch on slot 16.")
- print("Press any key to continue.")
- os.pullEvent("key")
- elseif (torch.name == "minecraft:torch") and (chest.name == "enderstorage:ender_chest") then
- readyToLaunch = true
- else
- clearScreen()
- print("I'm not prepared to mine!")
- print("I need an Ender Chest in slot 15 and a Torch on slot 16.")
- print("Press any key to continue.")
- os.pullEvent("key")
- end
- -- if flag_Nether == true) then
- -- if blocks == nil then
- -- clearScreen()
- -- print("I'm not prepared to mine!")
- -- print("I need Cobblestone on slot 13.")
- -- print("Press any key to continue.")
- -- os.pullEvent("key")
- -- readyToLaunch = false
- -- elseif (block.name) == "minecraft:cobblestone"
- end
- function netherBlocks()
- if (flag_Nether == true) then
- if (height == 0) and (turtle.detectDown() == false) then
- turtle.select(13)
- turtle.placeDown()
- elseif (height == 1) and (turtle.detectUp() == false) then
- turtle.select(13)
- turtle.placeUp()
- end
- end
- end
- function getBlockName()
- local success,data = turtle.inspect()
- return data.name
- end
- function dig()
- while turtle.detect() do
- turtle.dig()
- end
- if (flag_Nether == true) and (direction ~= 1) then
- sleep(.6)
- lavaProtection()
- end
- end
- function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- end
- if (flag_Nether == true) and (direction ~= 1) then
- sleep(.6)
- lavaProtection()
- end
- end
- function torchCheck()
- if (ignoreFirstBlock == 1) and (height == 1) then
- -- Do Nothing :)
- ignoreFirstBlock = 0
- elseif (currentIteration >= torchSpacing) and (height == 1) then
- turtle.select(16)
- turtle.place()
- currentIteration = 1
- end
- end
- function switchHeight()
- if height == 0 then
- turtle.up()
- height = 1
- elseif height == 1 then
- turtle.down()
- height = 0
- else
- print("switchHeight error!")
- end
- end
- function unloadItems()
- -- Rotate turtle to Rear
- local originalDirection = direction
- if (direction == 0) then
- turtle.turnLeft()
- elseif (direction == 1) then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif (direction == 2) then
- turtle.turnRight()
- else
- print("unloadItems error!")
- end
- direction = 3
- -- turtle selects ender chest
- turtle.select(15)
- -- turtle place ender chest
- turtle.place()
- -- turtle loops placing items into chest
- for i=1,12 do
- turtle.select(i)
- turtle.drop()
- end
- -- turtle selects inv for ender chest
- turtle.select(15)
- -- turtle mines
- turtle.dig()
- -- turtle faces original direction
- if (originalDirection == 0) then
- turtle.turnRight()
- direction = 0
- elseif (originalDirection == 1) then
- turtle.turnRight()
- turtle.turnRight()
- direction = 1
- elseif (originalDirection == 2) then
- turtle.turnLeft()
- direction = 2
- else
- print("unloadItems error in originalDirection!")
- end
- end
- function slice()
- if (direction == 0) then
- dig()
- torchCheck()
- turtle.turnRight()
- direction = 1
- dig()
- turtle.turnRight()
- direction = 2
- dig()
- elseif (direction == 1) then
- turtle.turnLeft()
- direction = 0
- dig()
- torchCheck()
- turtle.turnRight()
- direction = 1
- dig()
- turtle.turnRight()
- dig()
- direction = 2
- elseif (direction == 2) then
- dig()
- turtle.turnLeft()
- direction = 1
- dig()
- turtle.turnLeft()
- direction = 0
- dig()
- torchCheck()
- else
- print("bruh")
- end
- if turtle.getItemCount(10) >= 1 then
- unloadItems()
- end
- end
- -- END OF FUNCTIONS
- -- if loopInput == nil then
- -- loopInput = 1
- -- end
- ----------------------
- -- MAIN CODE BEGINS --
- ----------------------
- if userInput_nether == nil or userInput_nether == 0 then
- flag_Nether = false
- elseif userInput_nether == 1 then
- flag_Nether = true
- else
- print("Invalid second argument. Please use either 0 or 1!")
- end
- findSortItem("minecraft:cobblestone",13)
- findSortItem("minecraft:diamond_pickaxe",14)
- findSortItem("enderstorage:ender_chest",15)
- findSortItem("minecraft:torch",16)
- -- Inventory Check on Launch
- while readyToLaunch == false do
- inventoryCheck()
- end
- if torchSpacing * turtle.getItemCount(16) < userInput_distance then
- clearScreen()
- print("I don't have enough torches to go that far!")
- print("OVERRIDE: Distance value set to", torchSpacing * turtle.getItemCount(16), "blocks")
- print("Press any key to continue")
- os.pullEvent("key")
- end
- -- Catch currentIteration if nil
- if userInput_distance == nil then
- clearScreen()
- print("Please input an additional argument for distance!")
- else
- local pickaxe = turtle.getItemDetail(14)
- if (pickaxe.name == "minecraft:diamond_pickaxe") then
- shell.run("equip 14 right")
- end
- for i=1, userInput_distance do
- clearScreen()
- print("Fuel Level: ", turtle.getFuelLevel())
- if (flag_Nether == true) then
- term.setTextColor(colors.green)
- print("Nether Mode Enabled")
- term.setTextColor(colors.white)
- else
- term.setTextColor(colors.red)
- print("Nether Mode Disabled")
- term.setTextColor(colors.white)
- end
- -- Check if a torch is present in inventory
- local torchSlot = turtle.getItemDetail(16)
- if torchSlot == nil or torchSlot.name ~= "minecraft:torch" then
- print("I'm out of torches! Exiting program...")
- break
- end
- -- dig left to right
- slice()
- -- move up
- switchHeight()
- netherBlocks()
- -- dig right to left
- slice()
- -- turn towards front, move forward
- if direction == 0 then
- turtle.turnRight()
- turtle.forward()
- elseif direction == 1 then
- turtle.turnLeft()
- turtle.forward()
- else
- print("End of loop error!")
- end
- direction = 1
- -- if in the nether do this thingy
- netherBlocks()
- currentIteration = currentIteration + 1
- end
- end
- -- swap back
- shell.run("equip 14 right")
- print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment