Advertisement
Lion4ever

Minesweeper generator

Dec 9th, 2015
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | None | 0 0
  1. local buttonType = "stone_pressure_plate"
  2. local asyncLimit = 900
  3. local mats = {
  4.     {
  5.       name = "minecraft:unpowered_repeater",
  6.       metadata = 0,
  7.     },
  8.     {
  9.       name = "minecraft:stone",
  10.       metadata = 0,
  11.     },
  12.     {
  13.       name = "minecraft:tnt",
  14.       metadata = 0,
  15.     },
  16.     {
  17.       name = "minecraft:redstone_wire",
  18.       metadata = 0,
  19.     },
  20.     {
  21.       name = "minecraft:air",
  22.       metadata = 0,
  23.     },
  24.     {
  25.       name = "minecraft:unpowered_repeater",
  26.       metadata = 2,
  27.     },
  28.     {
  29.       name = "minecraft:piston",
  30.       metadata = 1,
  31.     },
  32.     {
  33.       name = "minecraft:"..buttonType,
  34.       metadata = 0,
  35.     }
  36.   }
  37.  
  38. local pats = {{{{3,5,5},{5,2,5}},{{5,2,5},{2,7,2}},{{5,5,3},{5,2,5}}},{{{3,5,5},{5,2,7}},{{5,2,5},{2,4,2}},{{5,5,3},{7,2,5}}},{{{3,5,5},{5,2,7}},{{7,2,5},{2,4,2}},{{5,5,3},{5,2,7}}},{{{3,5,5},{7,2,7}},{{5,2,5},{2,4,2}},{{5,5,3},{7,2,7}}},{{{3,5,5},{7,2,7}},{{5,2,7},{2,4,2}},{{5,5,3},{7,2,7}}},{{{3,7,5},{7,2,7}},{{5,2,5},{2,4,2}},{{5,7,3},{7,2,7}}},{{{3,7,5},{7,2,7}},{{5,2,7},{2,4,2}},{{5,7,3},{7,2,7}}},{{{3,7,5},{7,2,7}},{{7,2,7},{2,4,2}},{{5,7,3},{7,2,7}}},{{{5,3,5},{2,5,2}},{{3,2,3},{5,4,5}},{{5,3,5},{2,5,2}}},[0]={{{1,2,1},{3,4,5}},{{2,2,2},{4,4,4}},{{6,2,6},{5,4,3}}}}
  39.  
  40. local args = {...}
  41.  
  42. local de = {5,5,6,0,0,0}
  43.  
  44. if commands then
  45.   de[4],de[5],de[6] = commands.getBlockPosition()
  46.   de[5]=de[5]+1
  47. end
  48.  
  49. for i,j in ipairs(de) do
  50.   args[i] = tonumber(args[i]) or j
  51. end
  52.  
  53. if args[3] > args[1] * args[2] then
  54.   print("Too many mines")
  55.   return
  56. end
  57.  
  58. local mines = {}
  59.  
  60. for i=0,args[1]+1 do
  61.   mines[i] = {}
  62. end
  63.  
  64. while args[3] > 0 do
  65.   local x,y = math.random(args[1]),math.random(args[2])
  66.   if not mines[x][y] then
  67.     mines[x][y] = true
  68.     args[3]=args[3]-1
  69.   end
  70. end
  71.  
  72. local function count(x,y)
  73.   local ms = 0
  74.   for i=-1,1 do
  75.     for j=-1,1 do
  76.       if mines[x+i][y+j] then
  77.         ms=ms+1
  78.       end
  79.     end
  80.   end
  81.   return ms
  82. end
  83. local taken = 0
  84. local function set(x,y,z,bn)
  85.   local mat = mats[bn or 2]
  86.   commands.async.setblock(args[4]+x,args[5]+y,args[6]+z,mat.name,mat.metadata)
  87.   taken = taken + 1
  88.   if taken >= asyncLimit then
  89.     sleep(0.1)
  90.     taken = 0
  91.   end
  92. end
  93.  
  94. if commands then
  95.   for i=0,args[1]*3+1 do
  96.     for h=0,3 do
  97.       set(i,h,0)
  98.       set(i,h,args[2]*3+1)
  99.     end
  100.   end
  101.   for i=1,args[2]*3 do
  102.     for h=0,3 do
  103.       set(0,h,i)
  104.       set(args[1]*3+1,h,i)
  105.     end
  106.   end
  107.   for i=0,args[1]-1 do
  108.     for j=0,args[2]-1 do
  109.       local c = mines[i+1][j+1] and #pats or count(i+1,j+1)
  110.       for k=1,3 do
  111.         for l=1,3 do
  112.           set(i*3+k,4,j*3+l,5)
  113.           set(i*3+k,0,j*3+l)
  114.           for m=1,2 do
  115.             set(i*3+k,m,j*3+l,pats[c][k][m][l])
  116.           end
  117.           set(i*3+k,3,j*3+l)
  118.         end
  119.       end
  120.       set(i*3+2,4,j*3+2,#mats)
  121.     end
  122.   end
  123. else
  124.   print("This needs to be on  an command computer")
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement