Advertisement
aodminecraft

Arc OS - Worldedit - programs/WE_Sel

Aug 1st, 2015
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.39 KB | None | 0 0
  1. sel={}
  2. local sleepInterval=sleepInterval or 25000
  3. local sleepInterval2=sleepInterval or 6
  4.  
  5. function getSleepTime(count,count2,iterations,checksBlocks,sleepInterval,sleepInterval2)
  6.   local sleepInterval=sleepInterval or 25000
  7.   local sleepInterval2=sleepInterval or 6
  8.   if hasChatBox and checksBlocks then
  9.     return iterations/20
  10.   else
  11.     return (math.floor((count+count2*sleepInterval)/sleepInterval)/20+math.floor((count+count2*sleepInterval)/(sleepInterval*sleepInterval2))/10+0.05)
  12.   end
  13. end
  14.  
  15. function BlockHasChanged(x,y,z,id,meta)
  16.   local blockData
  17.   if hasChatBox then
  18.     blockData=commands.getBlockInfo(x,y,z)
  19.     return blockData.name~=idToMCName(id) or blockData.metadata~=meta
  20.   end
  21.   return getBlockID(x,y,z)~=id or getMetadata(x,y,z)~=meta
  22. end
  23.  
  24. function BlockEquals(x,y,z,id,meta)
  25.   local blockData
  26.   if hasChatBox then
  27.     if tonumber(id) then
  28.       id=idToMCName(id)
  29.     end
  30.     blockData=commands.getBlockInfo(x,y,z)
  31.     return blockData.name==id and blockData.metadata==meta
  32.   end
  33.   return getBlockID(x,y,z)==id and getMetadata(x,y,z)==meta
  34. end
  35.  
  36. local MCVersion=1.7
  37. function sel.set(NoOutput) --http://wiki.sk89q.com/wiki/WorldEdit/Region_operations#Setting_blocks
  38.   local count=0
  39.   local count2=0
  40.   local iterations=0
  41.   if #Selection>0 then
  42.     for i=1,#Selection do --Go through all of the blocks in the selection...
  43.       x=Selection[i].x
  44.       y=Selection[i].y
  45.       z=Selection[i].z
  46.       count=count+1
  47.       if count>=sleepInterval then
  48.         count=0
  49.         sleep(0.05)
  50.         count2=count2+1
  51.       elseif count2>=sleepInterval2 then
  52.         count2=0
  53.         sleep(0.05)
  54.       end --Save the server from death by sleeping for a tick each 25000 blocks, and 2 for every 150000.
  55.       local blockChanged
  56.       if hasChatBox and MCVersion>=1.8 then
  57.         local maxPercent=1
  58.         for i=1,#Percentages do
  59.           if Percentages[i]>Percentages[maxPercent] then
  60.             maxPercent=i
  61.           end
  62.         end --Set as many blocks of the most common block type with fill to use as few commands as possible.
  63.         commands.exec("fill "..x1.." "..y1.." "..z1.." "..x2.." "..y2.." "..z2.." "..Blocks2[maxPercent].." "..Meta2[maxPercent].." replace")
  64.         if #Blocks2==1 then
  65.           break
  66.         end
  67.       end
  68.       if not (#Blocks2>1 and hasChatBox and MCVersion>=1.8) then
  69.         if TotalPercent~=0 then
  70.           repeat
  71.             BlockType=math.random(1,#Blocks2)
  72.             RandomRoll=math.random(1,TotalPercent)
  73.           until RandomRoll<=tonumber(Percentages[BlockType]) --Pick weighted random numbers, so that it picks a block randomly using the probabilities given by the user.
  74.         else
  75.           BlockType=1 --If there's only one block, use it!
  76.         end
  77.         if not hasChatBox then
  78.           blockChanged=BlockHasChanged(x,y,z,Blocks2[BlockType],Meta2[BlockType])
  79.           setBlock(x,y,z,Blocks2[BlockType],Meta2[BlockType])
  80.         elseif hasChatBox then
  81.           blockChanged=setBlock(x,y,z,Blocks2[BlockType],Meta2[BlockType])
  82.         end
  83.         if blockChanged then --If the block is actually CHANGED.
  84.           iterations=iterations+1 --Count how many blocks actually changed.
  85.         end
  86.         if iterations==1 and blockChanged then
  87.           sendChat("Setting blocks...")
  88.         end
  89.       end
  90.       if hasChatBox and MCVersion>=1.8 then
  91.         iterations=#Selection
  92.       end
  93.     end
  94.   end
  95.   if not NoOutput then
  96.     if iterations==0 then
  97.       sendChat("No blocks changed.")
  98.     else
  99.       sendChat(iterations.." blocks changed in "..getSleepTime(count,count2,iterations,false).." seconds.")
  100.     end --Tell the user how many blocks changed.
  101.   end
  102. end
  103.  
  104. function sel.replace(NoOutput) --http://wiki.sk89q.com/wiki/WorldEdit/Region_operations#Replacing_blocks
  105.   local count=0
  106.   local count2=0
  107.   local iterations=0
  108.   local sleepInterval=sleepInterval or 25000
  109.   local sleepInterval2=sleepInterval or 6
  110.   if #Selection>0 then
  111.     for i=1,#Selection do --Go through all of the blocks in the selection...
  112.       x=Selection[i].x
  113.       y=Selection[i].y
  114.       z=Selection[i].z
  115.       if count>=sleepInterval then
  116.         count=0
  117.         sleep(0.05)
  118.         count2=count2+1
  119.       elseif count2>=sleepInterval2 then
  120.         count2=0
  121.         sleep(0.05)
  122.       end
  123.       count=count+1
  124.       if TotalPercent~=0 then
  125.         repeat
  126.           BlockType=math.random(1,#Blocks2)
  127.           RandomRoll=math.random(1,TotalPercent)
  128.         until RandomRoll<=tonumber(Percentages[BlockType])
  129.       else
  130.         BlockType=1
  131.       end
  132.       for i=1,#Blocks do
  133.         if BlockEquals(x,y,z,Blocks[i],Meta[i]) then --If they match any of them...
  134.           setBlock(x,y,z,Blocks2[BlockType],Meta2[BlockType])
  135.           iterations=iterations+1 --Count how many blocks were changed.
  136.           break
  137.         end
  138.       end
  139.       if iterations==1 then
  140.         sendChat("Replacing blocks...")
  141.       end
  142.     end
  143.   end
  144.   if not NoOutput then
  145.     if iterations==0 then
  146.       sendChat("No blocks changed.")
  147.     else
  148.       sendChat(iterations.." blocks changed in "..getSleepTime(count,count2,iterations,true).." seconds.")
  149.     end
  150.   end
  151. end
  152.  
  153. function sel.naturalize(NoOutput)
  154.   local count=0
  155.   local count2=0
  156.   local iterations=0
  157.   local Map=heightmap()
  158.   for i=1,#Map do
  159.     x,y,z=Map[i].x,Map[i].y,Map[i].z
  160.     if y then
  161.       count=count+1
  162.       if count>=sleepInterval then
  163.        count=0
  164.         sleep(0.05)
  165.         count2=count2+1
  166.       elseif count2>=sleepInterval2 then
  167.         count2=0
  168.         sleep(0.05)
  169.       end
  170.       for j=0,3 do
  171.         local ID=tonumber(getBlockID(x,y-j,z))
  172.         if ID==1 or ID==2 or ID==3 then
  173.           naturalBlockID=((j==0 and 2) or 3)
  174.           if BlockHasChanged(x,y-j,z,naturalBlockID,0) then
  175.             iterations=iterations+1
  176.             setBlock(x,y-j,z,naturalBlockID,0)
  177.           end
  178.           if iterations==1 then
  179.             sendChat("Naturalizing...")
  180.           end
  181.         end
  182.       end
  183.     end
  184.   end
  185.   if not NoOutput then
  186.     if iterations==0 then
  187.       sendChat("No blocks changed.")
  188.     else
  189.       sendChat(iterations.." blocks changed in "..getSleepTime(count,count2,iterations,true).." seconds.")
  190.     end
  191.   end
  192. end
  193.  
  194. function sel.overlay(NoOutput)
  195.   local count=0
  196.   local count2=0
  197.   local iterations=0
  198.   local Map=heightmap()
  199.   local BlockType
  200.   for i=1,#Map do
  201.     if tonumber(Map[i].y) then
  202.       x,y,z=Map[i].x,Map[i].y,Map[i].z
  203.       count=count+1
  204.       if count>=sleepInterval then
  205.         count=0
  206.         sleep(0.05)
  207.         count2=count2+1
  208.       elseif count2>=sleepInterval2 then
  209.         count2=0
  210.         sleep(0.05)
  211.       end
  212.       if TotalPercent~=0 then
  213.         repeat
  214.           BlockType=math.random(1,#Blocks2)
  215.           local RandomRoll=math.random(1,TotalPercent)
  216.         until RandomRoll<=tonumber(Percentages[BlockType])
  217.       else
  218.         local BlockType=1
  219.       end
  220.       for i=1,#Blocks2 do
  221.         if BlockHasChanged(x,y+1,z,Blocks2[BlockType],Meta2[BlockType]) then
  222.           setBlock(x,y+1,z,Blocks2[BlockType],Meta2[BlockType])
  223.           iterations=iterations+1
  224.           break
  225.         end
  226.       end
  227.       if iterations==1 then
  228.         sendChat("Overlaying blocks...")
  229.       end
  230.     end
  231.   end
  232.   if not NoOutput then
  233.     if iterations==0 then
  234.       sendChat("No blocks changed.")
  235.     else
  236.       sendChat(iterations.." blocks changed in "..getSleepTime(count,count2,iterations,false).." seconds.")
  237.     end
  238.   end
  239. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement