Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local root = ".3DD/"
- local ps = {}
- local points = {}
- local mdim = {}
- local converter = {}
- function split(str, pat)
- local t = {} -- NOTE: use {n = 0} in Lua-5.0
- if str ~= nil then
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- else
- print("##3DD ERROR failed to split ["..str.."] by:"..pat)
- end
- return t
- end
- local function open(name)
- local nps = {}
- if fs.exists(root..name) then
- local file = fs.open(root..name, "r")
- local line = file.readLine()
- while line ~= nil do
- local splt = split(line, ",")
- if splt[1] == "MDIM" then
- local mx = tonumber(splt[2])
- local my = tonumber(splt[3])
- local mz = tonumber(splt[4])
- mdim = {mx, my, mz}
- else
- local x = tonumber(splt[1])
- local y = tonumber(splt[2])
- local z = tonumber(splt[3])
- local str = splt[4]
- if str == "#NIL" then str = nil end
- nps[#nps + 1] = {x, y, z, str}
- end
- line = file.readLine()
- end
- file.close()
- ps = nps
- return true
- else
- return false
- end
- end
- local function convert(pts, dim)
- mdim = dim
- for i=1,#tps do
- local tabl = tps[i]
- local x = tabl[1]
- local y = tabl[2]
- local z = tabl[3]
- local str = tabl[4]
- if points[x] == nil then points[x] = {} end
- if points[x][y] == nil then points[x][y] = {} end
- points[x][y][z] = str
- end
- end
- local function dig()
- while turtle.detect() do
- turtle.dig()
- sleep(0.25)
- end
- end
- local function place(type)
- local slot = 1
- for i=1,#converter do
- local table = converter[i]
- if table[1] == type then slot = table[2] end
- end
- if slot > 9 then slot = 9 end
- if slot < 1 then slot = 1 end
- turtle.select(slot)
- dig()
- if type ~= nil then
- if turtle.detectDown() then turtle.digDown() end
- turtle.placeDown()
- end
- end
- local function printBLP()
- local left = true
- for y=1,mdim[2] do
- for x=1,mdim[1] do
- for z=1,mdim[3] do
- local str = point[x][y][z]
- place(str)
- turtle.forwards()
- end
- if left then
- turtle.turnLeft()
- dig()
- turtle.forward()
- turtle.turnLeft()
- left = false
- else
- turtle.turnRight()
- dig()
- turtle.forward()
- turtle.turnRight()
- left = true
- end
- end
- turtle.up()
- end
- end
- local function start()
- print("What is the name of the project you wish to build?")
- local name = io.read()
- print("Enter the format (character:slot), seperate with space:")
- local formater = io.read()
- local splt = split(formater, " ")
- for i=1,#splt do
- converter[#converter + 1] = {splt[1], splt[2]}
- end
- print("Opening blueprint ("..name..") ...")
- if not open(name) then
- print("Blueprint "..name.." does not exist!")
- else
- print("Converting blueprint...")
- convert(ps, mdim)
- print("Printing blueprint...")
- printBLP()
- print("Printed blueprint.")
- end
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement