Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- About this program ...
- - This program is tested using FTB Infinity Evolved 2.6.0 Modpack.
- - This program uses turtle to find mineral deposit using Immersive Engineering Core Sample Drill.
- - As stated above, the turtle must have these following items in its inventory:
- 1. Coal or Charcoal (for fueling)
- 2. Any pickaxe-harvestable block (the drill need a block below to function)
- 3. Tesseract (or any RF power source for the drill)
- 4. Immersive Engineering Core Sample Drill (well, the drill itself)
- Note: These items must be sorted in this order strictly!
- --]]
- -- Global variables
- startPos = {
- x = 0,
- z = 0,
- f = 0
- }
- facing = {"SOUTH", "WEST", "NORTH", "EAST"}
- iteration = 0
- currentIteration = 0
- function closeError(message,outputFile)
- if outputFile ~= nil then
- outputFile.writeLine(message)
- outputFile.writeLine("An error occur at iteration " .. (currentIteration+1) .. "/" .. iteration .. ".")
- outputFile.close()
- error(message)
- else
- error("[Failed] Output file doesn't exist.")
- end
- end
- function refuel()
- if turtle.getItemCount(1) <= 0 then
- closeError("[Failed] Turtle run out of fuel.",outputFile)
- end
- if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 1 then
- turtle.refuel()
- end
- end
- -- For safety reasons, these are the overridden moving functions
- function safeForward(outputFile)
- if not turtle.forward() then
- closeError("[Failed] There's an obstruct in the turtle path.",outputFile)
- end
- end
- function safeUp(outputFile)
- if not turtle.up() then
- closeError("[Failed] There's an obstruct in the turtle path.",outputFile)
- end
- end
- function safeDown(outputFile)
- if not turtle.down() then
- closeError("[Failed] There's an obstruct in the turtle path.",outputFile)
- end
- end
- function safePlace(outputFile)
- if not turtle.place() then
- closeError("[Failed] There's an obstruct in the turtle path.",outputFile)
- end
- end
- function beginSampling(outputFile)
- -- Check requirement items in inventory
- if turtle.getItemCount(2) < 1 then
- closeError("[Failed] Missing platform block.",outputFile)
- return false
- end
- if turtle.getItemCount(3) < 1 then
- closeError("[Failed] Missing Tesseract.",outputFile)
- return false
- end
- if turtle.getItemCount(4) < 1 then
- closeError("[Failed] Missing Core Sample Drill 1.",outputFile)
- return false
- end
- -- Place platform block
- turtle.select(2)
- safePlace(outputFile)
- turtle.turnRight()
- safeForward(outputFile)
- turtle.turnLeft()
- -- Place Tesseract
- turtle.select(3)
- safeUp(outputFile)
- safePlace(outputFile)
- -- Place Core Sample Drill
- turtle.select(4)
- turtle.turnLeft()
- safeForward(outputFile)
- turtle.turnRight()
- safePlace(outputFile)
- print("Established sampling site successfully")
- return true
- end
- function doSampling(outputFile)
- -- Get the drill that "suppose" to be in front of the turtle right now
- local drill = peripheral.wrap("front")
- if drill == nil then
- closeError("[Failed] Missing Core Sample Drill 2.",outputFile)
- end
- while not drill.isSamplingFinished() do
- if drill.getEnergyStored() <= 0 then
- closeError("[Failed] The drill ran out of power.",outputFile)
- end
- end
- local result = drill.getVeinLocalizedName()
- if result == nil then
- outputFile.write("None\n")
- else
- outputFile.write(result .. "\n")
- end
- print("Done sampling successfully")
- return true
- end
- function endSampling(outputFile)
- -- Remove the platform blocks
- turtle.select(2)
- safeDown(outputFile)
- turtle.dig()
- turtle.turnRight()
- safeForward(outputFile)
- turtle.turnLeft()
- -- Remove Tesseract
- turtle.select(3)
- safeUp(outputFile)
- turtle.dig()
- -- Remove Core Sample Drill
- turtle.select(4)
- turtle.turnLeft()
- safeForward(outputFile)
- turtle.turnRight()
- turtle.dig()
- print("Removed sampling site successfully")
- return true
- end
- function main()
- -- Input current turtle coordinate and facing (This may be replaced by gps API)
- local stringInput
- print("Please input current x coordinate : ")
- stringInput = io.read()
- startPos["x"] = tonumber(stringInput)
- print("Please input current z coordinate : ")
- stringInput = io.read()
- startPos["z"] = tonumber(stringInput)
- print("Please input current f (facing) : ")
- stringInput = io.read()
- startPos["f"] = tonumber(stringInput)
- while startPos["f"] < 0 or startPos["f"] > 3 do
- print("Invalid f (facing) input, please input 0 - 3. (Check your facing by pressing F3)")
- stringInput = io.read()
- startPos["f"] = tonumber(stringInput)
- end
- -- Input number of iterations (number of chunks being sampled)
- print("Please input number of iterations : ")
- stringInput = io.read()
- iteration = tonumber(stringInput)
- print("x,z,f,i = " .. startPos["x"] .. "," .. startPos["z"] .. "," .. startPos["f"] .. "," .. iteration)
- -- Initialize output file
- local timeText = http.get("http://www.timeapi.org/utc/in+7+hours?format=%25d%25m%25Y_%25H%25M%25S").readAll()
- local outputFile = fs.open("OreSampling_" .. timeText, "w")
- outputFile.writeLine("Ore Sampling Report started at (" .. startPos["x"] .. ", " .. startPos["z"] .. ") facing to " .. facing[startPos["f"]])
- outputFile.writeLine("Number of iterations : " .. iteration)
- local deltaZ = 0
- local deltaX = 0
- while currentIteration < iteration do
- refuel(outputFile)
- print("f : " .. startPos["f"])
- deltaZ = ((startPos["f"]+1)%2)*(startPos["f"]-1)*currentIteration*16
- deltaX = (startPos["f"]%2)*(startPos["f"]-2)*currentIteration*16
- outputFile.write("[1]" .. (startPos["x"]+deltaX) .. (startPos["z"]+deltaZ) .. " : ")
- beginSampling(outputFile)
- doSampling(outputFile)
- endSampling(outputFile)
- for i=1,16 do
- safeForward(outputFile)
- end
- currentIteration = currentIteration + 1
- end
- print("All samplings done")
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment