Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Schematic2Holo
- -- Made by Totoro (25.06.2014)
- io.write("Input file name: ")
- local filename = io.read()
- local length = 0
- local height = 0
- local width = 0
- local blocks = {}
- local data = {}
- function getBlockId(x,y,z)
- return blocks[y + z*width + x*length*width+1]
- end
- function getData(x,y,z)
- return data[y + z*width + x*length*width+1]
- end
- function readbytes(file, n)
- for i=1,n do
- string.byte(file:read(1))
- end
- end
- function readname(file)
- n1 = string.byte(file:read(1))
- n2 = string.byte(file:read(1))
- if(n1 == nil or n2 == nil) then
- return ""
- end
- n = n1*256 + n2
- str = ""
- for i=1,n do
- c = file:read(1)
- if c == nil then
- return
- end
- str = str .. c
- end
- --
- --print("Name: "..str)
- --io.read()
- --
- return str
- end
- function parse(a, file, containsName)
- if containsName == nil then containsName = true end
- --print(a)
- if a==0 then
- return
- end
- if containsName then
- name = readname(file)
- end
- if a==1 then
- readbytes(file,1)
- elseif a==2 then
- i1 = string.byte(file:read(1))
- i2 = string.byte(file:read(1))
- i = i1*256 + i2
- if(name=="Height") then
- height = i
- elseif (name=="Length") then
- length = i
- elseif (name=="Width") then
- width = i
- end
- elseif a==3 then
- readbytes(file,4)
- elseif a==4 then
- readbytes(file,8)
- elseif a==5 then
- readbytes(file,4)
- elseif a==6 then
- readbytes(file,8)
- elseif a==7 then
- i1 = string.byte(file:read(1))
- i2 = string.byte(file:read(1))
- i3 = string.byte(file:read(1))
- i4 = string.byte(file:read(1))
- i = i1*256*256*256 + i2*256*256 + i3*256 + i4
- if name == "Blocks" then
- for i=1,i do
- table.insert(blocks, string.byte(file:read(1)))
- end
- elseif name == "Data" then
- for i=1,i do
- table.insert(data, string.byte(file:read(1)))
- end
- else
- readbytes(file,i)
- end
- elseif a==8 then
- i1 = string.byte(file:read(1))
- i2 = string.byte(file:read(1))
- i = i1*256 + i2
- readbytes(file,i)
- elseif a==9 then
- t = string.byte(file:read(1))
- i1 = string.byte(file:read(1))
- i2 = string.byte(file:read(1))
- i3 = string.byte(file:read(1))
- i4 = string.byte(file:read(1))
- i = i1*256*256*256 + i2*256*256 + i3*256 + i4
- --print("Num: "..i)
- for j=1,i do
- --print("Step: "..j.." of "..i)
- if t ~= 10 then
- parse(t, file, false)
- else
- break
- --parse(string.byte(file:read(1)), file)
- end
- end
- end
- end
- -- import
- file = io.open(filename, "rb")
- a = 0
- while (a ~= nil) do
- a = file:read(1)
- if a == nil then break end
- a = string.byte(a)
- parse(a, file)
- end
- io.write("Length: " .. length)
- io.write(" Width: " .. width)
- io.write(" Height: " .. height .. "\n")
- file.close()
- file = io.open(filename..".txt", "w")
- print(#blocks)
- local bx, ax, by, ay, bz, az
- if width%2 == 1 then bx = (48-width-1)/2; ax = bx + 1
- else bx = (48-width)/2; ax = bx; end
- if length%2 == 1 then by = (48-length-1)/2; ay = by + 1
- else by = (48-length)/2; ay = by; end
- if height%2 == 1 then bz = (32-height-1)/2; az = bz + 1
- else bz = (32-height)/2; az = bz; end
- --for i=1, bz*length*width do file:write("0") end
- --for i=1, #blocks do
- -- if blocks[i] ~= 0 then
- -- file:write(blocks[i]%3+1)
- -- else
- -- file:write("0")
- -- end
- --end
- --for i=1, az*length*width do file:write("0") end
- --print()
- -- export
- for i=1, bz*48*48 do file:write("0") end
- for y=0,height-1 do
- for i=1, bx*48 do file:write("0") end
- for x=0,width-1 do
- for i=1, by do file:write("0") end
- for z=0,length-1 do
- blockID = getBlockId(y,x,z)
- blockData = getData(y,x,z)
- if blockID ~= 0 then
- file:write(string.char(blockData+49))
- else
- file:write("0")
- end
- end
- for i=1, ay do file:write("0") end
- end
- for i=1, ax*48 do file:write("0") end
- end
- for i=1, az*48*48 do file:write("0") end
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement