View difference between Paste ID: zuuRxe86 and 9e1Y9FCM
SHOW: | | - or go back to the newest paste.
1
--modified by BillBodkin
2
3
4
-- Made By Orwell
5-
if #tArgs ~= 1 then
5+
6-
  print("Usage: build <gunzipped schematic file>")
6+
7
local tArgs = { ... }
8
local filename = tArgs[1]
9
if tArgs[2] then
10
	dom = "http://192.168.1.2:92"
11
elseif filename then
12
	dom = "http://cablepost.ddns.net:92"
13
else
14
	print("Enter a name of what to build")
15
	--could replace this with a list of files to build pulled from website
16
	return
17
end
18
19
local content = http.get(dom .. "/cc/schematic/" .. filename).readAll()
20
if not content then
21
	error("Could not connect to website")
22
	return
23
end
24
f = fs.open(filename, "w")
25
f.write(content)
26
f.close()
27
28
if not fs.exists(filename) then
29
  print("File does not exist.")
30
  return
31
end
32
33
local length = 0
34
local height = 0
35
local width = 0
36
local blocks = {}
37
local data = {}
38
39
block_id = {}
40
41
block_id[0] = "Air"
42
block_id[1] = "Stone"
43
block_id[2] = "Grass"
44
block_id[3] = "Dirt"
45
block_id[4] = "Cobblestone"
46
block_id[5] = "Wooden Plank"
47
block_id[6] = "Sapling"
48
block_id[7] = "Bedrock"
49
block_id[8] = "Water"
50
block_id[9] = "Stationary water"
51
block_id[10] = "Lava"
52
block_id[11] = "Stationary lava"
53
block_id[12] = "Sand"
54
block_id[13] = "Gravel"
55
block_id[14] = "Gold Ore"
56
block_id[15] = "Iron (Ore)"
57
block_id[16] = "Coal Ore"
58
block_id[17] = "Log"
59
block_id[18] = "Leaves"
60
block_id[19] = "Sponge"
61
block_id[20] = "Glass"
62
block_id[21] = "Lapis Lazuli (Ore)"
63
block_id[22] = "Lapis Lazuli (Block)"
64
block_id[23] = "Dispenser"
65
block_id[24] = "Sandstone"
66
block_id[25] = "Note Block Tile entity"
67
block_id[26] = "Bed"
68
block_id[27] = "Powered Rail "
69
block_id[28] = "Detector Rail "
70
block_id[29] = "Sticky Piston"
71
block_id[30] = "Cobweb"
72
block_id[31] = "Tall Grass"
73
block_id[32] = "Dead Bush"
74
block_id[33] = "Piston"
75
block_id[34] = "Piston Extension"
76
block_id[35] = "Wool"
77
block_id[36] = "Block moved by Piston"
78
block_id[37] = "Dandelionandelion"
79
block_id[38] = "Rose"
80
block_id[39] = "Brown Mushroom"
81
block_id[40] = "Red Mushroom"
82
block_id[41] = "Block of Gold"
83
block_id[42] = "Block of Iron"
84
block_id[43] = "Double Slabs"
85
block_id[44] = "Slabs"
86
block_id[45] = "Brick Block"
87
block_id[46] = "TNT"
88
block_id[47] = "Bookshelf"
89
block_id[48] = "Moss Stone"
90
block_id[49] = "Obsidian"
91
block_id[50] = "Torch"
92
block_id[51] = "Fire"
93
block_id[52] = "Monster Spawner"
94
block_id[53] = "Wooden Stairs"
95
block_id[54] = "Chest"
96
block_id[55] = "Redstone (Wire)"
97
block_id[56] = "Diamond (Ore)"
98
block_id[57] = "Block of Diamond"
99
block_id[58] = "Crafting Table"
100
block_id[59] = "Seeds"
101
block_id[60] = "Farland"
102
block_id[61] = "Furnace"
103
block_id[62] = "Burning Furnace"
104
block_id[63] = "Sign Post"
105
block_id[64] = "Wooden Door"
106
block_id[65] = "Ladders"
107
block_id[66] = "Rails"
108
block_id[67] = "Cobblestone Stairs"
109
block_id[68] = "Wall Sign"
110
block_id[69] = "Lever"
111
block_id[70] = "Stone Pressure Plate"
112
block_id[71] = "Iron Door"
113
block_id[72] = "Wooden Pressure Plates"
114
block_id[73] = "Redstone Ore"
115
block_id[74] = "Glowing Redstone Ore"
116
block_id[75] = "Redstone Torch"
117
block_id[76] = "Redstone Torch"
118
block_id[77] = "Stone Button "
119
block_id[78] = "Snow"
120
block_id[79] = "Ice"
121
block_id[80] = "Snow Block"
122
block_id[81] = "Cactus"
123
block_id[82] = "Clay (Block)"
124
block_id[83] = "Sugar Cane"
125
block_id[84] = "Jukebox"
126
block_id[85] = "Fence"
127
block_id[86] = "Pumpkin"
128
block_id[87] = "Netherrack"
129
block_id[88] = "Soul Sand"
130
block_id[89] = "Glowstone"
131
block_id[90] = "Portal"
132
block_id[91] = "Jack-O-Lantern"
133
block_id[92] = "Cake Block"
134
block_id[93] = "Redstone Repeater"
135
block_id[94] = "Redstone Repeater"
136
block_id[95] = "Locked Chest"
137
block_id[96] = "Trapdoors"
138
block_id[97] = "Hidden Silverfish"
139
block_id[98] = "Stone Brick"
140
block_id[99] = "Huge brown and red mushroom"
141
block_id[100] = "Huge brown and red mushroom"
142
block_id[101] = "Iron Bars"
143
block_id[102] = "Glass Pane"
144
block_id[103] = "Melon"
145
block_id[104] = "Pumpkin Stem"
146
block_id[105] = "Melon Stem"
147
block_id[106] = "Vines"
148
block_id[107] = "Fence Gate"
149
block_id[108] = "Brick Stairs"
150
block_id[109] = "Stone Brick Stairs"
151
block_id[110] = "Mycelium"
152
block_id[111] = "Lily Pad"
153
block_id[112] = "Nether Brick"
154
block_id[113] = "Nether Brick Fence"
155
block_id[114] = "Nether Brick Stairs"
156
block_id[115] = "Nether Wart"
157
block_id[116] = "Enchantment Table"
158
block_id[117] = "Brewing Stand"
159
block_id[118] = "Cauldron"
160
block_id[119] = "End Portal"
161
block_id[120] = "End Portal Frame"
162
block_id[121] = "End Stone "
163
block_id[256] = "Iron Ingotron Shovel"
164
block_id[257] = "Iron Pickaxe"
165
block_id[258] = "Iron Axe"
166
block_id[259] = "Flint and Steel"
167
block_id[260] = "Red Apple"
168
block_id[261] = "Bow"
169
block_id[262] = "Arrow"
170
block_id[263] = "Coal"
171
172
woolColors = {}
173
woolColors[0] = "White"
174
woolColors[1] = "Orange"
175
woolColors[2] = "Magenta"
176
woolColors[3] = "Light Blue"
177
woolColors[4] = "Yellow"
178
woolColors[5] = "Lime"
179
woolColors[6] = "Pink"
180
woolColors[7] = "Gray"
181
woolColors[8] = "Light Gray"
182
woolColors[9] = "Cyan"
183
woolColors[10] = "Purple"
184
woolColors[11] = "Blue"
185
woolColors[12] = "Brown"
186
woolColors[13] = "Green"
187
woolColors[14] = "Red"
188
woolColors[15] = "Black"
189
190
function getBlockName(id, blockData)
191
  blockData = blockData or nil
192
  if(block_id[id] == nil) then
193
    return "UNKNOWN"
194
  else
195
    if(blockData) then
196
      if(id == 35) then
197
        str = woolColors[blockData] .. " " .. block_id[id]
198
        return str
199
      end
200
    end
201
    return block_id[id]
202
  end
203
end
204
205
function getBlockId(x,y,z)
206
  return blocks[y + z*width + x*length*width + 1]
207
end
208
209
function getData(x,y,z)
210
  return data[y + z*width + x*length*width + 1]
211
end
212
213
function readbytes(h, n)
214
  for i=1,n do
215
    h.read()
216
  end
217
end
218
219
function readname(h)  
220
  n1 = h.read()
221
  n2 = h.read()
222
223
  if(n1 == nil or n2 == nil) then
224
    return ""
225
  end
226
  
227
  n = n1*256 + n2
228
  
229
  str = ""
230
  for i=1,n do
231
    c = h.read()
232
    if c == nil then
233
      return
234
    end  
235
    str = str .. string.char(c)
236
  end
237
  return str
238
end
239
240
function parse(a, h, containsName)
241
  containsName = containsName or true
242
  if a==0 then
243
    return
244
  end
245
  if containsName then
246
    name = readname(h)
247
  end
248
    
249
  if a==1 then
250
    readbytes(h,1)  
251
  elseif a==2 then
252
    i1 = h.read()
253
    i2 = h.read()
254
    i = i1*256 + i2
255
    if(name=="Height") then
256
      height = i
257
    elseif (name=="Length") then
258
      length = i
259
    elseif (name=="Width") then
260
      width = i
261
    end
262
  elseif a==3 then
263
    readbytes(h,4)
264
  elseif a==4 then
265
    readbytes(h,8)
266
  elseif a==5 then
267
    readbytes(h,4)
268
  elseif a==6 then
269
    readbytes(h,8)
270
  elseif a==7 then
271
    i1 = h.read()
272
    i2 = h.read()
273
    i3 = h.read()
274
    i4 = h.read()
275
    i = i1*256*256*256 + i2*256*256 + i3*256 + i4
276
    if name == "Blocks" then
277
      for i=1,i do
278
        table.insert(blocks, h.read())
279
      end
280
    elseif name == "Data" then
281
      for i=1,i do
282
        table.insert(data, h.read())
283
      end
284
    else
285
      readbytes(h,i)
286
    end
287
  elseif a==8 then
288
    i1 = h.read()
289
    i2 = h.read()
290
    i = i1*256 + i2
291
    readbytes(h,i)
292
  elseif a==9 then
293
  	--readbytes(h,5)
294
  	type = h.read()
295
  	i1 = h.read()
296
    i2 = h.read()
297
    i3 = h.read()
298
    i4 = h.read()
299
    i = i1*256*256*256 + i2*256*256 + i3*256 + i4
300
    for j=1,i do
301
      parse(h.read(), h, false)
302
    end
303
  end
304
end
305
306
function forward()
307
  while not turtle.forward() do
308
    turtle.dig()
309
  end
310
end
311
312
function up()
313
  while not turtle.up() do
314
    turtle.digUp()
315
  end
316
end
317
318
function down()
319
  while not turtle.down() do
320
    turtle.digDown()
321
  end
322
end
323
324
function place()
325
  while not turtle.placeDown() do
326
    turtle.digDown()
327
  end
328
end
329
330
h = fs.open(filename, "rb")
331
332
a = 0
333
while (a ~= nil) do
334
  a = h.read()
335
  parse(a, h)
336
end
337
338
write("length: " .. length)
339
write("   width: " .. width)
340
write("   height: " .. height .. "\n")
341
342
uniqueblocks={}
343
for i,v in ipairs(blocks) do
344
  found = false
345
  for j,w in ipairs(uniqueblocks) do
346
    -- for now, data is only accounted for when the block is whool
347
    if (w.blockID==v and (w.data==data[i] or w.blockID ~= 35)) then
348
      found = true
349
      w.amount = w.amount + 1
350
      break
351
    end
352
  end
353
  
354
  if found==false then
355
    uniqueblocks[#uniqueblocks+1] = {}
356
    uniqueblocks[#uniqueblocks].blockID = v
357
    uniqueblocks[#uniqueblocks].data = data[i]
358
    uniqueblocks[#uniqueblocks].amount = 1
359
  end
360
end
361
362
print("number of block types: " .. #uniqueblocks)
363
for i,v in ipairs(uniqueblocks) do
364
  if (i%9)==0 then
365
    read()
366
  end
367
  print(" -" .. getBlockName(v.blockID, v.data) .. ": " .. v.amount)
368
end
369
370
read()
371
372
print("Give the numbers of all slots containing the specified block type:")
373
374
slots={}
375
for i,block in ipairs(uniqueblocks) do
376
  blockData = block.data
377
  print(" -in which slots is " .. getBlockName(block.blockID, blockData) .. "?")
378
  if not slots[block.blockID] then
379
    slots[block.blockID] = {}
380
  end
381
  slots[block.blockID][blockData] = {}
382
  write("   ")
383
  str = read()
384
  for i = 1, #str do
385
    local c = str:sub(i,i)
386
    n = tonumber(c)
387
    if(n) then
388
      if(n>0 and n<10) then
389
        table.insert(slots[block.blockID][blockData], n)
390
      end
391
    end
392
  end
393
end
394
395
print("Press key to start building...")
396
read()
397
398
up()
399
n = 1
400
turtle.select(n)
401
402
for x=1,height do
403
  for y=1,width do
404
    for z=1,length do
405
      blockID = getBlockId(x-1,y-1,z-1)
406
      blockData = getData(x-1,y-1,z-1)
407
      forward()
408
      turtle.digDown()
409
      slot_lst = slots[blockID][blockData]
410
      if(slot_lst ~= nil) then
411
        if(#slot_lst > 0) then
412
          local found=false
413
          for i,v in ipairs(slot_lst) do
414
            if(turtle.getItemCount(v) > 0) then
415
              found=true
416
              turtle.select(v)
417
              break
418
            end
419
          end
420
          if not found then
421
            print("Not enough " .. getBlockName(blockID, blockData) .. ". Please refill...")
422
            read()
423
          end
424
          place()
425
        end
426
      end
427
    end
428
    turtle.turnLeft()
429
    forward()
430
    turtle.turnLeft()
431
    for i=1,length do
432
      forward()
433
    end
434
    turtle.turnRight()
435
    turtle.turnRight()
436
  end
437
  turtle.turnRight()
438
  for i=1,width do
439
    forward()
440
  end
441
  turtle.turnLeft()
442
  up()
443
end
444
445
for i=1,height+1 do
446
  down()
447
end