Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tab = {}
- local tArgs = { ... }
- if #tArgs ~= 2 then
- error("Usage : scan <fileName> <side of diskDrive>")
- else
- peri = peripheral.getType(tArgs[2])
- if peri ~= nil then
- if peri == "drive" then
- isDiskPresent = disk.hasData(tArgs[2])
- if isDiskPresent == false then
- error("There is no Disk in the diskDrive !")
- end
- else
- error("There is no DiskDrive attached to "..tArgs[2].." !")
- end
- else
- error("There is no peripheral attached to "..tArgs[2].." !")
- end
- dir = disk.getMountPath(tArgs[2])
- sPath = dir.."/"..tArgs[1]
- if fs.exists(sPath) == true then
- error("The fileName "..tArgs[1].." already exists !")
- end
- end
- isFinished = false
- local currentX = 0
- local currentY = 1
- local currentZ = 1
- local handleFacing = {{1,0},{0,1},{-1,0},{0,-1}}
- local facing = 1
- print("Please enter lenght :")
- local x = read()
- print("Please enter height :")
- local y = read()
- print("Please enter width :")
- local z = read()
- x = tonumber(x)
- y = tonumber(y)
- z = tonumber(z)
- local layers = math.ceil(y/3)
- local lastLayerCount = y%3
- if lastLayerCount == 0 then
- lastLayerCount = 3
- end
- local currentLayer = 1
- local area = x*z
- local volume = x*y*z
- --TEST--
- print("X: "..x..", Y: "..y..", Z: "..z..", Volume: "..volume)
- --------
- if x < 1 or y < 1 or z < 1 then
- error("x,y and z must be non null positive numbers.")
- end
- -- Checking for pickaxe
- function checkPickaxe()
- turtle.select(16)
- turtle.equipLeft()
- obj = turtle.getItemDetail()
- if obj ~= nil then
- if obj["name"] == "minecraft:diamond_pickaxe" then
- print("Mining turtle : OK ")
- turtle.equipLeft()
- else
- error("Turtle need to be a mining turtle.")
- end
- else
- error("Turtle need to be a mining turtle.")
- end
- end
- -- Cheking for fuel
- function fuel()
- turtle.select(1)
- term.write("Fuel : ")
- currentFuelLevel = turtle.getFuelLevel()
- if currentFuelLevel < math.floor(1.1*area*layers) then
- term.write("Need more !\n")
- print("Current level : "..currentFuelLevel.."\n")
- print("Need "..math.floor(1.1*volume)-currentFuelLevel.." more fuel point.\n")
- print("Also known as "..math.ceil((math.floor(1.1*volume)-currentFuelLevel)/80).." coals/charcoals or "..math.ceil((math.floor(1.1*volume)-currentFuelLevel)/15).." wood log\n")
- while currentFuelLevel < math.floor(1.1*volume) do
- turtle.refuel()
- currentFuelLevel = turtle.getFuelLevel()
- sleep(2)
- end
- else
- term.write("OK.\n")
- end
- end
- ---------FUNCTION/SETTING UP----------
- for l = 1,x do
- tab[l] = {}
- for m = 1,y do
- tab[l][m] = {}
- for n = 1,z do
- tab[l][m][n] = {}
- tab[l][m][n]["id"] = ""
- tab[l][m][n]["metadata"] = 0
- tab[l][m][n]["facing"] = ""
- tab[l][m][n]["half"] = ""
- end
- end
- end
- function analyze(t)
- local tData = {}
- if t["name"] == "minecraft:log" or t["name"] == "minecraft:log2" then
- tData["facing"] = t["state"]["axis"]
- elseif t["name"]:find("slab")~= nil and t["name"]:find("double") == nil then
- tData["half"] = t["state"]["half"]
- elseif t["name"]:find("stairs") ~= nil then
- tData["half"] = t["state"]["half"]
- tData["facing"] = t["state"]["facing"]
- elseif t["name"]:find("button") ~= nil or t["name"] == "ladder" then
- tData["facing"] = t["state"]["facing"]
- elseif t["name"]:find("trapdoor") ~= nil then
- tData["half"] = t["state"]["half"]
- tData["facing"] = t["state"]["facing"]
- elseif t["name"]:find("chest") ~= nil or t["name"]:find("furnace") ~= nil or t["name"]:find("anvil") then
- tData["facing"] = t["state"]["facing"]
- elseif t["name"]:find("piston")~= nil or t["name"] == "minecraft:dropper" or t["name"] == "minecraft:dispenser" then
- tData["facing"] = t["state"]["facing"]
- end
- tData["id"] = t["name"]
- tData["metadata"] = t["metadata"]
- return tData
- end
- function advInspect(level,a,b,c)
- if level == 0 then
- sucess,tInspect = turtle.inspect()
- elseif level == -1 then
- sucess,tInspect = turtle.inspectDown()
- elseif level == 1 then
- sucess,tInspect = turtle.inspectUp()
- end
- if sucess == true then
- temp = analyze(tInspect)
- for k,v in pairs(temp) do
- tab[a][b+level][c][k] = v
- end
- else
- tab[a][b+level][c]["id"] = "minecraft:air"
- end
- end
- function turningRight()
- turtle.turnRight()
- facing = facing +1
- if facing == 5 then
- facing = 1
- end
- end
- function upping()
- currentX = 0
- currentZ = 1
- facing = 1
- currentLayer = currentLayer + 1
- for _ = 1,3 do
- turtle.up()
- currentY = currentY+1
- turtle.digUp()
- end
- end
- function turningLeft()
- turtle.turnLeft()
- facing = facing -1
- if facing == 0 then
- facing = 4
- end
- end
- function moveOn()
- if currentLayer == layers then
- if lastLayerCount >=2 then
- advInspect(0,currentX+handleFacing[facing][1],currentY,currentZ+handleFacing[facing][2])
- end
- else
- advInspect(0,currentX+handleFacing[facing][1],currentY,currentZ+handleFacing[facing][2])
- end
- turtle.dig()
- turtle.forward()
- currentZ = currentZ+handleFacing[facing][2]
- currentX = currentX+handleFacing[facing][1]
- end
- -- MAIN PROGRAMM
- checkPickaxe()
- fuel()
- turtle.up()
- currentY = currentY+1
- moveOn()
- while not isFinished do
- advInspect(-1,currentX,currentY,currentZ)
- turtle.digDown()
- if currentLayer == layers then
- if lastLayerCount == 3 then
- advInspect(1,currentX,currentY,currentZ)
- turtle.digUp()
- end
- else
- advInspect(1,currentX,currentY,currentZ)
- turtle.digUp()
- end
- if currentZ == z then
- if currentX == x and facing == 1 then
- turtle.turnLeft()
- if z == 1 then
- error("You can't use a one by one area ! ")
- end
- for i = 1,(z-1) do
- turtle.forward()
- end
- turtle.turnLeft()
- for j = 1,x do
- turtle.forward()
- end
- turningRight()
- turningRight()
- if currentLayer < layers then
- upping()
- else
- isFinished = true
- for _ = 1,(currentY-1) do
- turtle.down()
- end
- end
- elseif currentX == 1 and facing == 3 then
- turtle.turnRight()
- for i = 1,(z-1) do
- turtle.forward()
- end
- turtle.turnRight()
- turtle.back()
- if currentLayer < layers then
- upping()
- else
- isFinished = true
- for _ = 1,(currentY-1) do
- turtle.down()
- end
- end
- end
- end
- if not isFinished then
- if currentX == x and facing == 1 then
- turningRight()
- moveOn()
- turningRight()
- elseif currentX == 1 and facing == 3 then
- turningLeft()
- moveOn()
- turningLeft()
- else
- moveOn()
- end
- end
- end
- h = fs.open(sPath,"w")
- h.write(textutils.serialize(tab))
- h.close()
Advertisement
Add Comment
Please, Sign In to add comment