Advertisement
Wyvern67

cityBuilder

Jul 10th, 2015
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.42 KB | None | 0 0
  1. old = {}
  2. old.execAsync = commands.execAsync
  3. dangerousAmountOfQueries = 700 -- blocks
  4. restingTime = 0.1 -- seconds
  5.  
  6. sandstone = "minecraft:sandstone"
  7. stone = "minecraft:stone"
  8. air = "minecraft:air"
  9. glass = "minecraft:stained_glass"
  10. wood = "minecraft:planks"
  11.  
  12. x="x"
  13. y="y"
  14. z="z"
  15.  
  16. function isTrue(number)
  17.     if number == 0 then
  18.         return false
  19.     else
  20.         return true
  21.     end
  22. end
  23.  
  24. function round(num, idp)
  25.   local mult = 10^(idp or 0)
  26.   return math.floor(num * mult + 0.5) / mult
  27. end
  28. math.round = round
  29.  
  30. function console(txt,line)
  31.     if true then
  32.         if line == nil then
  33.             line = 1
  34.         end
  35.         term.setCursorPos(1,line)
  36.         term.clearLine(line)
  37.         term.write(txt)
  38.         term.setCursorPos(1,line+1)
  39.     end
  40. end
  41.  
  42. function deltaT(timerID)
  43.     if type(lastCallFromTheID) ~= "table" then
  44.         lastCallFromTheID = {}
  45.     end
  46.    
  47.     if lastCallFromTheID[timerID] == nil then
  48.         lastCallFromTheID[timerID] = os.clock()
  49.     end
  50.    
  51.     temp = os.clock()-lastCallFromTheID[timerID]
  52.     lastCallFromTheID[timerID] = os.clock()
  53.     return temp
  54. end
  55.  
  56. function execAsync(str)
  57.     if execAsyncQueries == nil then
  58.         execAsyncQueries = 0
  59.     end
  60.    
  61.     timeDiff2 = deltaT("execAsync")
  62.     if timeDiff2 > restingTime then
  63.         execAsyncQueries = 0 --Blast of queries was cut off. I consider this one a new one.
  64.     else
  65.         execAsyncQueries = execAsyncQueries+1
  66.     end
  67.     -- console(execAsyncQueries, 7)
  68.     if execAsyncQueries > dangerousAmountOfQueries then
  69.         sleep(restingTime)
  70.         execAsyncQueries = 0 --just to be sure, manually consider the blast as done and down
  71.     end
  72.    
  73.     return old.execAsync(str)
  74. end
  75. commands.execAsync = execAsync
  76.  
  77. function setBlock(block,xa,ya,za,dataValue,oldBlockHandling)
  78.     if type(dataValue) ~= "string" then
  79.         dataValue = ""
  80.     end
  81.     if type(oldBlockHandling) ~= "string" then
  82.         oldBlockHandling = ""
  83.     end
  84.     -- print("setblock ~" .. tostring(xa) .. " ~" .. tostring(za) .. " ~".. tostring(ya) .. " " .. tostring(block) .. " " .. tostring(dataValue) .. " " .. tostring(oldBlockHandling))
  85.     commands.execAsync("setblock ~" .. tostring(xa) .. " ~" .. tostring(za) .. " ~".. tostring(ya) .. " " .. tostring(block) .. " " .. tostring(dataValue) .. " " .. tostring(oldBlockHandling))
  86. end
  87.  
  88. function fill(block, xa, ya, za, width, length, height)
  89.     queries = 0
  90.     for i=xa,xa+width-1 do
  91.         for j=ya,ya+length-1 do
  92.             for k=za,za+height-1 do
  93.                 setBlock(block, i, j, k)
  94.                 queries = queries+1
  95.             end
  96.         end
  97.     end
  98.     return queries
  99. end
  100.  
  101. function fillNicely(block, xa, ya, za, width, length, height)
  102.     queries = fill(block, xa, ya, za, width, length, height)
  103.     queries = queries + fill(glass, xa+1, ya+1, za, width-2, length-2, height)
  104.     return queries
  105. end
  106.  
  107. function floor(block, xa, ya, za, width, length)
  108.     return fill(block, xa, ya, za, width, length, 1)
  109. end
  110.  
  111. function walls(block, xa, ya, za, width, length, height)
  112.     queries = fill(block, xa, ya, za, width, length, height)
  113.     queries = queries + fill(air, xa+1, ya+1, za, width-2, length-2, height)
  114.     return queries
  115. end
  116.  
  117. function room(blockFloor, blockWalls, xa, ya, za, width, length, height)
  118.     fill(air, xa, ya, za, width, length, height)
  119.     floor(blockFloor, xa, ya, za, width, length)
  120.     walls(blockWalls, xa, ya, za+1, width, length, height-2)
  121.     floor(blockFloor, xa, ya, za+height-1, width, length)
  122. end
  123.  
  124. function forEachColumnOfAWallDoMyFunc(yourFunc, xa, ya, width, length)
  125.     column = 1
  126.     for i=xa,width+2 do
  127.         yourFunc(i, ya, column, true)
  128.         yourFunc(i, ya+length-1, column, true)
  129.         -- sleep(1)
  130.         column = column+1
  131.     end
  132.     column = 1
  133.     glass = "minecraft:glass"
  134.     for i=ya,length+2 do
  135.         yourFunc(xa, i, column, false)
  136.         yourFunc(xa+width-1, i, column, false)
  137.         -- sleep(1)
  138.         column = column+1
  139.     end
  140. end
  141.  
  142. function roomWithWindows(blockFloor, blockWalls, xa, ya, za, width, length, height, numberOfWindowsFront, numberOfWindowsSide)
  143.     room(blockFloor, blockWalls, xa, ya, za, width, length, height)
  144.    
  145.     if numberOfWindowsFront == nil then
  146.         numberOfWindowsFront = math.floor(math.sqrt(width))
  147.         print(numberOfWindowsFront)
  148.     end
  149.     if numberOfWindowsSide == nil then
  150.         numberOfWindowsSide = math.floor(math.sqrt(length))
  151.         print(numberOfWindowsSide)
  152.     end
  153.    
  154.     frontWindowsLength = math.floor((width-numberOfWindowsFront-1)/numberOfWindowsFront)
  155.     frontMiddleWindowLength = width-(numberOfWindowsFront+1)-((numberOfWindowsFront-1)*frontWindowsLength)
  156.     frontMiddleWindow = math.ceil(numberOfWindowsFront/2)
  157.     frontMiddleWindowPosition = frontMiddleWindow + (frontMiddleWindow-1)*frontWindowsLength
  158.    
  159.     sideWindowsLength = math.floor((length-numberOfWindowsSide-1)/numberOfWindowsSide)
  160.     sideMiddleWindowLength = length-(numberOfWindowsSide+1)-((numberOfWindowsSide-1)*sideWindowsLength)
  161.     sideMiddleWindow = math.ceil(numberOfWindowsSide/2)
  162.     sideMiddleWindowPosition = sideMiddleWindow + (sideMiddleWindow-1)*sideWindowsLength
  163.    
  164.     -- Maintenant on a les dimensions des fenêtres. Longueurs. Positions. Tout.
  165.     -- L'idée est de parcourir le contour du mur et de dessiner les fenêtres.
  166.     validColumns = {}
  167.     validColumns.front = {}
  168.     validColumns.side = {}
  169.         -- Murs de face et arrière
  170.     for i=1,width do --tout en verre
  171.         validColumns.front[i] = true
  172.     end
  173.     validColumns.front[1] = false --sauf le début
  174.     validColumns.front[width] = false --et la fin
  175.     i=1
  176.     while i < width/2 do --puis on fait vitre après vitre depuis le début jusqu'au milieu
  177.         validColumns.front[i] = false
  178.         i=i+frontWindowsLength+1
  179.     end
  180.     i=width
  181.     while i > width/2 do --puis de la fin jusqu'au milieu
  182.         validColumns.front[i] = false
  183.         i=i-frontWindowsLength-1
  184.     end
  185.     for i=frontMiddleWindowPosition+1,frontMiddleWindowPosition+frontMiddleWindowLength do
  186.         validColumns.front[i] = true
  187.     end
  188.    
  189.    
  190.         -- Murs de face et arrière
  191. --  for i=1,width do
  192. --      validColumns.front[i] = true
  193. --  end
  194. --  validColumns.front[1] = false
  195. --  validColumns.front[width] = false
  196. --  i=1
  197. --  while i<frontMiddleWindowPosition do
  198. --      validColumns.front[i] = false
  199. --      i=i+frontWindowsLength+1
  200. --  end
  201. --  i=frontMiddleWindowPosition
  202. --  validColumns.front[i] = false
  203. --  i=frontMiddleWindowPosition+frontMiddleWindowLength+1
  204. --  while i<=width do
  205. --      validColumns.front[i] = false
  206. --      i=i+frontWindowsLength+1
  207. --  end
  208.  
  209.         -- Murs des côtés
  210.     for i=1,length do --tout en verre
  211.         validColumns.side[i] = true
  212.     end
  213.     validColumns.side[1] = false --sauf le début
  214.     validColumns.side[length] = false --et la fin
  215.     i=1
  216.     while i < length/2 do --puis on fait vitre après vitre depuis le début jusqu'au milieu
  217.         validColumns.side[i] = false
  218.         i=i+sideWindowsLength+1
  219.     end
  220.     i=length
  221.     while i > length/2 do --puis de la fin jusqu'au milieu
  222.         validColumns.side[i] = false
  223.         i=i-sideWindowsLength-1
  224.     end
  225.     center = (length/2)
  226.     otherCenter = math.ceil(sideMiddleWindowPosition+(sideMiddleWindowLength/2))
  227. --  for i=sideMiddleWindowPosition+1,sideMiddleWindowPosition+sideMiddleWindowLength do
  228. --      validColumns.side[i] = true
  229. --  end
  230.    
  231.    
  232.     function myFunc(xa,ya,column,isFront)
  233.         if isFront == true then
  234.             if validColumns.front[column] == true then
  235.                 fill(glass, xa, ya, za+1, 1, 1, height-2) --glassify column
  236.             end
  237.         else --if isSide
  238.             if validColumns.side[column] == true then
  239.                 fill(glass, xa, ya, za+1, 1, 1, height-2) --glassify column
  240.             end
  241.         end
  242.     end
  243.    
  244.     forEachColumnOfAWallDoMyFunc(myFunc, xa, ya, width, length)
  245. end
  246.  
  247. if false then
  248.     fill(air,3,3,3,20,20,20)
  249.     roomWithWindows(wood, stone, 3,3,3, 9,15,5,4,4)
  250. else
  251.     while true do
  252.         fill(air,3,3,3,20,20,20)
  253.         roomWithWindows(wood, stone, 3,3,3, math.random(4,20),math.random(4,20),5,math.random(1,7),math.random(1,7))
  254.         sleep(2)
  255.     end
  256. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement