tomtrein

up

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