Advertisement
Kopasz7

WorldEdit Boulder Brush V2.2

May 25th, 2015
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Boulder Brush CraftScript for WorldEdit
  3.  * Original brush script by inHaze <http://bit.ly/inHaze>
  4.  * Modified by Fefinix (changed the bush shape)
  5.  *
  6.  * This program is free software: you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation, either version 3 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. importPackage(Packages.com.sk89q.worldedit);
  20. importPackage(Packages.com.sk89q.worldedit.blocks);
  21. importPackage(Packages.com.sk89q.worldedit.tools);
  22. importPackage(Packages.com.sk89q.worldedit.tools.brushes);
  23. importPackage(Packages.com.sk89q.worldedit.patterns);
  24. importPackage(Packages.com.sk89q.worldedit.foundation);
  25.  
  26. var material = argv.length > 1 ? context.getBlock(argv[1]) : 1;
  27. var xSize = argv.length > 2 ? parseInt(argv[2]) : 9;
  28. var ySize = argv.length > 3 ? parseInt(argv[3]) : 6;
  29. var zSize = argv.length > 4 ? parseInt(argv[4]) : 11;
  30. var yOff = argv.length > 5 ? parseInt(argv[5]) : 0;
  31. var thickInput = argv.length > 6 ? parseInt(argv[6]) : -1;
  32. var fModInput = argv.length > 7 ? parseInt(argv[7]) : -1;
  33.  
  34. var fMod = [0,0,0];
  35. var thick = 0;
  36.  
  37. if (thickInput == -1) {thick = Math.floor(Math.sqrt(Math.min(xSize,ySize,zSize)))} else {thick = thickInput};
  38.  
  39. var strength = 1;
  40. //var tool = undefined;
  41. //var matPat = undefined;
  42.  
  43.  
  44. var brush = new Brush({
  45.     strength : strength,
  46.     build : function(editSession,posB,size) {
  47.  
  48.         var session = context.remember();
  49.         var pos = player.getBlockTrace(300, true);
  50.        
  51.         var xPer = (Math.random() * 2 * 3.14);
  52.         var yPer = (Math.random() * 2 * 3.14);
  53.         var zPer = (Math.random() * 2 * 3.14);
  54.         if (fModInput == -1) {
  55.             fMod[1] = ((Math.random() * Math.max(xSize,ySize,zSize)/2) + Math.max(xSize,ySize,zSize)*0.4 +1);
  56.             fMod[2] = ((Math.random() * Math.max(xSize,ySize,zSize)/2) + Math.max(xSize,ySize,zSize)*0.4 +1);
  57.             fMod[3] = ((Math.random() * Math.max(xSize,ySize,zSize)/2) + Math.max(xSize,ySize,zSize)*0.4 +1);
  58.             }
  59.         else {
  60.             fMod[1] = fModInput;
  61.             fMod[2] = fModInput;
  62.             fMod[3] = fModInput;
  63.             };
  64.         var s = [1, 1, 1, 1, 1, 1, 1, 1, 1];
  65.         var s2 = 0;
  66.         for (var i = 0; i <= 2; i++){
  67.             s2 = Math.floor(Math.random()*3);
  68.             s[s2+i*3] = -1;
  69.         }
  70.         for (var x = -(xSize+thick); x <= (xSize+thick); x++) {
  71.             for (var y = -(ySize+thick); y <= (ySize+thick); y++) {
  72.                 for (var z = -(zSize+thick); z <= (zSize+thick); z++) {
  73.                     if ((Math.pow((x),2)/Math.pow((thick*Math.sin((x*s[0]+y*s[1]+z*s[2])/fMod[1]-xPer)+xSize),2)+Math.pow(z,2)/Math.pow((thick*Math.sin((x*s[3]+y*s[4]+z*s[5])/fMod[2]+zPer)+zSize),2)+Math.pow(y,2)/Math.pow((thick*Math.sin((x*s[6]+y*s[7]+z*s[8])/fMod[3]+yPer)+ySize),2)) < 1) {
  74.                         var pt = pos.add((x), (y+yOff+thick), (z));
  75.                         editSession.setBlock(pt, material);
  76.                     }
  77.                 }
  78.             }
  79.         }
  80.    
  81.         return true;
  82.     },
  83.    
  84. })
  85.  
  86.  
  87. if (argv.length <= 1)  {
  88.     CommandText();
  89. }
  90. else {
  91.     tool = context.getSession().getBrushTool(player.getItemInHand());
  92.     //matPat = new SingleBlockPattern(material);
  93.     //tool.setFill(matPat);
  94.     tool.setBrush(brush,"worldedit.brush.boulder");
  95.     player.printError("Boulder brush bound to " + ItemType.toHeldName(player.getItemInHand()) + "." );
  96.     player.print("[X: " +  xSize +" | Y: " + ySize + " | Z: " + zSize + " | Mat: " + material + "]");
  97. }
  98.  
  99.  
  100. function CommandText()  {
  101.    
  102.     player.print(" ");
  103.     player.print("§5Boulder Brush Script by Fefinix, huge thanks to inHaze!");
  104.     player.print(" ");
  105.     player.print("§cUsage: /cs boulder [§6mat§c]<§ex§c><§ey§c><§ez§c><§eyOff§c><§ethick§c><§efMod§c>");
  106.     player.print("§6mat§7  - §6Required§7. Boulder material.");
  107.     player.print("§ex§7     - §eOptional§7. Radius in x direction. Default:9");
  108.     player.print("§ey§7     - §eOptional§7. Radius in y direction. Default:6");
  109.     player.print("§ez§7     - §eOptional§7. Radius in z direction. Default:11");
  110.     player.print("§eyOff§7 - §eOptional§7. Vertical offset. Default:0");
  111.     player.print("§ethick§7 - §eOptional§7. Surface bumpyness. 0 = Ellipsoid.");
  112.     player.print("§efMod§7 - §eOptional§7. Shape mod. Higher value = smoother surface.");
  113.  
  114.     return true;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement