Advertisement
QuantumWarpCode

Computercraft City Generator V2

Nov 1st, 2015
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.60 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. if #tArgs ~= 1 and #tArgs ~= 6 and #tArgs ~= 7 then
  4.     print("citygen <Command> <Corner X> <Height> <Corner Z> <Chunks X> <Chunks Y>")
  5.     return
  6. end
  7.  
  8. wall_blocks = {"stone", "cobblestone", "netherrack", "brick_block", "nether_brick", "sandstone", "sandstone 2"}
  9. floor_blocks = {"planks", "planks 1", "planks 2", "planks 3", "planks 4", "planks 5"}
  10. glass_blocks = {"glass", "stained_glass", "stained_glass 3", "stained_glass 11"}
  11. door_blocks = {"wooden_door"}
  12.  
  13.  
  14.  
  15.  
  16.  
  17. function csetblock(xshift, yshift, zshift, block)
  18.     x = tArgs[2] + xshift
  19.     y = tArgs[3] + yshift
  20.     z = tArgs[4] + zshift
  21.     --print("Placing block of "..block.." at "..x.." "..y.." "..z)
  22.     commands.exec("setblock "..x.." "..y.." "..z.." "..block)
  23. end
  24.  
  25. function fillblock(xshift, yshift, zshift, xlength, zlength, block)
  26.     xposition = 0
  27.     while xposition < xlength do
  28.         zposition = 0
  29.         while zposition < zlength do
  30.             csetblock(xshift + xposition, yshift, zshift + zposition, block)
  31.             zposition = zposition + 1
  32.         end
  33.         xposition = xposition + 1
  34.     end
  35. end
  36.  
  37. function createoutline(xshift, yshift, zshift, xlength, zlength, block)
  38.     xposition = 0
  39.     while xposition < xlength do
  40.         zposition = 0
  41.         while zposition < zlength do
  42.             if (xposition == 0 or xposition == xlength - 1) or (zposition == 0 or zposition == zlength - 1) then
  43.                 csetblock(xshift + xposition, yshift, zshift + zposition, block)
  44.             end
  45.             zposition = zposition + 1
  46.         end
  47.         xposition = xposition + 1
  48.     end
  49. end
  50.  
  51. function createoutlinewcorners(xshift, yshift, zshift, xlength, zlength, block, cornerblock)
  52.     xposition = 0
  53.     while xposition < xlength do
  54.         zposition = 0
  55.         while zposition < zlength do
  56.             if (xposition == 0 or xposition == zlength - 1) and (zposition == 0 or zposition == zlength - 1) then
  57.                 csetblock(xshift + xposition, yshift, zshift + zposition, cornerblock)
  58.             elseif (xposition == 0 or xposition == zlength - 1) or (zposition == 0 or zposition == zlength - 1) then
  59.                 csetblock(xshift + xposition, yshift, zshift + zposition, block)
  60.             end
  61.             zposition = zposition + 1
  62.         end
  63.         xposition = xposition + 1
  64.     end
  65. end
  66.  
  67. function buildsidewalk(xshift, zshift)
  68.     fillblock(xshift + 1, 0, zshift + 1, 14, 14, "grass")
  69.     createoutline(xshift, 0, zshift, 16, 16, "stone")
  70. end
  71.  
  72. function buildskyscraper(xshift, zshift)
  73.     wall = wall_blocks[math.random(1, #wall_blocks)]
  74.     floor = floor_blocks[math.random(1, #floor_blocks)]
  75.     glass = glass_blocks[math.random(1, #glass_blocks)]
  76.     door = door_blocks[math.random(1, #door_blocks)]
  77.    
  78.     lawn = math.random(1, 3)
  79.    
  80.     createoutline(xshift + lawn + 1, 0, zshift + lawn + 1, 16 - (2 * lawn) - 2, 16 - (2 * lawn) - 2, wall)
  81.     fillblock(xshift + lawn + 2, 0, zshift + lawn + 2, 16 - (2 * lawn) - 4, 16 - (2 * lawn) - 4, floor)
  82.    
  83.     floors = math.random(3,10)
  84.     --the below line is for quick debugging
  85.     --floors = 1
  86.     blocky = 1
  87.     floory = 0
  88.    
  89.     door_direction = math.random(1, 4)
  90.     if door_direction == 1 then
  91.         fillblock(xshift + 7, 0, zshift + 1, 2, lawn, "stone")
  92.     elseif door_direction == 2 then
  93.         fillblock(xshift + 7, 0, zshift + 15 - lawn, 2, lawn, "stone")
  94.     elseif door_direction == 3 then
  95.         fillblock(xshift + 1, 0, zshift + 7, lawn, 2, "stone")
  96.     elseif door_direction == 4 then
  97.         fillblock(xshift  + 15 - lawn, 0, zshift + 7, lawn, 2, "stone")
  98.     end
  99.    
  100.     while floory * 4 + blocky < floors * 4 + 1 do
  101.         if blocky == 0 then
  102.             createoutline(xshift + lawn + 1, floory * 4 + blocky, zshift + lawn + 1, 16 - (2 * lawn) - 2, 16 - (2 * lawn) - 2, wall)
  103.             fillblock(xshift + lawn + 2, floory * 4 + blocky, zshift + lawn + 2, 16 - (2 * lawn) - 4, 16 - (2 * lawn) - 4, floor)
  104.         else
  105.             createoutlinewcorners(xshift + lawn + 1, floory * 4 + blocky, zshift + lawn + 1, 16 - (2 * lawn) - 2, 16 - (2 * lawn) - 2, glass, wall)
  106.         end
  107.        
  108.         if blocky == 3 then
  109.             floory = floory + 1
  110.             blocky = 0
  111.         else
  112.             blocky = blocky + 1
  113.         end
  114.     end
  115.     createoutline(xshift + lawn + 1, floory * 4 + blocky, zshift + lawn + 1, 16 - (2 * lawn) - 2, 16 - (2 * lawn) - 2, wall)
  116. end
  117.  
  118.  
  119.  
  120.  
  121.  
  122. if tArgs[1] == "gen" or tArgs[1] == "generate" then
  123.     xchunk = 0
  124.     while xchunk < tArgs[5] * 1 do
  125.         zchunk = 0
  126.         while zchunk < tArgs[6] * 1 do
  127.             print("Terraforming chunk "..xchunk..", "..zchunk)
  128.             buildsidewalk(16 * xchunk, 16 * zchunk)
  129.             print("Building chunk "..xchunk..", "..zchunk)
  130.             buildskyscraper(16 * xchunk, 16 * zchunk)
  131.             zchunk = zchunk + 1
  132.         end
  133.         xchunk = xchunk + 1
  134.     end
  135. elseif tArgs[1] == "reset" then
  136.  
  137.     xchunk = 0
  138.     while xchunk < tArgs[5] * 1 do
  139.         zchunk = 0
  140.         while zchunk < tArgs[6] * 1 do
  141.             print("Reseting chunk "..xchunk..", "..zchunk)
  142.             yposition = 0
  143.             while yposition < 255 - tArgs[3] do
  144.                 if yposition == 0 then
  145.                     if #tArgs == 6 then
  146.                         fillblock(xchunk * 16, yposition, zchunk * 16, 16, 16, "grass")
  147.                     elseif #tArgs >= 7 then
  148.                         fillblock(xchunk * 16, yposition, zchunk * 16, 16, 16, tArgs[7])
  149.                     end
  150.                 else
  151.                     fillblock(xchunk * 16, yposition, zchunk * 16, 16, 16, "air")
  152.                 end
  153.                 yposition = yposition + 1
  154.             end
  155.             zchunk = zchunk + 1
  156.         end
  157.         xchunk = xchunk + 1
  158.     end
  159. elseif tArgs[1] == "terraform" then
  160.     xchunk = 0
  161.     while xchunk < tArgs[5] * 1 do
  162.         zchunk = 0
  163.         while zchunk < tArgs[6] * 1 do
  164.             print("Terraforming chunk "..xchunk..", "..zchunk)
  165.             buildsidewalk(16 * xchunk, 16 * zchunk)
  166.             zchunk = zchunk + 1
  167.         end
  168.         xchunk = xchunk + 1
  169.     end
  170. elseif tArgs[1] == "build" then
  171.     xchunk = 0
  172.     while xchunk < tArgs[5] * 1 do
  173.         zchunk = 0
  174.         while zchunk < tArgs[6] * 1 do
  175.             print("Building chunk "..xchunk..", "..zchunk)
  176.             buildskyscraper(16 * xchunk, 16 * zchunk)
  177.             zchunk = zchunk + 1
  178.         end
  179.         xchunk = xchunk + 1
  180.     end
  181. else
  182.     print("Error: Invalid command.")
  183. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement