Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --supplier
- --lists available schematics
- local sArg = ...
- if not fs.exists("market") then
- shell.run("pastebin get BztihKh3 market")
- end
- if not sArg then
- shell.run("market")
- error()
- else
- if not fs.exists(sArg) then
- shell.run("market "..sArg)
- end
- h = fs.open(sArg,"rb")
- end
- 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(h, n)
- for i=1,n do
- h.read()
- end
- end
- function readname(h)
- local n1 = h.read()
- local n2 = h.read()
- if(n1 == nil or n2 == nil) then
- return ""
- end
- local n = n1*256 + n2
- local str = ""
- for i=1,n do
- local c = h.read()
- if c == nil then
- return
- end
- str = str .. string.char(c)
- end
- return str
- end
- function parse(a, h, containsName)
- local containsName = containsName or true
- local i,i1,i2,i3,i4
- if a==0 then
- return
- end
- if containsName then
- name = readname(h)
- uPrint(name,colors.lime,1)
- end
- if a==1 then
- readbytes(h,1)
- elseif a==2 then
- i1 = h.read()
- i2 = h.read()
- i = i1*256 + i2
- uPrint(i,colors.white,2)
- if(name=="Height") then
- height = i
- elseif (name=="Length") then
- length = i
- elseif (name=="Width") then
- width = i
- end
- elseif a==3 then
- readbytes(h,4)
- elseif a==4 then
- readbytes(h,8)
- elseif a==5 then
- readbytes(h,4)
- elseif a==6 then
- readbytes(h,8)
- elseif a==7 then
- i1 = h.read()
- i2 = h.read()
- i3 = h.read()
- i4 = h.read()
- i = i1*256*256*256 + i2*256*256 + i3*256 + i4
- if name == "Blocks" then
- for i=1,i do
- table.insert(blocks, h.read())
- end
- saveTable(blocks, "blocks")
- elseif name == "Data" then
- for i=1,i do
- table.insert(data, h.read())
- end
- saveTable(data,"data")
- else
- readbytes(h,i)
- end
- elseif a==8 then
- i1 = h.read()
- i2 = h.read()
- i = i1*256 + i2
- readbytes(h,i)
- elseif a==9 then
- --readbytes(h,5)
- local type = h.read()
- i1 = h.read()
- i2 = h.read()
- i3 = h.read()
- i4 = h.read()
- i = i1*256*256*256 + i2*256*256 + i3*256 + i4
- for j=1,i do
- parse(h.read(), h, false)
- end
- end
- end
- function readThrough()
- local a = 0
- while (a ~= nil) do
- a = h.read()
- parse(a, h)
- end
- end
- function saveTable(tData,sFilename)
- local h = fs.open(sFilename,"w")
- h.write(textutils.serialize(tData))
- h.close()
- end
- function giveMaterials(tBlocks,tData)
- for i = 1,#tBlocks do
- if tBlocks[i]~=0 then
- commands.execAsync("give @p "..tostring(tBlocks[i]).." 1 "..tostring(tData[i]))
- end
- end
- end
- uPrint = function(sTitle,nColor,nIndents)
- --reads a number, string, or payload
- sTitle = sTitle or ""
- if sTitle == "Schematic" then
- nIndents = 0
- nColor = colors.orange
- end
- nColor = nColor or colors.white
- term.setTextColor(nColor)
- nIndents = nIndents or 1
- local sIndent = ""
- for i = 1,nIndents do
- sIndent = sIndent.." "
- end
- print(sIndent..tostring(sTitle))
- end
- readThrough()
- giveMaterials(blocks,data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement